Search in sources :

Example 1 with PersonalAccessToken

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);
}
Also used : User(org.gitlab4j.api.models.User) PersonalAccessToken(de.catma.repository.git.managers.gitlab4j_api_custom.models.PersonalAccessToken) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test)

Example 2 with PersonalAccessToken

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);
}
Also used : User(org.gitlab4j.api.models.User) PersonalAccessToken(de.catma.repository.git.managers.gitlab4j_api_custom.models.PersonalAccessToken) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test)

Aggregations

GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)2 PersonalAccessToken (de.catma.repository.git.managers.gitlab4j_api_custom.models.PersonalAccessToken)2 User (org.gitlab4j.api.models.User)2 Test (org.junit.Test)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1