/hg/icedtea-web: Added experimental usage of headless dialogues ...

jvanek at icedtea.classpath.org jvanek at icedtea.classpath.org
Fri Jun 19 12:22:16 UTC 2015


changeset a5561b460631 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=a5561b460631
author: Jiri Vanek <jvanek at redhat.com>
date: Fri Jun 19 14:21:55 2015 +0200

	Added experimental usage of headless dialogues to reproducers suite

	* tests/reproducers/signed/RunInSandbox/testcases/RunInSandboxTest.java: added four tests popuping and answering headless dialogue
	* tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java: use diamonds, added methods setWriter alllowing to set StdInWriter of ThreadedProcess
	* tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java: added setWriter method, which allows to set writer to to underlying process stdin. (run) if writer is not null, thenstdin writer  thread is started and it writes writer to underlying process.


diffstat:

 ChangeLog                                                             |  13 ++
 tests/reproducers/signed/RunInSandbox/testcases/RunInSandboxTest.java |  65 ++++++++++
 tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java        |  25 ++-
 tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java       |  35 +++++
 4 files changed, 132 insertions(+), 6 deletions(-)

diffs (267 lines):

diff -r ac236a9d0b92 -r a5561b460631 ChangeLog
--- a/ChangeLog	Fri Jun 19 12:22:43 2015 +0200
+++ b/ChangeLog	Fri Jun 19 14:21:55 2015 +0200
@@ -1,3 +1,16 @@
+2015-06-19  Jiri Vanek  <jvanek at redhat.com>
+
+	Added experimental usage of headless dialogues to reproducers suite
+	* tests/reproducers/signed/RunInSandbox/testcases/RunInSandboxTest.java:
+	added four tests popuping and answering headless dialogue
+	* tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java:
+	use diamonds, added methods setWriter alllowing to set StdInWriter of
+	ThreadedProcess
+	* tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java:
+	added setWriter method, which allows to set writer to to underlying process
+	stdin. (run) if writer is not null, thenstdin writer  thread is started and
+	it writes writer to underlying process.
+
 2015-06-19  Jiri Vanek  <jvanek at redhat.com>
 
 	Partially signed reproducer adapted to new schema and enhanced
diff -r ac236a9d0b92 -r a5561b460631 tests/reproducers/signed/RunInSandbox/testcases/RunInSandboxTest.java
--- a/tests/reproducers/signed/RunInSandbox/testcases/RunInSandboxTest.java	Fri Jun 19 12:22:43 2015 +0200
+++ b/tests/reproducers/signed/RunInSandbox/testcases/RunInSandboxTest.java	Fri Jun 19 14:21:55 2015 +0200
@@ -51,6 +51,7 @@
 import java.util.Collections;
 import java.util.Arrays;
 import net.sourceforge.jnlp.OptionsDefinitions;
+import net.sourceforge.jnlp.ProcessWrapper;
 import net.sourceforge.jnlp.ServerAccess;
 import net.sourceforge.jnlp.annotations.TestInBrowsers;
 import net.sourceforge.jnlp.browsertesting.Browsers;
@@ -68,6 +69,7 @@
     private final List<String> TRUSTNONE = Collections.unmodifiableList(Arrays.asList(new String[]{OptionsDefinitions.OPTIONS.TRUSTNONE.option}));
     private final List<String> TRUSTALLHTML = Collections.unmodifiableList(Arrays.asList(new String[]{OptionsDefinitions.OPTIONS.TRUSTALL.option, OptionsDefinitions.OPTIONS.HTML.option}));
     private final List<String> TRUSTNONEHTML = Collections.unmodifiableList(Arrays.asList(new String[]{OptionsDefinitions.OPTIONS.TRUSTNONE.option, OptionsDefinitions.OPTIONS.HTML.option}));
+    private final List<String> HEADLESS = Collections.unmodifiableList(Arrays.asList(new String[]{OptionsDefinitions.OPTIONS.HEADLESS.option}));
     private static final String appletCloseString = AutoOkClosingListener.MAGICAL_OK_CLOSING_STRING;
 
     private static final String ItwAlias = "icedteaweb_signed";
