From: Duarte Meneses Date: Wed, 18 Oct 2017 13:02:23 +0000 (+0200) Subject: SONAR-9939 Improve parsing of license X-Git-Tag: 6.7-RC1~82 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=69d79bcad21aa2ad801e3e05e4163b89071936b6;p=sonarqube.git SONAR-9939 Improve parsing of license --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/edition/License.java b/server/sonar-server/src/main/java/org/sonar/server/edition/License.java index fbfdaef18a9..6749a29176f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/edition/License.java +++ b/server/sonar-server/src/main/java/org/sonar/server/edition/License.java @@ -77,11 +77,11 @@ public class License { Properties props = new Properties(); props.load(new StringReader(data)); - Collection 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"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/edition/LicenseTest.java b/server/sonar-server/src/test/java/org/sonar/server/edition/LicenseTest.java index 4f155e97a7c..8b5509a5aa1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/edition/LicenseTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/edition/LicenseTest.java @@ -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.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();