use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldNotListDeletedTokens.
@Test
public void shouldNotListDeletedTokens() {
String user1 = "Bob";
String user2 = "John";
AccessToken token1 = randomAccessTokenForUser(user1);
AccessToken token2 = randomAccessTokenForUser(user1);
AccessToken token3 = randomAccessTokenForUser(user2);
accessTokenSqlMapDao.saveOrUpdate(token1);
accessTokenSqlMapDao.saveOrUpdate(token2);
accessTokenSqlMapDao.saveOrUpdate(token3);
List<AccessToken> user1AccessTokens = accessTokenSqlMapDao.findAllTokensForUser(user1, AccessTokenFilter.all);
List<AccessToken> user2AccessTokens = accessTokenSqlMapDao.findAllTokensForUser(user2, AccessTokenFilter.all);
assertThat(user1AccessTokens).hasSize(2).containsExactlyInAnyOrder(token1, token2);
assertThat(user2AccessTokens).hasSize(1).containsExactlyInAnyOrder(token3);
accessTokenSqlMapDao.revokeTokensBecauseOfUserDelete(Arrays.asList("bob", "john"), "admin");
assertThat(accessTokenSqlMapDao.findAllTokensForUser("bob", AccessTokenFilter.all)).isEmpty();
assertThat(accessTokenSqlMapDao.findAllTokensForUser("john", AccessTokenFilter.all)).isEmpty();
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldSaveUsersIntoDatabase.
@Test
public void shouldSaveUsersIntoDatabase() {
AccessToken accessToken = randomAccessToken();
accessTokenSqlMapDao.saveOrUpdate(accessToken);
AccessToken savedAccessToken = accessTokenSqlMapDao.loadForAdminUser(accessToken.getId());
assertThat(savedAccessToken).isEqualTo(accessToken);
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldReturnAllTheAccessTokensBelongingToAUser.
@Test
public void shouldReturnAllTheAccessTokensBelongingToAUser() {
String user1 = "Bob";
String user2 = "John";
AccessToken token1 = randomAccessTokenForUser(user1);
AccessToken token2 = randomAccessTokenForUser(user1);
AccessToken token3 = randomAccessTokenForUser(user2);
accessTokenSqlMapDao.saveOrUpdate(token1);
accessTokenSqlMapDao.saveOrUpdate(token2);
accessTokenSqlMapDao.saveOrUpdate(token3);
List<AccessToken> user1AccessTokens = accessTokenSqlMapDao.findAllTokensForUser(user1, AccessTokenFilter.all);
List<AccessToken> user2AccessTokens = accessTokenSqlMapDao.findAllTokensForUser(user2, AccessTokenFilter.all);
assertThat(user1AccessTokens).hasSize(2).containsExactlyInAnyOrder(token1, token2);
assertThat(user2AccessTokens).hasSize(1).containsExactlyInAnyOrder(token3);
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method shouldListAllTokensThatAreRevoked.
@Test
public void shouldListAllTokensThatAreRevoked() {
String user1 = "will-be-deleted";
String user2 = "will-be-revoked";
AccessToken token1 = randomAccessTokenForUser(user1);
AccessToken token2 = randomAccessTokenForUser(user2);
accessTokenSqlMapDao.saveOrUpdate(token1);
accessTokenSqlMapDao.saveOrUpdate(token2);
accessTokenSqlMapDao.saveOrUpdate(token1.revoke("admin", "user is making too many requests", clock.currentTimestamp()));
accessTokenSqlMapDao.revokeTokensBecauseOfUserDelete(Collections.singletonList(user2), "admin");
assertThat(accessTokenSqlMapDao.findAllTokens(AccessTokenFilter.revoked)).hasSize(2).containsExactlyInAnyOrder(accessTokenSqlMapDao.loadForAdminUser(token1.getId()), accessTokenSqlMapDao.loadForAdminUser(token2.getId()));
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenService method findAccessTokenForGoCD.
// load access token within GoCD
private AccessToken findAccessTokenForGoCD(long id) {
AccessToken token;
token = accessTokenDao.loadForAdminUser(id);
if (token == null) {
throw new RecordNotFoundException(EntityType.AccessToken, id);
}
return token;
}
Aggregations