@@ -227,10 +229,63 @@
     
     
     //end of must HAVE cert
+    
+    //and those must NOT have cert, and are trying to answer dialogues
+    
+    @Test
+    public void testStandardJnlpApplicationLaunchWithAnswerYes() throws Exception {
+        deleteCertificate();
+        ProcessWrapper pw =  new ProcessWrapper(server.getJavawsLocation(), HEADLESS, server.getUrl("RunInSandboxApplication.jnlp"));
+        pw.setWriter("YES\n");
+        ProcessResult pr = pw.execute();
+        assertReadProperty(pr);
+        assertProperClose(pr);
+    }
+    
+    @Test
+    public void testStandardJnlpApplicationLaunchWithAnswerSandbox() throws Exception {
+        deleteCertificate();
+        ProcessWrapper pw =  new ProcessWrapper(server.getJavawsLocation(), HEADLESS, server.getUrl("RunInSandboxApplication.jnlp"));
+        pw.setWriter("SANDBOX\n");
+        ProcessResult pr = pw.execute();
+        assertNotReadProperty(pr);
+        assertAccessControlException(pr);
+        assertProperClose(pr);
+    }
+    
+    @Test
+    public void testStandardJnlpApplicationLaunchWithAnswerNo() throws Exception {
+        deleteCertificate();
+        ProcessWrapper pw =  new ProcessWrapper(server.getJavawsLocation(), HEADLESS, server.getUrl("RunInSandboxApplication.jnlp"));
+        pw.setWriter("NO\n");
+        ProcessResult pr = pw.execute();
+        assertNotReadProperty(pr);
+        assertNotAccessControlException(pr);
+        assertNotProperClose(pr);
+        assertLaunchException(pr);
+    }
+    
+      @Test
+    public void testStandardJnlpApplicationLaunchWithAnswerEOF() throws Exception {
+        deleteCertificate();
+        ProcessWrapper pw =  new ProcessWrapper(server.getJavawsLocation(), HEADLESS, server.getUrl("RunInSandboxApplication.jnlp"));
+        pw.setWriter("");
+        ProcessResult pr = pw.execute();
+        assertNotReadProperty(pr);
+        assertNotAccessControlException(pr);
+        assertNotProperClose(pr);
+        assertLaunchException(pr);
+    }
+    
+    //end of tests
 
     private void assertProperClose(ProcessResult pr) {
         assertTrue("applet should have closed correctly", pr.stdout.contains(appletCloseString));
     }
+    
+    private void assertNotProperClose(ProcessResult pr) {
+        assertFalse("applet must not have closed correctly", pr.stdout.contains(appletCloseString));
+    }
 
     private void assertReadProperty(ProcessResult pr) {
         assertTrue("applet should have been able to read user.home", pr.stdout.contains(System.getProperty("user.home")));
@@ -244,5 +299,15 @@
         String ace = "java.security.AccessControlException: access denied (\"java.util.PropertyPermission\" \"user.home\" \"read\")";
         assertTrue("applet should have throw AccessControlException", pr.stdout.contains(ace));
     }
+    
+    private void assertNotAccessControlException(ProcessResult pr) {
+        String ace = "java.security.AccessControlException: access denied (\"java.util.PropertyPermission\" \"user.home\" \"read\")";
+        assertFalse("applet must not throw AccessControlException", pr.stdout.contains(ace));
+    }
+     
+    private void assertLaunchException(ProcessResult pr) {
+        String ace = "LaunchException";
+        assertTrue("applet should have throw LaunchException", pr.stderr.contains(ace));
+    }
 
 }
diff -r ac236a9d0b92 -r a5561b460631 tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java
--- a/tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java	Fri Jun 19 12:22:43 2015 +0200
+++ b/tests/test-extensions/net/sourceforge/jnlp/ProcessWrapper.java	Fri Jun 19 14:21:55 2015 +0200
@@ -37,9 +37,12 @@
 
 package net.sourceforge.jnlp;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 import net.sourceforge.jnlp.browsertesting.ReactingProcess;
@@ -56,10 +59,11 @@
 
     private List<String> args;
     private File dir;
