From 1624eb4d7390443e7b8f3e63b07d2ffca0d65a6a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 7 Sep 2016 17:13:06 +0200 Subject: [PATCH] SONAR-8039 Return invalid server id when no server id generated and license not set to "*" --- .../org/sonar/server/license/ws/ListAction.java | 4 +++- .../org/sonar/server/license/ws/ListActionTest.java | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/license/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/license/ws/ListAction.java index f7f914b4f8e..39cf1b3d560 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/license/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/license/ws/ListAction.java @@ -161,7 +161,9 @@ public class ListAction implements WsAction { if (licenseServerId != null) { licenseBuilder.setServerId(licenseServerId); } - if (!Objects.equals(ALL_SERVERS_VALUE, licenseServerId) && serverId.isPresent() && !serverId.get().equals(licenseServerId)) { + boolean isValidServerId = Objects.equals(licenseServerId, ALL_SERVERS_VALUE) + || (serverId.isPresent() && Objects.equals(licenseServerId, serverId.get())); + if (!isValidServerId) { licenseBuilder.setInvalidServerId(true); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/license/ws/ListActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/license/ws/ListActionTest.java index 0ee5b0633c9..d831532356d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/license/ws/ListActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/license/ws/ListActionTest.java @@ -190,6 +190,19 @@ public class ListActionTest { assertThat(license.hasInvalidExpiration()).isFalse(); } + @Test + public void return_bad_server_id_when_server_has_no_server_id() throws Exception { + setUserAsSystemAdmin(); + addLicenseSetting(LICENSE_KEY_SAMPLE, LICENSE_NAME_SAMPLE, + createBase64License(ORGANISATION_SAMPLE, PRODUCT_SAMPLE, SERVER_ID_SAMPLE, EXPIRATION_SAMPLE, TYPE_SAMPLE, Collections.emptyMap())); + + ListWsResponse result = executeRequest(); + + assertThat(result.getLicensesList()).hasSize(1); + Licenses.License license = result.getLicenses(0); + assertThat(license.getInvalidServerId()).isTrue(); + } + @Test public void does_not_return_invalid_server_id_when_all_servers_accepted_and_no_server_id_setting() throws Exception { setUserAsSystemAdmin(); -- 2.39.5