]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8039 Return invalid server id when no server id generated and license not set... 1219/head
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 7 Sep 2016 15:13:06 +0000 (17:13 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 7 Sep 2016 15:14:19 +0000 (17:14 +0200)
server/sonar-server/src/main/java/org/sonar/server/license/ws/ListAction.java
server/sonar-server/src/test/java/org/sonar/server/license/ws/ListActionTest.java

index f7f914b4f8eba38d3c2312de75c44fbefe4bd6f8..39cf1b3d560fa37c9b4ed1e509bdff8fb24121d1 100644 (file)
@@ -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);
       }
     }
index 0ee5b0633c92876871d05a845e6e7e062e53d78c..d831532356dfe306f52386b33f462ef020c88100 100644 (file)
@@ -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();