Search in sources :

Example 11 with AuthToken

use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testDeleteAuthToken_expectDeletedAuthTokenMustNotBeValid.

@Test
public void testDeleteAuthToken_expectDeletedAuthTokenMustNotBeValid() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken);
    AuthToken result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
    assertNotNull(result);
    authTokenService.deleteAuthToken(authToken.getUuid());
    result = authTokenService.isAuthTokenValid(user.getUuid(), authToken.getUuid(), authToken.getTokenValue());
    assertNull(result);
}
Also used : User(org.summerb.microservices.users.api.dto.User) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) Test(org.junit.Test)

Example 12 with AuthToken

use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testCreateAuthToken_expectOk.

@Test
public void testCreateAuthToken_expectOk() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.authenticate(user.getEmail(), "aaa", "LOCAL");
    assertNotNull(authToken);
}
Also used : User(org.summerb.microservices.users.api.dto.User) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) Test(org.junit.Test)

Example 13 with AuthToken

use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.

the class AuthTokenDaoImplTest method testUpdateToken_expectValueWillBeUpdated.

@Test
public void testUpdateToken_expectValueWillBeUpdated() throws Exception {
    User user = userService.createUser(UserFactory.createNewUserTemplate());
    passwordService.setUserPassword(user.getUuid(), "aaa");
    AuthToken authToken = authTokenService.createAuthToken(user.getEmail(), "LOCAL", "tUuid1", "tValue1");
    assertNotNull(authToken);
    authTokenDao.updateToken(authToken.getUuid(), new Date().getTime() + 1, "newValue2");
    authToken = authTokenService.getAuthTokenByUuid(authToken.getUuid());
    assertEquals("newValue2", authToken.getTokenValue());
}
Also used : User(org.summerb.microservices.users.api.dto.User) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) Date(java.util.Date) Test(org.junit.Test)

Example 14 with AuthToken

use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.

the class AuthTokenServiceDbImplFactory method createAuthTokenServiceDbImpl.

public static AuthTokenServiceImpl createAuthTokenServiceDbImpl() {
    AuthTokenServiceImpl ret = new AuthTokenServiceImpl();
    ret.setPasswordService(PasswordServiceDbImplFactory.createPasswordServiceDbImpl());
    ret.setUserService(UserServiceImplFactory.createUsersServiceImpl());
    AuthTokenDao authTokenDao = Mockito.mock(AuthTokenDao.class);
    ret.setAuthTokenDao(authTokenDao);
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_EXCEPTION)).thenThrow(new IllegalStateException("test simulate exception"));
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_EXISTENT)).thenReturn(AuthTokenFactory.createAuthTokenForExistentUser());
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_NOT_EXISTENT)).thenReturn(null);
    when(authTokenDao.findAuthTokenByUuid(AuthTokenFactory.AUTH_TOKEN_EXPIRED)).thenReturn(AuthTokenFactory.createExpiredAuthToken());
    List<AuthToken> expiredTokens = new LinkedList<AuthToken>();
    expiredTokens.add(AuthTokenFactory.createExpiredAuthToken());
    PaginatedList<AuthToken> expiredAuthTokens = new PaginatedList<AuthToken>(new PagerParams(), expiredTokens, 1);
    return ret;
}
Also used : AuthTokenDao(org.summerb.microservices.users.impl.dao.AuthTokenDao) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) AuthToken(org.summerb.microservices.users.api.dto.AuthToken) PaginatedList(org.summerb.approaches.jdbccrud.api.dto.PaginatedList) LinkedList(java.util.LinkedList)

Example 15 with AuthToken

use of org.summerb.microservices.users.api.dto.AuthToken in project summerb by skarpushin.

the class AuthTokenServiceDbImplTest method testIsAuthTokenValid_blackbox_expectFalseForExpiredToken.

@Test
public void testIsAuthTokenValid_blackbox_expectFalseForExpiredToken() throws Exception {
    AuthTokenServiceImpl fixture = AuthTokenServiceDbImplFactory.createAuthTokenServiceDbImpl();
    AuthToken result = fixture.isAuthTokenValid(UserFactory.EXISTENT_USER_WITH_EXPIRED_TOKEN, AuthTokenFactory.AUTH_TOKEN_EXPIRED, "...");
    assertNull(result);
}
Also used : AuthToken(org.summerb.microservices.users.api.dto.AuthToken) Test(org.junit.Test)

Aggregations

AuthToken (org.summerb.microservices.users.api.dto.AuthToken)28 Test (org.junit.Test)12 User (org.summerb.microservices.users.api.dto.User)11 Transactional (org.springframework.transaction.annotation.Transactional)3 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)3 UserNotFoundException (org.summerb.microservices.users.api.exceptions.UserNotFoundException)3 UserServiceUnexpectedException (org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)3 File (java.io.File)2 Date (java.util.Date)2 AuthTokenNotFoundException (org.summerb.microservices.users.api.exceptions.AuthTokenNotFoundException)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 PersistentRememberMeToken (org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken)1 PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)1 PaginatedList (org.summerb.approaches.jdbccrud.api.dto.PaginatedList)1