changeset 1194:45c4323f5df3

Added tool for manipulating deployment-properties during tests run * tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java: is now using DeploymentPropetiesModifier * tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java: same * tests/reproducers/signed/SignedAppletManifestSpecifiesSandbox/testcases/SignedAppletManifestSpecifiesSandboxTests.java: same * tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropetiesModifier.java: new tool to manipualte deployment properties in runtime.
author Jiri Vanek <jvanek@redhat.com>
date Fri, 03 Apr 2015 16:48:26 +0200
parents 85505d8c9f3c
children 7de7aa9d01c2
files ChangeLog tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java tests/reproducers/signed/SignedAppletManifestSpecifiesSandbox/testcases/SignedAppletManifestSpecifiesSandboxTests.java tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropetiesModifier.java
diffstat 5 files changed, 159 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 02 21:28:10 2015 +0200
+++ b/ChangeLog	Fri Apr 03 16:48:26 2015 +0200
@@ -1,3 +1,15 @@
+2015-04-03  Lukasz Dracz  <ldracz@redhat.com>
+
+	Added tool for manipulating deployment-properties during tests run
+	* tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java:
+	is now using DeploymentPropetiesModifier
+	* tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java:
+	same
+	* tests/reproducers/signed/SignedAppletManifestSpecifiesSandbox/testcases/SignedAppletManifestSpecifiesSandboxTests.java:
+	same
+	* tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropetiesModifier.java:
+	new tool to manipualte deployment properties in runtime.
+
 2015-04-02  Jiri Vanek  <jvanek@redhat.com>
 
 	InfrastructureFileDescriptor got setter
--- a/tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java	Thu Apr 02 21:28:10 2015 +0200
+++ b/tests/reproducers/custom/PartiallySignedAppletManifestSpecifiesSandbox/testcases/PartiallySignedAppletManifestSpecifiesSandboxTests.java	Fri Apr 03 16:48:26 2015 +0200
@@ -47,8 +47,12 @@
 import net.sourceforge.jnlp.browsertesting.BrowserTest;
 import net.sourceforge.jnlp.browsertesting.Browsers;
 import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
+import net.sourceforge.jnlp.config.DeploymentConfiguration;
 
 import net.sourceforge.jnlp.config.PathsAndFiles;
+import net.sourceforge.jnlp.runtime.ManifestAttributesChecker;
+import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel;
+import net.sourceforge.jnlp.tools.DeploymentPropetiesModifier;
 import net.sourceforge.jnlp.util.FileUtils;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -64,50 +68,22 @@
     private static final String STACKTRACE_NOT_GRANT_PERMISSIONS_TYPE = "Cannot grant permissions to unsigned jars";
     private static final String USER_HOME = System.getProperty("user.home");
 
-    private static File deployFile;
-    private static String attributesCheck;
-    private static String securityLevel;
+    private static DeploymentPropetiesModifier permissionsModifier;
+    private static DeploymentPropetiesModifier securityLevelModifier;
 
     @BeforeClass
     public static void setupDeploymentProperties() throws IOException {
-        deployFile = PathsAndFiles.USER_DEPLOYMENT_FILE.getFile();
-        String properties = FileUtils.loadFileAsString(deployFile);
+        permissionsModifier = new DeploymentPropetiesModifier();
+        permissionsModifier.setProperties(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK,  ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.PERMISSIONS.toString());
 
-        for (String line : properties.split("\n")) {
-            if (line.contains("deployment.manifest.attribute.check")) {
-                attributesCheck = line;
-                properties = properties.replace(line, "deployment.manifest.attributes.check=PERMISSIONS\n");
-            }
-            if (line.contains("deployment.security.level")) {
-                securityLevel = line;
-                properties = properties.replace(line, "deployment.security.level=ALLOW_UNSIGNED\n");
-            }
-        }
-        if (attributesCheck == null) {
-            properties += "deployment.manifest.attributes.check=PERMISSIONS\n";
-        }
-        if (securityLevel == null) {
-            properties += "deployment.security.level=ALLOW_UNSIGNED\n";
-        }
-
-        FileUtils.saveFile(properties, deployFile);
+        securityLevelModifier = new DeploymentPropetiesModifier();
+        securityLevelModifier.setProperties(DeploymentConfiguration.KEY_SECURITY_LEVEL, AppletSecurityLevel.ALLOW_UNSIGNED.toChars());
     }
 
     @AfterClass
     public static void setbackDeploymentProperties() throws IOException {
-        String properties = FileUtils.loadFileAsString(deployFile);
-        if (attributesCheck != null) {
-            properties = properties.replace("deployment.manifest.attributes.check=PERMISSIONS\n", attributesCheck);
-        } else {
-            properties = properties.replace("deployment.manifest.attributes.check=PERMISSIONS\n", "");
-        }
-
-        if (securityLevel != null) {
-            properties = properties.replace("deployment.security.level=ALLOW_UNSIGNED\n", securityLevel);
-        } else {
-            properties = properties.replace("deployment.security.level=ALLOW_UNSIGNED\n", "");
-        }
-        FileUtils.saveFile(properties, deployFile);
+        securityLevelModifier.restoreProperties();
+        permissionsModifier.restoreProperties();
     }
 
     @Test
