use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldReturnNullWhenNoAccessTokenFound.
@Test
public void shouldReturnNullWhenNoAccessTokenFound() {
AccessToken savedAccessToken = accessTokenSqlMapDao.loadForAdminUser(-1);
assertThat(savedAccessToken).isNull();
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method adminsShouldBeAbleToLoadTokensRevokedBecauseOfUserDeletionButUsersCannot.
@Test
public void adminsShouldBeAbleToLoadTokensRevokedBecauseOfUserDeletionButUsersCannot() {
String user = RandomStringUtils.random(32);
AccessToken token = randomAccessTokenForUser(user);
accessTokenSqlMapDao.saveOrUpdate(token);
accessTokenSqlMapDao.saveOrUpdate(token.revokeBecauseOfUserDelete("admin", clock.currentTimestamp()));
assertThat(accessTokenSqlMapDao.loadForAdminUser(token.getId())).isEqualTo(token);
assertThat(accessTokenSqlMapDao.loadNotDeletedTokenForUser(token.getId(), user)).isNull();
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldUpdateLastUsedTimeForGivenTokens.
@Test
public void shouldUpdateLastUsedTimeForGivenTokens() {
AccessToken token1 = randomAccessTokenForUser("bob");
accessTokenSqlMapDao.saveOrUpdate(token1);
AccessToken token2 = randomAccessTokenForUser("bob");
accessTokenSqlMapDao.saveOrUpdate(token2);
assertThat(token1.getLastUsed()).isNull();
assertThat(token2.getLastUsed()).isNull();
final DateTime now = DateTime.now();
final Timestamp lastUsedTimeForToken1 = new Timestamp(now.getMillis());
now.plusHours(2);
final Timestamp lastUsedTimeForToken2 = new Timestamp(now.getMillis());
final HashMap<Long, Timestamp> accessTokenIdToLastUsedTimestamp = new HashMap<>();
accessTokenIdToLastUsedTimestamp.put(token1.getId(), lastUsedTimeForToken1);
accessTokenIdToLastUsedTimestamp.put(token2.getId(), lastUsedTimeForToken2);
accessTokenSqlMapDao.updateLastUsedTime(accessTokenIdToLastUsedTimestamp);
final List<AccessToken> allTokensForUser = accessTokenSqlMapDao.findAllTokensForUser("bob", AccessTokenFilter.all);
assertThat(allTokensForUser).hasSize(2);
assertThat(allTokensForUser.get(0).getLastUsed()).isEqualTo(lastUsedTimeForToken1);
assertThat(allTokensForUser.get(1).getLastUsed()).isEqualTo(lastUsedTimeForToken2);
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldListAllTokensThatAreActive.
@Test
public void shouldListAllTokensThatAreActive() {
String user1 = "bob";
String user2 = "will-be-revoked";
AccessToken token1 = randomAccessTokenForUser(user1);
AccessToken token2 = randomAccessTokenForUser(user2);
accessTokenSqlMapDao.saveOrUpdate(token1);
accessTokenSqlMapDao.saveOrUpdate(token2);
accessTokenSqlMapDao.saveOrUpdate(token2.revoke("admin", "user is making too many requests", clock.currentTimestamp()));
assertThat(accessTokenSqlMapDao.findAllTokens(AccessTokenFilter.active)).hasSize(1).containsExactlyInAnyOrder(accessTokenSqlMapDao.loadForAdminUser(token1.getId()));
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldReturnNullWhenNoAccessTokenFoundForTheSpecifiedSaltId.
@Test
public void shouldReturnNullWhenNoAccessTokenFoundForTheSpecifiedSaltId() {
String saltId = "access-token-for-apis";
AccessToken savedAccessToken = accessTokenSqlMapDao.findAccessTokenBySaltId(saltId);
assertThat(savedAccessToken).isNull();
}
Aggregations