[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-distro-pkg-dev
Subject:    /hg/icedtea-web: PolicyEditor dies given invalid -codebase -sign...
From:       aazores () icedtea ! classpath ! org
Date:       2015-08-24 16:38:12
Message-ID: hg.18e401faa1b9.1440434292.8643924302249223276 () icedtea ! classpath ! org
[Download RAW message or body]

changeset 18e401faa1b9 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=18e401faa1b9
author: Andrew Azores <aazores@redhat.com>
date: Mon Aug 24 12:28:23 2015 -0400

	PolicyEditor dies given invalid -codebase -signedby or -principals arguments

	* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
	(main): extracted helper methods for getting codebase, signedBy, principals
	arguments.
	(getCodebaseArgument, getSignedByArgument, getPrincipalsArgument): new
	methods
	(cleanFilePathArgument): make parameter final for consistent style
	* tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java
	(testGetCodebaseArgument, testGetCodebaseArgument2,
	testGetCodebaseArgument3, testGetCodebaseArgumentWhenNotProvided,
	testGetPrincipalsArgument, testGetPrincipalsArgument2,
	testGetPrincipalsArgument3, testGetPrincipalsArgumentWhenNotProvided,
	testGetSignedByArgument, testGetSignedByArgumentWhenNotProvided): new tests


diffstat:

 ChangeLog                                                                        |  \
16 ++  netx/net/sourceforge/jnlp/resources/Messages.properties                        \
|   2 +  netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java            \
|  57 ++++++-  tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java \
|  78 ++++++++++  4 files changed, 143 insertions(+), 10 deletions(-)

diffs (219 lines):

diff -r bbd5fd366c96 -r 18e401faa1b9 ChangeLog
--- a/ChangeLog	Wed Aug 19 10:48:35 2015 -0400
+++ b/ChangeLog	Mon Aug 24 12:28:23 2015 -0400
@@ -1,3 +1,19 @@
+2015-08-19  Andrew Azores  <aazores@redhat.com>
+
+	PolicyEditor dies given invalid -codebase -signedby or -principals arguments
+	* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
+	(main): extracted helper methods for getting codebase, signedBy, principals
+	arguments.
+	(getCodebaseArgument, getSignedByArgument, getPrincipalsArgument): new
+	methods
+	(cleanFilePathArgument): make parameter final for consistent style
+	* tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java
+	(testGetCodebaseArgument, testGetCodebaseArgument2,
+	testGetCodebaseArgument3, testGetCodebaseArgumentWhenNotProvided,
+	testGetPrincipalsArgument, testGetPrincipalsArgument2,
+	testGetPrincipalsArgument3, testGetPrincipalsArgumentWhenNotProvided,
+	testGetSignedByArgument, testGetSignedByArgumentWhenNotProvided): new tests
+
 2015-08-19  Andrew Azores  <aazores@redhat.com>
 
 	Sort identifiers list in PolicyEditor
diff -r bbd5fd366c96 -r 18e401faa1b9 \
                netx/net/sourceforge/jnlp/resources/Messages.properties
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties	Wed Aug 19 10:48:35 \
                2015 -0400
+++ b/netx/net/sourceforge/jnlp/resources/Messages.properties	Mon Aug 24 12:28:23 \
2015 -0400 @@ -780,6 +780,8 @@
 PEClipboardAccessError=Could not read from clipboard
 PEDefaultFileFilePathSpecifiedError=Either -file (or simply a main argument) or \
-defaultfile may be specified, but not both  \
PEMainArgAndFileSwitchSpecifiedError=Either -file may be specified or a main argument \
may be specified, but not both +PESignedByEmpty=SignedBy cannot be empty
+PEInvalidUrl=Invalid URL: {0}
 
 PEHelpMenu=Help
 PEAboutPolicyEditorItem=About PolicyEditor
diff -r bbd5fd366c96 -r 18e401faa1b9 \
                netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java	Wed Aug 19 \
                10:48:35 2015 -0400
+++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java	Mon Aug 24 \
12:28:23 2015 -0400 @@ -1758,18 +1758,15 @@
             // not really important, so just ignore
         }
 