--- a/tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java	Thu Apr 02 21:28:10 2015 +0200
+++ b/tests/reproducers/signed/CodeBaseManifestEntrySignedMatching/testcases/CodeBaseManifestEntrySignedMatching.java	Fri Apr 03 16:48:26 2015 +0200
@@ -49,8 +49,13 @@
 import net.sourceforge.jnlp.browsertesting.Browsers;
 import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
 import net.sourceforge.jnlp.closinglisteners.RulesFolowingClosingListener;
+import net.sourceforge.jnlp.config.DeploymentConfiguration;
+import net.sourceforge.jnlp.runtime.ManifestAttributesChecker;
+import net.sourceforge.jnlp.tools.DeploymentPropetiesModifier;
 import net.sourceforge.jnlp.util.FileUtils;
+import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 public class CodeBaseManifestEntrySignedMatching extends BrowserTest {
@@ -67,6 +72,19 @@
         /*5*/ "CBCheckSignedAppletDontMatchException",
         /*6*/ "CBCheckSignedFail"};
 
+    private static DeploymentPropetiesModifier codebaseModifier;
+
+    @BeforeClass
+    public static void setupDeploymentProperties() throws IOException {
+        codebaseModifier = new DeploymentPropetiesModifier();
+        codebaseModifier.setProperties(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.CODEBASE.toString());
+    }
+
+    @AfterClass
+    public static void setbackDeploymentProperties() throws IOException {
+        codebaseModifier.restoreProperties();
+    }
+
     public static String getMessage(int i) {
         try {
             String s = "";//_cs, _de, _pl
--- a/tests/reproducers/signed/SignedAppletManifestSpecifiesSandbox/testcases/SignedAppletManifestSpecifiesSandboxTests.java	Thu Apr 02 21:28:10 2015 +0200
+++ b/tests/reproducers/signed/SignedAppletManifestSpecifiesSandbox/testcases/SignedAppletManifestSpecifiesSandboxTests.java	Fri Apr 03 16:48:26 2015 +0200
@@ -37,9 +37,7 @@
 
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
 import java.io.IOException;
-import java.util.List;
 
 import net.sourceforge.jnlp.ProcessResult;
 import net.sourceforge.jnlp.annotations.Bug;
@@ -48,10 +46,10 @@
 import net.sourceforge.jnlp.browsertesting.BrowserTest;
 import net.sourceforge.jnlp.browsertesting.Browsers;
 import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
+import net.sourceforge.jnlp.config.DeploymentConfiguration;
+import net.sourceforge.jnlp.runtime.ManifestAttributesChecker;
+import net.sourceforge.jnlp.tools.DeploymentPropetiesModifier;
 
-import net.sourceforge.jnlp.config.PathsAndFiles;
-import net.sourceforge.jnlp.runtime.ManifestAttributesChecker;
-import net.sourceforge.jnlp.util.FileUtils;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -66,37 +64,17 @@
     private static final String JNLP_EXPECTED_STDOUT = "Initialization Error";
     private static final String JNLP_EXPECTED_STDERR = "net.sourceforge.jnlp.LaunchException";
 
-    private static File deployFile;
-    private static String attributesCheck;
+    private static DeploymentPropetiesModifier deploymentPropetiesModifier;
 
     @BeforeClass
     public static void setupDeploymentProperties() throws IOException {
-        deployFile = PathsAndFiles.USER_DEPLOYMENT_FILE.getFile();
-        String properties = FileUtils.loadFileAsString(deployFile);
-
-        for (String line : properties.split("\n")) {
-            if (line.contains("deployment.manifest.attribute.check")) {
-                attributesCheck = line;
-                properties = properties.replace(line, "deployment.manifest.attributes.check=PERMISSIONS\n");
-            }
-        }
-        if (attributesCheck == null) {
-            properties += "deployment.manifest.attributes.check=PERMISSIONS\n";
-        }
-
-        FileUtils.saveFile(properties, deployFile);
+        deploymentPropetiesModifier = new DeploymentPropetiesModifier();
+        deploymentPropetiesModifier.setProperties(DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.PERMISSIONS.toString());
     }
 
     @AfterClass
     public static void setbackDeploymentProperties() throws IOException {
-        String properties = FileUtils.loadFileAsString(deployFile);
-        if (attributesCheck != null) {
-            properties = properties.replace("deployment.manifest.attributes.check=PERMISSIONS\n", attributesCheck);
-        } else {
-            properties = properties.replace("deployment.manifest.attributes.check=PERMISSIONS\n", "");
-        }
-
-        FileUtils.saveFile(properties, deployFile);
+        deploymentPropetiesModifier.restoreProperties();
     }
 
     @Test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/tools/DeploymentPropetiesModifier.java	Fri Apr 03 16:48:26 2015 +0200
@@ -0,0 +1,110 @@
+/*
+   Copyright (C) 2015 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.
+*/
+
+package net.sourceforge.jnlp.tools;
+
+import java.io.IOException;
+
+import net.sourceforge.jnlp.config.PathsAndFiles;
+import net.sourceforge.jnlp.util.FileUtils;
+
+public class DeploymentPropetiesModifier {
+
+    private final PathsAndFiles.InfrastructureFileDescriptor src;
+    private String savedValue;
+    private String requestedProperty;
+    private String requestedValue;
+    private boolean isPropertiesSet;
+
+    public DeploymentPropetiesModifier() {
+        this(PathsAndFiles.USER_DEPLOYMENT_FILE);
+    }
+
+    public DeploymentPropetiesModifier(PathsAndFiles.InfrastructureFileDescriptor src) {
+        this.src = src;
+        isPropertiesSet = false;
+    }
+
+    public void setProperties(String property, String value) throws IOException {
+        if (isPropertiesSet) {
+            throw new IllegalStateException();
+        }
+        isPropertiesSet = true;
+        requestedProperty = property;
+        requestedValue = value;
+
+        setDeploymentProperties(requestedProperty, requestedValue);
+    }
+
+    public void restoreProperties() throws IOException {
+        if (!isPropertiesSet) {
+            throw new IllegalStateException();
+        }
+        isPropertiesSet = false;
+
+        restoreDeploymentProperties();
+    }
+
+    private void setDeploymentProperties(String property, String value) throws IOException {
+        String properties = FileUtils.loadFileAsString(src.getFile());
+
+        for (String line : properties.split("\n")) {
+            if (line.contains(property)) {
+                savedValue = line;
+                properties = properties.replace(line, property + "=" + value + "\n");
+            }
+        }
+
+        if (savedValue == null) {
+            properties += property + "=" + value + "\n";
+        }
+
+        FileUtils.saveFile(properties, src.getFile());
+    }
+
+    private void restoreDeploymentProperties() throws IOException {
+        String properties = FileUtils.loadFileAsString(src.getFile());
+        if (savedValue != null) {
+            properties = properties.replace(requestedProperty + "=" + requestedValue + "\n", savedValue);
+        } else {
+            properties = properties.replace(requestedProperty + "=" + requestedValue + "\n", "");
+        }
+
+        FileUtils.saveFile(properties, src.getFile());
+    }
+
+}