use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenSqlMapDaoIntegrationTest method adminsShouldBeAbleToLoadTokensRevokedByAnyone.
@Test
public void adminsShouldBeAbleToLoadTokensRevokedByAnyone() {
String user = RandomStringUtils.random(32);
AccessToken token = randomAccessTokenForUser(user);
accessTokenSqlMapDao.saveOrUpdate(token);
accessTokenSqlMapDao.saveOrUpdate(token.revoke("admin", "user is making too many requests", clock.currentTimestamp()));
assertThat(accessTokenSqlMapDao.loadForAdminUser(token.getId())).isEqualTo(token);
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenServiceIntegrationTest method shouldCreateAnAccessToken.
@Test
public void shouldCreateAnAccessToken() {
String tokenDescription = "This is my first token";
AccessToken.AccessTokenWithDisplayValue createdToken = accessTokenService.create(tokenDescription, "bob", authConfigId);
AccessToken fetchedToken = accessTokenService.find(createdToken.getId(), "bob");
assertThat(createdToken.getDescription()).isEqualTo(tokenDescription);
assertThat(createdToken.getValue()).isNotNull();
assertThat(createdToken.getDisplayValue()).isNotNull();
assertThat(createdToken.getCreatedAt()).isNotNull();
assertThat(createdToken.getLastUsed()).isNull();
assertThat(createdToken.isRevoked()).isFalse();
assertThat(fetchedToken.getValue()).isEqualTo(createdToken.getValue());
assertThat(fetchedToken.getDescription()).isEqualTo(createdToken.getDescription());
assertThat(fetchedToken.getCreatedAt()).isEqualTo(createdToken.getCreatedAt());
assertThat(fetchedToken.getLastUsed()).isNull();
assertThat(fetchedToken.isRevoked()).isEqualTo(createdToken.isRevoked());
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenServiceIntegrationTest method shouldRevokeAccessTokenWithinGoCD.
@Test
public void shouldRevokeAccessTokenWithinGoCD() {
String tokenDescription = "This is my first Token";
AccessToken createdToken = accessTokenService.create(tokenDescription, "BOB", authConfigId);
assertThat(createdToken.isRevoked()).isFalse();
assertThat(createdToken.getRevokeCause()).isBlank();
accessTokenService.revokeAccessTokenByGoCD(createdToken.getId(), "from GoCD");
AccessToken tokenAfterRevoking = accessTokenService.find(createdToken.getId(), "bOb");
assertThat(tokenAfterRevoking.isRevoked()).isTrue();
assertThat(tokenAfterRevoking.getRevokedBy()).isEqualTo("GoCD");
assertThat(tokenAfterRevoking.getRevokeCause()).isEqualTo("from GoCD");
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenServiceIntegrationTest method shouldRevokeAnAccessToken.
@Test
public void shouldRevokeAnAccessToken() {
String tokenDescription = "This is my first Token";
AccessToken createdToken = accessTokenService.create(tokenDescription, "BOB", authConfigId);
assertThat(createdToken.isRevoked()).isFalse();
assertThat(createdToken.getRevokeCause()).isBlank();
accessTokenService.revokeAccessToken(createdToken.getId(), "bob", "blah");
AccessToken tokenAfterRevoking = accessTokenService.find(createdToken.getId(), "bOb");
assertThat(tokenAfterRevoking.isRevoked()).isTrue();
assertThat(tokenAfterRevoking.getRevokeCause()).isEqualTo("blah");
}
use of com.thoughtworks.go.domain.AccessToken in project gocd by gocd.
the class AccessTokenServiceIntegrationTest method shouldFailToRevokeAnAlreadyRevokedAccessToken.
@Test
public void shouldFailToRevokeAnAlreadyRevokedAccessToken() {
String tokenDescription = "This is my first Token";
AccessToken createdToken = accessTokenService.create(tokenDescription, "BOB", authConfigId);
assertThat(createdToken.isRevoked()).isFalse();
accessTokenService.revokeAccessToken(createdToken.getId(), "bOb", null);
AccessToken tokenAfterRevoking = accessTokenService.find(createdToken.getId(), "bOb");
assertThat(tokenAfterRevoking.isRevoked()).isTrue();
assertThatCode(() -> accessTokenService.revokeAccessToken(createdToken.getId(), "bOb", null)).isInstanceOf(ConflictException.class).hasMessage("Access token has already been revoked!");
}
Aggregations