+        final String filepath = getFilePathArgument(optionParser);
+        final String codebase = getCodebaseArgument(optionParser);
+        final String signedBy = getSignedByArgument(optionParser);
+        final Set<PolicyParser.PrincipalEntry> principals = \
getPrincipalsArgument(optionParser); +
         SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
-                final String filepath = getFilePathArgument(optionParser);
                 final PolicyEditorWindow frame = getPolicyEditorFrame(filepath);
-                final String codebase = \
                optionParser.getParam(OptionsDefinitions.OPTIONS.CODEBASE);
-                final String signedBy = \
                optionParser.getParam(OptionsDefinitions.OPTIONS.SIGNEDBY);
-                final List<String> rawPrincipals = \
                optionParser.getParams(OptionsDefinitions.OPTIONS.PRINCIPALS);
-                final Set<PolicyParser.PrincipalEntry> principals = new HashSet<>();
-                for (int i = 0; i < rawPrincipals.size(); i+= 2) {
-                    principals.add(new \
                PolicyParser.PrincipalEntry(rawPrincipals.get(i), rawPrincipals.get(i \
                + 1)));
-                }
                 frame.getPolicyEditor().openPolicyFileSynchronously();
                 frame.getPolicyEditor().addNewEntry(new PolicyIdentifier(signedBy, \
principals, codebase));  frame.asWindow().setVisible(true);
@@ -1777,7 +1774,47 @@
         });
     }
 