-    private final List<ContentReaderListener> stdoutl = new ArrayList<ContentReaderListener>(1);
-    private final List<ContentReaderListener> stderrl = new ArrayList<ContentReaderListener>(1);
+    private final List<ContentReaderListener> stdoutl = new ArrayList<>(1);
+    private final List<ContentReaderListener> stderrl = new ArrayList<>(1);
     private String[] vars;
     private ReactingProcess reactingProcess;
+    private InputStream writer;
 
     public ProcessWrapper() {
     }
@@ -73,9 +77,9 @@
         Assert.assertNotNull(toBeExecuted);
         Assert.assertTrue(toBeExecuted.trim().length() > 1);
         if (otherargs == null) {
-            otherargs = new ArrayList<String>(1);
+            otherargs = new ArrayList<>(1);
         }
-        List<String> urledArgs = new ArrayList<String>(otherargs);
+        List<String> urledArgs = new ArrayList<>(otherargs);
         urledArgs.add(0, toBeExecuted);
         urledArgs.add(s);
         this.args = urledArgs;
@@ -204,7 +208,7 @@
     public ProcessResult execute() throws Exception {
         if (reactingProcess !=null ){
             reactingProcess.beforeProcess("");
-        };
+        }
         ThreadedProcess t = new ThreadedProcess(args, dir, vars);
         if (ServerAccess.PROCESS_LOG) {
             String connectionMesaage = createConnectionMessage(t);
@@ -215,6 +219,7 @@
         pa.setReactingProcess(reactingProcess);
         setUpClosingListener(stdoutl, pa, t);
         setUpClosingListener(stderrl, pa, t);
+        t.setWriter(writer);
         pa.start();
         t.start();
         while (t.getP() == null && t.deadlyException == null) {
@@ -251,7 +256,7 @@
         }
         if (reactingProcess != null) {
             reactingProcess.afterProcess("");
-        };
+        }
         return pr;
     }
 
@@ -272,4 +277,12 @@
      void setReactingProcess(ReactingProcess reactingProcess) {
         this.reactingProcess = reactingProcess;
     }
+
+    public void setWriter(InputStream writer) {
+        this.writer = writer;
+    }
+     
+     public void setWriter(String writer) {
+        setWriter(new ByteArrayInputStream(writer.getBytes(StandardCharsets.UTF_8)));
+    }
 }
diff -r ac236a9d0b92 -r a5561b460631 tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java
--- a/tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java	Fri Jun 19 12:22:43 2015 +0200
+++ b/tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java	Fri Jun 19 14:21:55 2015 +0200
@@ -37,7 +37,12 @@
 
 package net.sourceforge.jnlp;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
 import java.util.List;
 import net.sourceforge.jnlp.util.StreamUtils;
 
@@ -61,6 +66,7 @@
      */
     private boolean destoyed = false;
     private ProcessAssasin assasin;
+    private InputStream writer;
 
     public boolean isDestoyed() {
         return destoyed;
@@ -86,6 +92,11 @@
         return variables;
     }
 
+    public void setWriter(InputStream writer) {
+        this.writer = writer;
+    }
+
+    
 
 
     public ThreadedProcess(List<String> args) {
@@ -142,6 +153,30 @@
                 p = r.exec(args.toArray(new String[0]), variables, dir);
             }
             try {
+                if (writer != null){
+                    Thread t = new Thread(new Runnable() {
+
+                        @Override
+                        public void run() {
+                            try (
+                                    BufferedReader br = new BufferedReader(new InputStreamReader(writer, "utf-8"));
+                                    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(p.getOutputStream(), "utf-8"))) {
+                                while (true) {
+                                    String s = br.readLine();
+                                    if (s == null) {
+                                        break;
+                                    }
+                                    bw.write(s + System.lineSeparator());
+                                    bw.flush();
+
+                                }
+                            } catch (Exception ex) {
+                                ServerAccess.logException(ex);
+                            }
+                        }
+                    });
+                    t.start();
+                }
                 StreamUtils.waitForSafely(p);
                 exitCode = p.exitValue();
                 Thread.sleep(500); //this is giving to fast done proecesses's e/o readers time to read all. I would like to know better solution :-/


More information about the distro-pkg-dev mailing list