]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9939 Improve parsing of license
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 18 Oct 2017 13:02:23 +0000 (15:02 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 23 Oct 2017 15:01:13 +0000 (08:01 -0700)
server/sonar-server/src/main/java/org/sonar/server/edition/License.java
server/sonar-server/src/test/java/org/sonar/server/edition/LicenseTest.java

index fbfdaef18a906ec2eb8ef6d4b420cf3fd93dc50f..6749a29176f5e3631fc6b6ecfe97c1d3d9c8c78b 100644 (file)
@@ -77,11 +77,11 @@ public class License {
       Properties props = new Properties();
       props.load(new StringReader(data));
 
-      Collection<String> plugins = Arrays.asList(StringUtils.split(props.getProperty(PLUGINS_KEY), ','));
+      String[] plugins = StringUtils.split(props.getProperty(PLUGINS_KEY), ',');
       String editionKey = props.getProperty(EDITION_KEY);
 
-      if (editionKey != null && !plugins.isEmpty()) {
-        return Optional.of(new License(editionKey, plugins, base64));
+      if (StringUtils.isNotBlank(editionKey) && plugins.length > 0) {
+        return Optional.of(new License(editionKey, Arrays.asList(plugins), base64));
       } else {
         LOG.debug("Failed to parse license: no edition key and/or no plugin found");
       }
index 4f155e97a7c72967127bca0c18a8a68befb71714..8b5509a5aa174ba29076f92e5f9ccceae7af7bf0 100644 (file)
@@ -110,6 +110,20 @@ public class LicenseTest {
     assertThat(license).isEmpty();
   }
 
+  @Test
+  public void parse_is_empty_if_license_has_empty_edition_key() throws IOException {
+    Properties props = new Properties();
+    props.setProperty("Plugins", "p1");
+    props.setProperty("Edition", "");
+    StringWriter writer = new StringWriter();
+    props.store(writer, "");
+
+    byte[] encoded = Base64.getEncoder().encode(writer.toString().getBytes());
+
+    Optional<License> license = License.parse(new String(encoded));
+    assertThat(license).isEmpty();
+  }
+
   @Test
   public void parse_is_empty_if_license_has_no_edition_key() throws IOException {
     Properties props = new Properties();