diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2022-06-30 17:55:56 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-07-01 20:03:06 +0000 |
commit | b12e93617de7e80dcb848c6b2cf7a011e11a288c (patch) | |
tree | caddcda342010b1fdd5523d5b4a1a70f03e11faa /server | |
parent | 5159eb8d7cda29c357aa06868a595d07fbc6f633 (diff) | |
download | sonarqube-b12e93617de7e80dcb848c6b2cf7a011e11a288c.tar.gz sonarqube-b12e93617de7e80dcb848c6b2cf7a011e11a288c.zip |
SONAR-16567 update API api/user_tokens/search for returning the expiration date
Diffstat (limited to 'server')
3 files changed, 20 insertions, 0 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/SearchAction.java index 0a04977cc9f..653c700e704 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/usertoken/ws/SearchAction.java @@ -58,6 +58,7 @@ public class SearchAction implements UserTokensWsAction { "Field 'lastConnectionDate' is only updated every hour, so it may not be accurate, for instance when a user is using a token many times in less than one hour.<br> " + "It requires administration permissions to specify a 'login' and list the tokens of another user. Otherwise, tokens for the current user are listed. <br> " + "Authentication is required for this API endpoint") + .setChangelog(new Change("9.6", "New field 'expirationDate' is added to response")) .setChangelog(new Change("7.7", "New field 'lastConnectionDate' is added to response")) .setResponseExample(getClass().getResource("search-example.json")) .setSince("5.3") @@ -93,6 +94,7 @@ public class SearchAction implements UserTokensWsAction { .setCreatedAt(formatDateTime(userTokenDto.getCreatedAt())) .setType(userTokenDto.getType()); ofNullable(userTokenDto.getLastConnectionDate()).ifPresent(date -> userTokenBuilder.setLastConnectionDate(formatDateTime(date))); + ofNullable(userTokenDto.getExpirationDate()).ifPresent(expirationDate -> userTokenBuilder.setExpirationDate(formatDateTime(expirationDate))); if (!isNullOrEmpty(userTokenDto.getProjectKey()) && !isNullOrEmpty(userTokenDto.getProjectName())) { Project.Builder projectBuilder = newBuilder().getProjectBuilder() diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/usertoken/ws/search-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/usertoken/ws/search-example.json index 34f35268527..4279e2891be 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/usertoken/ws/search-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/usertoken/ws/search-example.json @@ -9,6 +9,7 @@ { "name": "Project scan on Jenkins", "createdAt": "2015-04-08T21:57:47+0200", + "expirationDate": "2022-07-14T00:00:00+0200", "type": "PROJECT_ANALYSIS_TOKEN", "project": { "key": "project-1", diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java index 1b165a2367c..6b1d152d521 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/usertoken/ws/SearchActionTest.java @@ -75,6 +75,7 @@ public class SearchActionTest { db.users().insertToken(user1, t -> t.setName("Project scan on AppVeyor").setCreatedAt(1438523067221L)); db.users().insertProjectAnalysisToken(user1, t -> t.setName("Project scan on Jenkins") .setCreatedAt(1428523067221L) + .setExpirationDate(1657749600000L) .setProjectKey(project1.getKey())); db.users().insertProjectAnalysisToken(user2, t -> t.setName("Project scan on Travis") .setCreatedAt(141456787123L) @@ -119,6 +120,22 @@ public class SearchActionTest { } @Test + public void expiration_date_is_returned_only_when_set() { + UserDto user = db.users().insertUser(); + UserTokenDto token1 = db.users().insertToken(user, t -> t.setExpirationDate(10_000_000_000L)); + UserTokenDto token2 = db.users().insertToken(user); + logInAsSystemAdministrator(); + + SearchWsResponse response = newRequest(user.getLogin()); + + assertThat(response.getUserTokensList()) + .extracting(UserToken::getName, UserToken::getExpirationDate) + .containsExactlyInAnyOrder( + tuple(token1.getName(), formatDateTime(10_000_000_000L)), + tuple(token2.getName(), "")); + } + + @Test public void fail_when_login_does_not_exist() { logInAsSystemAdministrator(); |