@@ -61,7 +61,8 @@ public class TestUserApi extends AbstractIntegrationTest {
61
61
private static final String TEST_BLOCK_USERNAME = HelperUtils .getProperty (BLOCK_USERNAME_KEY );
62
62
private static final String TEST_SUDO_AS_USERNAME = HelperUtils .getProperty (SUDO_AS_USERNAME_KEY );
63
63
64
- private static final String TEST_IMPERSONATION_TOKEN_NAME = "token1" ;
64
+ private static final String TEST_IMPERSONATION_TOKEN_NAME = "ipt_1" ;
65
+ private static final String TEST_PERSONAL_ACCESS_TOKEN_NAME = "pat_1" ;
65
66
private static final String TEST_SSH_KEY =
66
67
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3rWzl/oPAD+Em2iGTmR81HcYZsopvnKp7jelI4XS91fT1NjCRrGsxf5Mw/" +
67
68
"KnmtBjhk+kQjkhIrnsBDcs6DZWtNcHJtyWJZrYsfxMTqWCaQv+OTRwVboqS2pmPcbK3gizUd5GCLFTKbg4OMpdywTwi6NAPwQ" +
@@ -325,9 +326,9 @@ public void testCreateImpersonationToken() throws GitLabApiException, ParseExcep
325
326
326
327
User user = gitLabApi .getUserApi ().getCurrentUser ();
327
328
328
- // NOTE: READ_REGISTRY scope is left out because the GitLab server docker instance does not have the
329
- // registry configured and the test would thus fail.
330
- Scope [] scopes = {Scope .API , Scope .READ_USER , Scope .READ_REPOSITORY , Scope .WRITE_REPOSITORY , Scope .SUDO };
329
+ // NOTE: READ_REGISTRY & WRITE_REGISTRY scopes are left out because the GitLab server docker instance does not
330
+ // have the registry configured and the test would thus fail.
331
+ Scope [] scopes = {Scope .API , Scope .READ_API , Scope . READ_USER , Scope .READ_REPOSITORY , Scope .WRITE_REPOSITORY , Scope .SUDO };
331
332
Date expiresAt = ISO8601 .toDate ("2018-01-01T00:00:00Z" );
332
333
333
334
ImpersonationToken token = null ;
@@ -401,7 +402,7 @@ public void testGetImpersonationTokens() throws GitLabApiException, ParseExcepti
401
402
}
402
403
403
404
@ Test
404
- public void testDeleteImpersonationTokens () throws GitLabApiException , ParseException {
405
+ public void testRevokeImpersonationToken () throws GitLabApiException , ParseException {
405
406
406
407
User user = gitLabApi .getUserApi ().getCurrentUser ();
407
408
Scope [] scopes = {Scope .API , Scope .READ_USER };
@@ -418,6 +419,37 @@ public void testDeleteImpersonationTokens() throws GitLabApiException, ParseExce
418
419
assertFalse (token .getActive ());
419
420
}
420
421
422
+ @ Test
423
+ public void testCreatePersonalAccessToken () throws GitLabApiException , ParseException {
424
+
425
+ User user = gitLabApi .getUserApi ().getCurrentUser ();
426
+
427
+ // NOTE: READ_REGISTRY & WRITE_REGISTRY scopes are left out because the GitLab server docker instance does not
428
+ // have the registry configured and the test would thus fail.
429
+ Scope [] scopes = {Scope .API , Scope .READ_API , Scope .READ_USER , Scope .READ_REPOSITORY , Scope .WRITE_REPOSITORY , Scope .SUDO };
430
+ Date expiresAt = ISO8601 .toDate ("2018-01-01T00:00:00Z" );
431
+
432
+ ImpersonationToken token = null ;
433
+ try {
434
+
435
+ token = gitLabApi .getUserApi ().createPersonalAccessToken (user , TEST_PERSONAL_ACCESS_TOKEN_NAME , expiresAt , scopes );
436
+
437
+ assertNotNull (token );
438
+ assertNotNull (token .getId ());
439
+ assertEquals (TEST_PERSONAL_ACCESS_TOKEN_NAME , token .getName ());
440
+ assertEquals (expiresAt .getTime (), token .getExpiresAt ().getTime ());
441
+ assertEquals (scopes .length , token .getScopes ().size ());
442
+ assertThat (token .getScopes (), contains (scopes ));
443
+
444
+ } finally {
445
+ if (user != null && token != null ) {
446
+ // GitLab doesn't have this API method yet - not a big issue since multiple tokens with the same name
447
+ // can be created. Note that you won't see a token in the UI unless the expiry date is in the future.
448
+ // gitLabApi.getUserApi().revokePersonalAccessToken(user.getId(), token.getId());
449
+ }
450
+ }
451
+ }
452
+
421
453
@ Test
422
454
public void testGetSshKeys () throws GitLabApiException {
423
455
0 commit comments