From 91e6864c715cf57e93e0337fbdec288b46cf897a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20N=C3=BCst?= Date: Thu, 17 Apr 2014 16:45:47 +0200 Subject: [PATCH] add integration test for injection, fix wps-off test --- .../src/main/webapp/R/scripts/test_echo.R | 7 +++++ .../src/main/webapp/R/scripts/test_wps-off.R | 2 +- .../test/java/org/n52/wps/test/Wps4rIT.java | 29 +++++++++++++++++-- .../test/resources/R/ExecuteTestInjection.xml | 23 +++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 52n-wps-webapp/src/main/webapp/R/scripts/test_echo.R create mode 100644 52n-wps-webapp/src/test/resources/R/ExecuteTestInjection.xml diff --git a/52n-wps-webapp/src/main/webapp/R/scripts/test_echo.R b/52n-wps-webapp/src/main/webapp/R/scripts/test_echo.R new file mode 100644 index 000000000..3bb668fc0 --- /dev/null +++ b/52n-wps-webapp/src/main/webapp/R/scripts/test_echo.R @@ -0,0 +1,7 @@ +# wps.des: test.echo, title = dummy echo process, abstract = you get what you put in; + +# wps.in: id = inputVariable, type = string, title = input variable, minOccurs = 1, maxOccurs = 1; + +outputVariable <- inputVariable + +#wps.out: id = outputVariable, type = string, title = returning input variable; \ No newline at end of file diff --git a/52n-wps-webapp/src/main/webapp/R/scripts/test_wps-off.R b/52n-wps-webapp/src/main/webapp/R/scripts/test_wps-off.R index 4a9112018..7bdf8215f 100644 --- a/52n-wps-webapp/src/main/webapp/R/scripts/test_wps-off.R +++ b/52n-wps-webapp/src/main/webapp/R/scripts/test_wps-off.R @@ -13,7 +13,7 @@ c = 3 out <- a + b + c #wps.off; -out <- 42 +out <- 17 #wps.on; #wps.out: id = out, type = integer, title = sum of inputs; \ No newline at end of file diff --git a/52n-wps-webapp/src/test/java/org/n52/wps/test/Wps4rIT.java b/52n-wps-webapp/src/test/java/org/n52/wps/test/Wps4rIT.java index 3c40f02b0..ccc9d7c3e 100644 --- a/52n-wps-webapp/src/test/java/org/n52/wps/test/Wps4rIT.java +++ b/52n-wps-webapp/src/test/java/org/n52/wps/test/Wps4rIT.java @@ -256,7 +256,8 @@ else if (opString.equals("*")) String response = PostClient.sendRequest(wpsUrl, payload); assertThat(AllTestsIT.parseXML(response), is(not(nullValue()))); - assertThat(response, containsString(Integer.toString(result))); + String expected = "dataType=\"xs:double\">" + Integer.toString(result) + ".0"; + assertThat(response, containsString(expected)); } @Test @@ -271,7 +272,7 @@ public void wpsOffAnnotationWorks() throws XmlException, IOException { response, containsString(expected)); } - + @Test public void defaultValuesAreLoaded() throws XmlException, IOException { URL resource = Wps4rIT.class.getResource("/R/ExecuteTestDefaults.xml"); @@ -285,4 +286,28 @@ public void defaultValuesAreLoaded() throws XmlException, IOException { containsString(expected)); } + @Test + public void exceptionsOnIllegalInputs() throws XmlException, IOException { + String[] illegalCommands = new String[] {"unlink(getwd())", + "\"\";quit(\"no\");", + "q();", + "quit()", + "system('format hardisk')"}; + + URL resource = Wps4rIT.class.getResource("/R/ExecuteTestInjection.xml"); + XmlObject xmlPayload = XmlObject.Factory.parse(resource); + + for (String cmd : illegalCommands) { + String payload = xmlPayload.toString(); + payload = payload.replace("@@@cmd@@@", cmd); + + String response = PostClient.sendRequest(wpsUrl, payload); + + String expected = "Illegal command"; + assertThat("Response is an exception", response, containsString("ExceptionReport")); + assertThat("Response containts the keyphrase '" + expected + "'", response, containsString(expected)); + assertThat("Response contains the illegal input", response, containsString(cmd)); + } + } + } diff --git a/52n-wps-webapp/src/test/resources/R/ExecuteTestInjection.xml b/52n-wps-webapp/src/test/resources/R/ExecuteTestInjection.xml new file mode 100644 index 000000000..2e7c3cb58 --- /dev/null +++ b/52n-wps-webapp/src/test/resources/R/ExecuteTestInjection.xml @@ -0,0 +1,23 @@ + + + org.n52.wps.server.r.test.echo + + + inputVariable + + @@@cmd@@@ + + + + + + + outputVariable + + + +