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: If2cb9fa96effea7ce55a4ffe6d1666ca7521e1fbtags/7.4.0.beta1
<path id="classpath.compile.custom"> | <path id="classpath.compile.custom"> | ||||
<fileset file="${gwt.dev.jar}" /> | <fileset file="${gwt.dev.jar}" /> | ||||
</path> | </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 id="compiler.includes"> | ||||
<union refid="client-compiler.gwt.includes" /> | <union refid="client-compiler.gwt.includes" /> | ||||
<fileset dir="${result.dir}"> | <fileset dir="${result.dir}"> | ||||
</target> | </target> | ||||
<target name="test" depends="checkstyle"> | <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> | </target> | ||||
</project> | </project> |
<conf name="build" /> | <conf name="build" /> | ||||
<conf name="build-provided" /> | <conf name="build-provided" /> | ||||
<conf name="ide" visibility="private" /> | <conf name="ide" visibility="private" /> | ||||
<conf name="test" visibility="private" /> | |||||
</configurations> | </configurations> | ||||
<publications> | <publications> | ||||
<artifact type="jar" ext="jar" /> | <artifact type="jar" ext="jar" /> | ||||
<dependency org="com.vaadin" name="vaadin-server" | <dependency org="com.vaadin" name="vaadin-server" | ||||
rev="${vaadin.version}" conf="build" /> | rev="${vaadin.version}" conf="build" /> | ||||
<dependency org="com.vaadin" name="vaadin-client" | <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" | <dependency org="com.vaadin" name="vaadin-sass-compiler" | ||||
rev="${vaadin.sass.version}" conf="build,ide->default"> | rev="${vaadin.sass.version}" conf="build,ide->default"> | ||||
<!-- remove cssparser override once sass-compiler is updated --> | <!-- remove cssparser override once sass-compiler is updated --> | ||||
<dependency org="com.vaadin" name="vaadin-client-compiler-deps" | <dependency org="com.vaadin" name="vaadin-client-compiler-deps" | ||||
rev="1.2.0" conf="build,ide -> default" /> | rev="1.2.0" conf="build,ide -> default" /> | ||||
<dependency org="junit" name="junit" rev="4.11" | |||||
conf="test,ide -> default" /> | |||||
</dependencies> | </dependencies> | ||||
</ivy-module> | </ivy-module> |
import org.apache.commons.io.IOUtils; | import org.apache.commons.io.IOUtils; | ||||
import elemental.json.JsonException; | import elemental.json.JsonException; | ||||
import elemental.json.JsonNull; | |||||
import elemental.json.JsonObject; | import elemental.json.JsonObject; | ||||
import elemental.json.impl.JsonUtil; | import elemental.json.impl.JsonUtil; | ||||
/** | /** | ||||
* This class is able to validate the vaadin CVAL license. | * This class is able to validate the vaadin CVAL license. | ||||
* | |||||
* | |||||
* It reads the developer license file and asks the server to validate the | * 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 | * licenseKey. If the license is invalid it throws an exception with the | ||||
* information about the problem and the server response. | * information about the problem and the server response. | ||||
* | |||||
* | |||||
* @since 7.3 | * @since 7.3 | ||||
*/ | */ | ||||
public final class CvalChecker { | public final class CvalChecker { | ||||
private static <T> T get(JsonObject o, String k, Class<T> clz) { | private static <T> T get(JsonObject o, String k, Class<T> clz) { | ||||
Object ret = null; | Object ret = null; | ||||
try { | try { | ||||
if (o == null || o.get(k) == null | |||||
|| o.get(k) instanceof JsonNull) { | |||||
return null; | |||||
} | |||||
if (clz == String.class) { | if (clz == String.class) { | ||||
ret = o.getString(k); | ret = o.getString(k); | ||||
} else if (clz == JsonObject.class) { | } else if (clz == JsonObject.class) { | ||||
/** | /** | ||||
* Given a product name returns the name of the file with the license key. | * Given a product name returns the name of the file with the license key. | ||||
* | |||||
* | |||||
* Traditionally we have delivered license keys with a name like | * Traditionally we have delivered license keys with a name like | ||||
* 'vaadin.touchkit.developer.license' but our database product name is | * 'vaadin.touchkit.developer.license' but our database product name is | ||||
* 'vaadin-touchkit' so we have to replace '-' by '.' to maintain | * 'vaadin-touchkit' so we have to replace '-' by '.' to maintain | ||||
/** | /** | ||||
* Validate whether there is a valid license key for a product. | * Validate whether there is a valid license key for a product. | ||||
* | |||||
* | |||||
* @param productName | * @param productName | ||||
* for example vaadin-touchkit | * for example vaadin-touchkit | ||||
* @param productVersion | * @param productVersion |
static final String responseJson = "{'licenseKey':'" + VALID_KEY + "'," | static final String responseJson = "{'licenseKey':'" + VALID_KEY + "'," | ||||
+ "'licensee':'Test User','type':'normal'," | + "'licensee':'Test User','type':'normal'," | ||||
+ "'expiredEpoch':'1893511225000'," + "'product':{'name':'" | |||||
+ "'expiredEpoch':1893511225000," + "'product':{'name':'" | |||||
+ productNameCval + "', 'version': 2}}"; | + 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; | private static ByteArrayOutputStream outContent; | ||||
// A provider returning a valid license if productKey is valid or null if | // A provider returning a valid license if productKey is valid or null if | ||||
static final CvalServer unlimitedLicenseProvider = new CvalServer() { | static final CvalServer unlimitedLicenseProvider = new CvalServer() { | ||||
@Override | @Override | ||||
String askServer(String productName, String productKey, int timeout) { | String askServer(String productName, String productKey, int timeout) { | ||||
return responseJson.replaceFirst("1893511225000", ""); | |||||
return responseJson.replaceFirst("1893511225000", "null"); | |||||
} | } | ||||
}; | }; | ||||
// An unreachable provider | // An unreachable provider | ||||
return super.askServer(productName, productKey, 1000); | 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 CvalChecker licenseChecker; | ||||
private String licenseName; | private String licenseName; | ||||
Assert.assertTrue(cacheExists(productNameCval)); | Assert.assertTrue(cacheExists(productNameCval)); | ||||
// Check an unlimited license | // Check an unlimited license | ||||
deleteCache(productNameCval); | |||||
licenseChecker.setLicenseProvider(unlimitedLicenseProvider); | licenseChecker.setLicenseProvider(unlimitedLicenseProvider); | ||||
licenseChecker | licenseChecker | ||||
.validateProduct(productNameCval, "2.1", productTitleCval); | .validateProduct(productNameCval, "2.1", productTitleCval); | ||||
assertEquals(productNameCval, expected.name); | assertEquals(productNameCval, expected.name); | ||||
} | } | ||||
Assert.assertTrue(cacheExists(productNameCval)); | Assert.assertTrue(cacheExists(productNameCval)); | ||||
deleteCache(productNameCval); | |||||
licenseChecker.setLicenseProvider(nullVersionLicenseProvider); | |||||
licenseChecker | |||||
.validateProduct(productNameCval, "2.1", productTitleCval); | |||||
Assert.assertTrue(cacheExists(productNameCval)); | |||||
} | } | ||||
/* | /* | ||||
testManifest.getMainAttributes().putValue(VAADIN_ADDON_VERSION, "2"); | testManifest.getMainAttributes().putValue(VAADIN_ADDON_VERSION, "2"); | ||||
// Create a temporary Jar | // 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(); | testJarFile.deleteOnExit(); | ||||
JarOutputStream target = new JarOutputStream(new FileOutputStream( | JarOutputStream target = new JarOutputStream(new FileOutputStream( | ||||
testJarFile), testManifest); | testJarFile), testManifest); |