-    static String getFilePathArgument(OptionParser optionParser) {
+    static String getCodebaseArgument(final OptionParser optionParser) {
+        if (optionParser.hasOption(OptionsDefinitions.OPTIONS.CODEBASE)) {
+            final String codebase = \
optionParser.getParam(OptionsDefinitions.OPTIONS.CODEBASE); +            try {
+                new URL(codebase);
+            } catch (final MalformedURLException e) {
+                throw new IllegalArgumentException(R("PEInvalidUrl", codebase), e);
+            }
+            return codebase;
+        } else {
+            return null;
+        }
+    }
+
+    static String getSignedByArgument(final OptionParser optionParser) {
+        if (optionParser.hasOption(OptionsDefinitions.OPTIONS.SIGNEDBY)) {
+            final String signedBy = \
optionParser.getParam(OptionsDefinitions.OPTIONS.SIGNEDBY); +            if \
(signedBy.isEmpty()) { +                throw new \
IllegalArgumentException(R("PESignedByEmpty")); +            } else {
+                return signedBy;
+            }
+        } else {
+            return null;
+        }
+    }
+
+    static Set<PolicyParser.PrincipalEntry> getPrincipalsArgument(final OptionParser \
optionParser) { +        if \
(optionParser.hasOption(OptionsDefinitions.OPTIONS.PRINCIPALS)) { +            final \
List<String> rawPrincipals = \
optionParser.getParams(OptionsDefinitions.OPTIONS.PRINCIPALS); +            final \
Set<PolicyParser.PrincipalEntry> principals = new HashSet<>(); +            for (int \
i = 0; i < rawPrincipals.size(); i+= 2) { +                principals.add(new \
PolicyParser.PrincipalEntry(rawPrincipals.get(i), rawPrincipals.get(i + 1))); +       \
} +            return principals;
+        } else {
+            return Collections.emptySet();
+        }
+    }
+
+    static String getFilePathArgument(final OptionParser optionParser) {
         final boolean openDefaultFile = \
                optionParser.hasOption(OptionsDefinitions.OPTIONS.DEFAULTFILE);
         final boolean hasFileArgument = \
optionParser.hasOption(OptionsDefinitions.OPTIONS.FILE);  final boolean \
hasMainArgument = optionParser.mainArgExists(); @@ -1803,7 +1840,7 @@
         return filepath;
     }
 
-    private static String cleanFilePathArgument(String filepath) {
+    private static String cleanFilePathArgument(final String filepath) {
         if (filepath == null) {
             return null;
         } else if (filepath.isEmpty() || filepath.trim().isEmpty()) {
diff -r bbd5fd366c96 -r 18e401faa1b9 \
                tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java
                
--- a/tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java	Wed \
                Aug 19 10:48:35 2015 -0400
+++ b/tests/netx/unit/net/sourceforge/jnlp/security/policyeditor/PolicyEditorTest.java	Mon \
Aug 24 12:28:23 2015 -0400 @@ -46,12 +46,14 @@
 import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 import net.sourceforge.jnlp.OptionsDefinitions;
 import net.sourceforge.jnlp.config.PathsAndFiles;
 import net.sourceforge.jnlp.util.optionparser.OptionParser;
+import net.sourceforge.jnlp.util.optionparser.UnevenParameterException;
 import org.junit.Before;
 import org.junit.Test;
 import sun.security.provider.PolicyParser;
@@ -375,4 +377,80 @@
         PolicyEditor.getFilePathArgument(optionParser);
     }
 
+    @Test
+    public void testGetCodebaseArgument() {
+        String[] args = new String[] { "-codebase", "http://example.com" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        String result = \
PolicyEditor.getCodebaseArgument(optionParser); +        \
assertTrue(result.equals("http://example.com")); +    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testGetCodebaseArgument2() {
+        String[] args = new String[] { "-codebase", "" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        \
PolicyEditor.getCodebaseArgument(optionParser); +    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testGetCodebaseArgument3() {
+        String[] args = new String[] { "-codebase", "example.com" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        \
PolicyEditor.getCodebaseArgument(optionParser); +    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testGetCodebaseArgumentWhenNotProvided() {
+        String[] args = new String[] { "-codebase" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        String result = \
PolicyEditor.getCodebaseArgument(optionParser); +    }
+
+    @Test
+    public void testGetPrincipalsArgument() {
+        String[] args = new String[] { "-principals", "aa=bb" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        \
Set<PolicyParser.PrincipalEntry> result = \
PolicyEditor.getPrincipalsArgument(optionParser); +        assertTrue(result.size() \
== 1); +        assertTrue(result.contains(new PolicyParser.PrincipalEntry("aa", \
"bb"))); +    }
+
+    @Test
+    public void testGetPrincipalsArgument2() {
+        String[] args = new String[] { "-principals", "aa", "bb" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        \
Set<PolicyParser.PrincipalEntry> result = \
PolicyEditor.getPrincipalsArgument(optionParser); +        assertTrue(result.size() \
== 1); +        assertTrue(result.contains(new PolicyParser.PrincipalEntry("aa", \
"bb"))); +    }
+
+    @Test(expected = UnevenParameterException.class)
+    public void testGetPrincipalsArgumentWhenUnevenArgumentsProvided() {
+        String[] args = new String[] { "-principals", "aa=bb", "cc" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        \
PolicyEditor.getPrincipalsArgument(optionParser); +    }
+
+    @Test
+    public void testGetPrincipalsArgumentWhenNotProvided() {
+        String[] args = new String[] { "-principals" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        \
Set<PolicyParser.PrincipalEntry> result = \
PolicyEditor.getPrincipalsArgument(optionParser); +        \
assertTrue(result.isEmpty()); +    }
+
+    @Test
+    public void testGetSignedByArgument() {
+        String[] args = new String[] { "-signedby", "foo" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        String result = \
PolicyEditor.getSignedByArgument(optionParser); +        \
assertTrue(result.equals("foo")); +    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testGetSignedByArgumentWhenNotProvided() {
+        String[] args = new String[] { "-signedby" };
+        OptionParser optionParser = new OptionParser(args, \
OptionsDefinitions.getPolicyEditorOptions()); +        \
PolicyEditor.getSignedByArgument(optionParser); +    }
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic