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);
}
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);
}
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());
}
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;
}
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);
}
Aggregations