Browse Source

Fix the license checker after elemental.json #15383

The elemental.json update changed how null values and string
representations of numbers were parsed, which caused a lot of
tests for CvalChecker to fail. Unfortunately the tests were
never run in an automated fashion, which means that they were
never discovered until we stumbled upon it due to the issue
reported in #15383

Change-Id: If2cb9fa96effea7ce55a4ffe6d1666ca7521e1fb
tags/7.4.0.beta1
Jonatan Kronqvist 9 years ago
parent
commit
272711e6f7

+ 12
- 3
client-compiler/build.xml View File

@@ -16,7 +16,16 @@
<path id="classpath.compile.custom">
<fileset file="${gwt.dev.jar}" />
</path>

<path id="classpath.test.custom">
<fileset dir="${result.dir}/classes">
<include name="**/*" />
</fileset>
</path>
<property name="extra.classes" value="**/*.properties" />
<!-- don't try to copy the same files twice (first from classes and then
from sources) in order for the build not to fail when packaging the
JAR -->
<property name="jar.exclude" value="**/*.properties" />
<union id="compiler.includes">
<union refid="client-compiler.gwt.includes" />
<fileset dir="${result.dir}">
@@ -62,8 +71,8 @@
</target>

<target name="test" depends="checkstyle">
<!--<antcall target="common.test.run" /> -->
<echo>WHAT? No tests for ${module.name}!</echo>
<antcall target="common.test.run" />
<!--<echo>WHAT? No tests for ${module.name}!</echo>-->
</target>

</project>

+ 6
- 1
client-compiler/ivy.xml View File

@@ -11,6 +11,7 @@
<conf name="build" />
<conf name="build-provided" />
<conf name="ide" visibility="private" />
<conf name="test" visibility="private" />
</configurations>
<publications>
<artifact type="jar" ext="jar" />
@@ -24,7 +25,7 @@
<dependency org="com.vaadin" name="vaadin-server"
rev="${vaadin.version}" conf="build" />
<dependency org="com.vaadin" name="vaadin-client"
rev="${vaadin.version}" conf="build" />
rev="${vaadin.version}" conf="build,test" />
<dependency org="com.vaadin" name="vaadin-sass-compiler"
rev="${vaadin.sass.version}" conf="build,ide->default">
<!-- remove cssparser override once sass-compiler is updated -->
@@ -96,6 +97,10 @@
<dependency org="com.vaadin" name="vaadin-client-compiler-deps"
rev="1.2.0" conf="build,ide -> default" />

<dependency org="junit" name="junit" rev="4.11"
conf="test,ide -> default" />


</dependencies>

</ivy-module>

+ 9
- 4
client-compiler/src/com/vaadin/tools/CvalChecker.java View File

@@ -35,16 +35,17 @@ import java.util.prefs.Preferences;
import org.apache.commons.io.IOUtils;

import elemental.json.JsonException;
import elemental.json.JsonNull;
import elemental.json.JsonObject;
import elemental.json.impl.JsonUtil;

/**
* This class is able to validate the vaadin CVAL license.
*
*
* It reads the developer license file and asks the server to validate the
* licenseKey. If the license is invalid it throws an exception with the
* information about the problem and the server response.
*
*
* @since 7.3
*/
public final class CvalChecker {
@@ -80,6 +81,10 @@ public final class CvalChecker {
private static <T> T get(JsonObject o, String k, Class<T> clz) {
Object ret = null;
try {
if (o == null || o.get(k) == null
|| o.get(k) instanceof JsonNull) {
return null;
}
if (clz == String.class) {
ret = o.getString(k);
} else if (clz == JsonObject.class) {
@@ -299,7 +304,7 @@ public final class CvalChecker {

/**
* Given a product name returns the name of the file with the license key.
*
*
* Traditionally we have delivered license keys with a name like
* 'vaadin.touchkit.developer.license' but our database product name is
* 'vaadin-touchkit' so we have to replace '-' by '.' to maintain
@@ -340,7 +345,7 @@ public final class CvalChecker {

/**
* Validate whether there is a valid license key for a product.
*
*
* @param productName
* for example vaadin-touchkit
* @param productVersion

+ 23
- 4
client-compiler/tests/src/com/vaadin/tools/CvalCheckerTest.java View File

@@ -66,9 +66,14 @@ public class CvalCheckerTest {

static final String responseJson = "{'licenseKey':'" + VALID_KEY + "',"
+ "'licensee':'Test User','type':'normal',"
+ "'expiredEpoch':'1893511225000'," + "'product':{'name':'"
+ "'expiredEpoch':1893511225000," + "'product':{'name':'"
+ productNameCval + "', 'version': 2}}";

static final String responseJsonWithNullVersion = "{'licenseKey':'" + VALID_KEY + "',"
+ "'licensee':'Test User','type':'normal',"
+ "'expiredEpoch':1893511225000," + "'product':{'name':'"
+ productNameCval + "', 'version': null}}";

private static ByteArrayOutputStream outContent;

// A provider returning a valid license if productKey is valid or null if
@@ -114,7 +119,7 @@ public class CvalCheckerTest {
static final CvalServer unlimitedLicenseProvider = new CvalServer() {
@Override
String askServer(String productName, String productKey, int timeout) {
return responseJson.replaceFirst("1893511225000", "");
return responseJson.replaceFirst("1893511225000", "null");
}
};
// An unreachable provider
@@ -128,6 +133,14 @@ public class CvalCheckerTest {
return super.askServer(productName, productKey, 1000);
}
};
// A provider with 'null' in the version field
static final CvalServer nullVersionLicenseProvider = new CvalServer() {
@Override
String askServer(String productName, String productKey, int timeout)
throws IOException {
return responseJsonWithNullVersion;
}
};

private CvalChecker licenseChecker;
private String licenseName;
@@ -245,6 +258,7 @@ public class CvalCheckerTest {
Assert.assertTrue(cacheExists(productNameCval));

// Check an unlimited license
deleteCache(productNameCval);
licenseChecker.setLicenseProvider(unlimitedLicenseProvider);
licenseChecker
.validateProduct(productNameCval, "2.1", productTitleCval);
@@ -262,6 +276,12 @@ public class CvalCheckerTest {
assertEquals(productNameCval, expected.name);
}
Assert.assertTrue(cacheExists(productNameCval));

deleteCache(productNameCval);
licenseChecker.setLicenseProvider(nullVersionLicenseProvider);
licenseChecker
.validateProduct(productNameCval, "2.1", productTitleCval);
Assert.assertTrue(cacheExists(productNameCval));
}

/*
@@ -282,8 +302,7 @@ public class CvalCheckerTest {
testManifest.getMainAttributes().putValue(VAADIN_ADDON_VERSION, "2");

// Create a temporary Jar
String tmpDir = System.getProperty("java.io.tmpdir");
File testJarFile = new File(tmpDir + "vaadin." + productName + ".jar");
File testJarFile = File.createTempFile("vaadin." + productName, "jar");
testJarFile.deleteOnExit();
JarOutputStream target = new JarOutputStream(new FileOutputStream(
testJarFile), testManifest);

Loading…
Cancel
Save