use of de.catma.repository.git.managers.gitlab4j_api_custom.models.PersonalAccessToken in project catma by forTEXT.
the class CustomUserApiTest method createImpersonationTokenWithExpiryAndScopes.
@Test
public void createImpersonationTokenWithExpiryAndScopes() throws Exception {
// create a user
User user = new User();
user.setEmail("testuser@catma.de");
user.setUsername("testuser");
user.setName("Test User");
user = this.gitLabApi.getUserApi().createUser(user, "password", null);
this.usersToDeleteOnTearDown.add(user.getId());
// create an impersonation token for the user, with expiresAt and scopes
GregorianCalendar cal = new GregorianCalendar();
cal.add(Calendar.DATE, 1);
Date expiryDate = cal.getTime();
PersonalAccessToken impersonationToken = this.customUserApi.createImpersonationToken(user.getId(), "test-token", expiryDate, new String[] { "api", "read_user" });
assertNotNull(impersonationToken);
assert impersonationToken.id > 0;
assertFalse(impersonationToken.revoked);
assertArrayEquals(new String[] { "api", "read_user" }, impersonationToken.scopes);
assert impersonationToken.token.length() > 0;
assert impersonationToken.active;
assert impersonationToken.impersonation;
assertEquals("test-token", impersonationToken.name);
assert impersonationToken.createdAt.length() > 0;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String expectedIsoFormattedExpiryDate = df.format(expiryDate);
assertEquals(expectedIsoFormattedExpiryDate, impersonationToken.expiresAt);
List<PersonalAccessToken> impersonationTokens = this.customUserApi.getImpersonationTokens(user.getId(), null);
assertEquals(1, impersonationTokens.size());
assertEquals(impersonationToken.id, impersonationTokens.get(0).id);
}
use of de.catma.repository.git.managers.gitlab4j_api_custom.models.PersonalAccessToken in project catma by forTEXT.
the class CustomUserApiTest method createImpersonationToken.
@Test
public void createImpersonationToken() throws Exception {
// create a user
User user = new User();
user.setEmail("testuser@catma.de");
user.setUsername("testuser");
user.setName("Test User");
user = this.gitLabApi.getUserApi().createUser(user, "password", null);
this.usersToDeleteOnTearDown.add(user.getId());
// create an impersonation token for the user
PersonalAccessToken impersonationToken = this.customUserApi.createImpersonationToken(user.getId(), "test-token", null, null);
assertNotNull(impersonationToken);
assert impersonationToken.id > 0;
assertFalse(impersonationToken.revoked);
assertArrayEquals(new String[] { "api" }, impersonationToken.scopes);
assert impersonationToken.token.length() > 0;
assert impersonationToken.active;
assert impersonationToken.impersonation;
assertEquals("test-token", impersonationToken.name);
assert impersonationToken.createdAt.length() > 0;
assertNull(impersonationToken.expiresAt);
List<PersonalAccessToken> impersonationTokens = this.customUserApi.getImpersonationTokens(user.getId(), null);
assertEquals(1, impersonationTokens.size());
assertEquals(impersonationToken.id, impersonationTokens.get(0).id);
}
Aggregations