Search in sources :

Example 1 with Access

use of org.mamute.auth.Access in project mamute by caelum.

the class AccessTest method should_not_auto_login_without_brutal_cookie.

@Test
public void should_not_auto_login_without_brutal_cookie() {
    Cookie[] cookies = new Cookie[] { anyCookie(), anyCookie(), anyCookie(), anyCookie() };
    when(request.getCookies()).thenReturn(cookies);
    Access access = new Access(response, request, users);
    assertFalse(access.tryToAutoLogin());
}
Also used : Cookie(javax.servlet.http.Cookie) Access(org.mamute.auth.Access) Test(org.junit.Test)

Example 2 with Access

use of org.mamute.auth.Access in project mamute by caelum.

the class AccessTest method should_not_auto_login_with_invalid_session.

@Test
public void should_not_auto_login_with_invalid_session() {
    String sessionKey = "invalid";
    Cookie brutalCookie = new Cookie(Access.BRUTAL_SESSION, sessionKey);
    Cookie[] cookies = new Cookie[] { anyCookie(), brutalCookie, anyCookie() };
    when(request.getCookies()).thenReturn(cookies);
    when(users.findBySessionKey(sessionKey)).thenReturn(null);
    Access access = new Access(response, request, users);
    assertFalse(access.tryToAutoLogin());
}
Also used : Cookie(javax.servlet.http.Cookie) Access(org.mamute.auth.Access) Test(org.junit.Test)

Example 3 with Access

use of org.mamute.auth.Access in project mamute by caelum.

the class AccessTest method should_auto_login_with_valid_cookie.

@Test
public void should_auto_login_with_valid_cookie() {
    String sessionKey = "session-key";
    Cookie brutalCookie = new Cookie(Access.BRUTAL_SESSION, sessionKey);
    Cookie[] cookies = new Cookie[] { anyCookie(), anyCookie(), brutalCookie, anyCookie(), anyCookie() };
    when(request.getCookies()).thenReturn(cookies);
    when(users.findBySessionKey(sessionKey)).thenReturn(new UserAndSession(user, new UserSession(user, sessionKey)));
    Access access = new Access(response, request, users);
    assertTrue(access.tryToAutoLogin());
}
Also used : Cookie(javax.servlet.http.Cookie) UserAndSession(org.mamute.dto.UserAndSession) UserSession(org.mamute.model.UserSession) Access(org.mamute.auth.Access) Test(org.junit.Test)

Aggregations

Cookie (javax.servlet.http.Cookie)3 Test (org.junit.Test)3 Access (org.mamute.auth.Access)3 UserAndSession (org.mamute.dto.UserAndSession)1 UserSession (org.mamute.model.UserSession)1