commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sgoes...@apache.org
Subject svn commit: r1723260 - in /commons/proper/exec/trunk/src/test: java/org/apache/commons/exec/issues/Exec65Test.java scripts/issues/ scripts/issues/exec-65.sh scripts/sleep.bat scripts/sleep.sh
Date Wed, 06 Jan 2016 10:07:02 GMT
Author: sgoeschl
Date: Wed Jan  6 10:07:02 2016
New Revision: 1723260

URL: http://svn.apache.org/viewvc?rev=1723260&view=rev
Log:
[EXEC-65] Watchdog can't destroy 'sudo' and 'sleep' - add unit test to ensure that the functionality
works

Added:
    commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java
    commons/proper/exec/trunk/src/test/scripts/issues/
    commons/proper/exec/trunk/src/test/scripts/issues/exec-65.sh   (with props)
    commons/proper/exec/trunk/src/test/scripts/sleep.bat   (with props)
    commons/proper/exec/trunk/src/test/scripts/sleep.sh   (with props)

Added: commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java?rev=1723260&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java
(added)
+++ commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/issues/Exec65Test.java
Wed Jan  6 10:07:02 2016
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.issues;
+
+import org.apache.commons.exec.*;
+import org.junit.Test;
+
+import java.io.File;
+
+/**
+ * Test to show that watchdog can destroy 'sudo' and 'sleep'.
+ *
+ * @see <a href="https://issues.apache.org/jira/browse/EXEC-65">EXEC-65</a>
+ */
+public class Exec65Test {
+
+    private static final int TIMEOUT = 3000;
+    private final File testDir = new File("src/test/scripts");
+
+    @Test(expected = ExecuteException.class, timeout = 2*TIMEOUT)
+    public void testExec65WitSleepUsingCommandLine() throws Exception
+    {
+        if(OS.isFamilyUnix())
+        {
+            final DefaultExecutor executor = new DefaultExecutor();
+            executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
+            final ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
+            executor.setWatchdog(watchdog);
+            final CommandLine command = new CommandLine("sleep");
+            command.addArgument("900");
+
+            executor.execute(command);
+        }
+    }
+
+    @Test(expected = ExecuteException.class, timeout = 2*TIMEOUT)
+    public void testExec65WithSleepUsingShellScript() throws Exception
+    {
+        final DefaultExecutor executor = new DefaultExecutor();
+        executor.setStreamHandler(new PumpStreamHandler(System.out, System.err));
+        final ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
+        executor.setWatchdog(watchdog);
+        final CommandLine command = new CommandLine(TestUtil.resolveScriptForOS(testDir +
"/sleep"));
+
+        executor.execute(command);
+    }
+
+    /**
+     * Please note that this tests make assumptions about the environment. It assumes
+     * that user "root" exists and that the current user is not a "sudoer" already.
+     */
+    @Test(expected = ExecuteException.class, timeout = 2*TIMEOUT)
+    public void testExec65WithSudoUsingShellScript() throws Exception
+    {
+        if(OS.isFamilyUnix())
+        {
+            final DefaultExecutor executor = new DefaultExecutor();
+            executor.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in));
+            final ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
+            executor.setWatchdog(watchdog);
+            final CommandLine command = new CommandLine(TestUtil.resolveScriptForOS(testDir
+ "/issues/exec-65"));
+
+            executor.execute(command);
+        }
+    }
+}

Added: commons/proper/exec/trunk/src/test/scripts/issues/exec-65.sh
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/issues/exec-65.sh?rev=1723260&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/issues/exec-65.sh (added)
+++ commons/proper/exec/trunk/src/test/scripts/issues/exec-65.sh Wed Jan  6 10:07:02 2016
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# force re-authentication
+sudo -K
+
+# run the "ls" command as "root" user but prompt for password
+sudo -S -u root ls

Propchange: commons/proper/exec/trunk/src/test/scripts/issues/exec-65.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/proper/exec/trunk/src/test/scripts/sleep.bat
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/sleep.bat?rev=1723260&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/sleep.bat (added)
+++ commons/proper/exec/trunk/src/test/scripts/sleep.bat Wed Jan  6 10:07:02 2016
@@ -0,0 +1,21 @@
+@ECHO OFF
+
+REM Little batch file to run nearly foerver
+REM see http://malektips.com/dos0017.html
+REM
+REM Licensed to the Apache Software Foundation (ASF) under one or more
+REM contributor license agreements.  See the NOTICE file distributed with
+REM this work for additional information regarding copyright ownership.
+REM The ASF licenses this file to You under the Apache License, Version 2.0
+REM (the "License"); you may not use this file except in compliance with
+REM the License.  You may obtain a copy of the License at
+REM
+REM      http://www.apache.org/licenses/LICENSE-2.0
+REM
+REM Unless required by applicable law or agreed to in writing, software
+REM distributed under the License is distributed on an "AS IS" BASIS,
+REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+REM See the License for the specific language governing permissions and
+REM limitations under the License.
+
+@ping 127.0.0.1 -n 2 -w 60000 > nul
\ No newline at end of file

Propchange: commons/proper/exec/trunk/src/test/scripts/sleep.bat
------------------------------------------------------------------------------
    svn:executable = *

Added: commons/proper/exec/trunk/src/test/scripts/sleep.sh
URL: http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/scripts/sleep.sh?rev=1723260&view=auto
==============================================================================
--- commons/proper/exec/trunk/src/test/scripts/sleep.sh (added)
+++ commons/proper/exec/trunk/src/test/scripts/sleep.sh Wed Jan  6 10:07:02 2016
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+sleep 60
\ No newline at end of file

Propchange: commons/proper/exec/trunk/src/test/scripts/sleep.sh
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message