@Test public void testPostScriptDisableAbsolutePath() { // check if sh is there Assume.assumeTrue(new File("/bin/sh").exists()); try { new PostScriptTransform("/bin/sh", Collections.emptyList()); fail("Should have failed disallowing usage of absoute path"); } catch (Exception e) { assertThat( e.getMessage(), allOf(containsString("/bin/sh"), containsString("not " + "found"))); } }
@Test public void testPostScriptDisableTraversal() throws Exception { // prepare the scripts folder, but leave it empty File scripts = getDataDirectory().findOrCreateDir("importer", "scripts"); FileUtils.deleteQuietly(scripts); assertTrue(scripts.mkdirs()); try { new PostScriptTransform("../wfs.xml", Collections.emptyList()); fail("Should have thrown an exception"); } catch (Exception e) { assertThat(e.getMessage(), containsString("invalid ..")); } }
@Test public void testRunNonExistingScript() throws Exception { // prepare the scripts folder, but leave it empty File scripts = getDataDirectory().findOrCreateDir("importer", "scripts"); FileUtils.deleteQuietly(scripts); assertTrue(scripts.mkdirs()); try { new PostScriptTransform("i_am_not_there.sh", Collections.emptyList()); fail("Should have thrown an exception"); } catch (Exception e) { assertThat(e.getMessage(), containsString("i_am_not_there.sh")); } }
assertEquals("archsites", task.getLayer().getResource().getName()); TransformChain transformChain = task.getTransform(); transformChain.add(new PostScriptTransform("test.sh", Collections.emptyList())); importer.run(context);