From 23bd0c41457262e7ef5223a187e3c15e44be039c Mon Sep 17 00:00:00 2001 From: netblue30 Date: Mon, 25 Jul 2016 12:29:00 -0400 Subject: argument subsystem testing framework --- test/arguments/arguments.sh | 17 +++++++++ test/arguments/bashrun.exp | 86 ++++++++++++++++++++++++++++++++++++++++++ test/arguments/bashrun.sh | 22 +++++++++++ test/arguments/joinrun.exp | 91 +++++++++++++++++++++++++++++++++++++++++++++ test/arguments/joinrun.sh | 22 +++++++++++ test/arguments/main.c | 31 +++++++++++++++ test/arguments/outrun.exp | 90 ++++++++++++++++++++++++++++++++++++++++++++ test/arguments/outrun.sh | 22 +++++++++++ test/arguments/readme | 9 +++++ test/arguments/symrun.exp | 71 +++++++++++++++++++++++++++++++++++ test/arguments/symrun.sh | 27 ++++++++++++++ 11 files changed, 488 insertions(+) create mode 100755 test/arguments/arguments.sh create mode 100755 test/arguments/bashrun.exp create mode 100755 test/arguments/bashrun.sh create mode 100755 test/arguments/joinrun.exp create mode 100755 test/arguments/joinrun.sh create mode 100644 test/arguments/main.c create mode 100755 test/arguments/outrun.exp create mode 100755 test/arguments/outrun.sh create mode 100644 test/arguments/readme create mode 100755 test/arguments/symrun.exp create mode 100755 test/arguments/symrun.sh (limited to 'test/arguments') diff --git a/test/arguments/arguments.sh b/test/arguments/arguments.sh new file mode 100755 index 000000000..a9b3f9587 --- /dev/null +++ b/test/arguments/arguments.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +echo "TESTING: 1. regular bash session" +./bashrun.exp + +echo "TESTING: 2. symbolic link to firejail" +./symrun.exp + +echo "TESTING: 3. --join option" +./joinrun.exp + +echo "TESTING: 4. --output option" +./outrun.exp +rm out +rm out.* + + diff --git a/test/arguments/bashrun.exp b/test/arguments/bashrun.exp new file mode 100755 index 000000000..a3c9e382d --- /dev/null +++ b/test/arguments/bashrun.exp @@ -0,0 +1,86 @@ +#!/usr/bin/expect -f + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + +send -- "./bashrun.sh\r" +expect { + timeout {puts "TESTING ERROR 1.1.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 1.1.2\n";exit} + "#arg1#" +} +expect { + timeout {puts "TESTING ERROR 1.1.3\n";exit} + "#arg2#" +} + +expect { + timeout {puts "TESTING ERROR 1.2.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 1.2.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 1.2.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 1.3.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 1.3.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 1.3.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 1.4.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 1.4.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 1.4.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 1.5.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 1.5.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 1.5.3\n";exit} + "#arg2&tail#" +} + +expect { + timeout {puts "TESTING ERROR 1.6.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 1.6.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 1.6.3\n";exit} + "#arg2&tail#" +} + +puts "\nall done\n" diff --git a/test/arguments/bashrun.sh b/test/arguments/bashrun.sh new file mode 100755 index 000000000..c2f209548 --- /dev/null +++ b/test/arguments/bashrun.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +echo "TESTING: 1.1 - simple args" +firejail --quiet ./argtest arg1 arg2 + +# simple quotes, testing spaces in file names +echo "TESTING: 1.2 - args with space and \"" +firejail --quiet ./argtest "arg1 tail" "arg2 tail" + +echo "TESTING: 1.3 - args with space and '" +firejail --quiet ./argtest 'arg1 tail' 'arg2 tail' + +# escaped space in file names +echo "TESTING: 1.4 - args with space and \\" +firejail --quiet ./argtest arg1\ tail arg2\ tail + +# & char appears in URLs - URLs should be quoted +echo "TESTING: 1.5 - args with & and \"" +firejail --quiet ./argtest "arg1&tail" "arg2&tail" + +echo "TESTING: 1.6 - args with & and '" +firejail --quiet ./argtest 'arg1&tail' 'arg2&tail' diff --git a/test/arguments/joinrun.exp b/test/arguments/joinrun.exp new file mode 100755 index 000000000..8e8570e4f --- /dev/null +++ b/test/arguments/joinrun.exp @@ -0,0 +1,91 @@ +#!/usr/bin/expect -f + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + + +send -- "firejail --name=joinrun\r" +sleep 2 + +spawn $env(SHELL) +send -- "./joinrun.sh\r" +expect { + timeout {puts "TESTING ERROR 3.1.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 3.1.2\n";exit} + "#arg1#" +} +expect { + timeout {puts "TESTING ERROR 3.1.3\n";exit} + "#arg2#" +} + +expect { + timeout {puts "TESTING ERROR 3.2.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 3.2.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 3.2.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 3.3.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 3.3.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 3.3.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 3.4.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 3.4.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 3.4.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 3.5.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 3.5.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 3.5.3\n";exit} + "#arg2&tail#" +} + +expect { + timeout {puts "TESTING ERROR 3.6.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 3.6.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 3.6.3\n";exit} + "#arg2&tail#" +} + +puts "\nall done\n" diff --git a/test/arguments/joinrun.sh b/test/arguments/joinrun.sh new file mode 100755 index 000000000..f6c2b2e22 --- /dev/null +++ b/test/arguments/joinrun.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +echo "TESTING: 3.1 - simple args" +firejail --join=joinrun ./argtest arg1 arg2 + +# simple quotes, testing spaces in file names +echo "TESTING: 3.2 - args with space and \"" +firejail --quiet ./argtest "arg1 tail" "arg2 tail" + +echo "TESTING: 3.3 - args with space and '" +firejail --quiet ./argtest 'arg1 tail' 'arg2 tail' + +# escaped space in file names +echo "TESTING: 3.4 - args with space and \\" +firejail --quiet ./argtest arg1\ tail arg2\ tail + +# & char appears in URLs - URLs should be quoted +echo "TESTING: 3.5 - args with & and \"" +firejail --quiet ./argtest "arg1&tail" "arg2&tail" + +echo "TESTING: 3.6 - args with & and '" +firejail --quiet ./argtest 'arg1&tail' 'arg2&tail' diff --git a/test/arguments/main.c b/test/arguments/main.c new file mode 100644 index 000000000..75bdca715 --- /dev/null +++ b/test/arguments/main.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014-2016 Firejail Authors + * + * This file is part of firejail project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include + +int main(int argc, char **argv) { + printf("Arguments:\n"); + + int i; + for (i = 0; i < argc; i++) { + printf("#%s#\n", argv[i]); + } + + return 0; +} diff --git a/test/arguments/outrun.exp b/test/arguments/outrun.exp new file mode 100755 index 000000000..d28e75661 --- /dev/null +++ b/test/arguments/outrun.exp @@ -0,0 +1,90 @@ +#!/usr/bin/expect -f + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + +send -- "./outrun.sh\r" +expect { + timeout {puts "TESTING ERROR 4.1.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 4.1.2\n";exit} + "#arg1#" +} +expect { + timeout {puts "TESTING ERROR 4.1.3\n";exit} + "#arg2#" +} + +exit +#*************************************************** +# breaking down from here on - bug to fix +#*************************************************** +expect { + timeout {puts "TESTING ERROR 4.2.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 4.2.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 4.2.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 4.3.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 4.3.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 4.3.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 4.4.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 4.4.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 4.4.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 4.5.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 4.5.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 4.5.3\n";exit} + "#arg2&tail#" +} + +expect { + timeout {puts "TESTING ERROR 4.6.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 4.6.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 4.6.3\n";exit} + "#arg2&tail#" +} + +puts "\nall done\n" diff --git a/test/arguments/outrun.sh b/test/arguments/outrun.sh new file mode 100755 index 000000000..cfd8e684c --- /dev/null +++ b/test/arguments/outrun.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +echo "TESTING: 4.1 - simple args" +firejail --output=out ./argtest arg1 arg2 + +# simple quotes, testing spaces in file names +echo "TESTING: 4.2 - args with space and \"" +firejail --output=out ./argtest "arg1 tail" "arg2 tail" + +echo "TESTING: 4.3 - args with space and '" +firejail --output=out ./argtest 'arg1 tail' 'arg2 tail' + +# escaped space in file names +echo "TESTING: 4.4 - args with space and \\" +firejail --output=out ./argtest arg1\ tail arg2\ tail + +# & char appears in URLs - URLs should be quoted +echo "TESTING: 4.5 - args with & and \"" +firejail --output=out ./argtest "arg1&tail" "arg2&tail" + +echo "TESTING: 4.6 - args with & and '" +firejail --output=out ./argtest 'arg1&tail' 'arg2&tail' diff --git a/test/arguments/readme b/test/arguments/readme new file mode 100644 index 000000000..f5844848e --- /dev/null +++ b/test/arguments/readme @@ -0,0 +1,9 @@ +Argument testing fremework for Firejail. + +A small test program, argtest, is compiled and installed in /usr/local/bin directory. +Run "make && sudo make install" to install it. + +Run "make test" to run the tests. + +Run "make uninstall" to remove the test program. + diff --git a/test/arguments/symrun.exp b/test/arguments/symrun.exp new file mode 100755 index 000000000..1466b791e --- /dev/null +++ b/test/arguments/symrun.exp @@ -0,0 +1,71 @@ +#!/usr/bin/expect -f + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + +send -- "./bashrun.sh\r" +expect { + timeout {puts "TESTING ERROR 2.1.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 2.1.2\n";exit} + "#arg1#" +} +expect { + timeout {puts "TESTING ERROR 2.1.3\n";exit} + "#arg2#" +} + +expect { + timeout {puts "TESTING ERROR 2.3.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 2.3.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 2.3.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 2.4.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 2.4.2\n";exit} + "#arg1 tail#" +} +expect { + timeout {puts "TESTING ERROR 2.4.3\n";exit} + "#arg2 tail#" +} + +expect { + timeout {puts "TESTING ERROR 2.5.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 2.5.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 2.5.3\n";exit} + "#arg2&tail#" +} + +expect { + timeout {puts "TESTING ERROR 2.6.1\n";exit} + "Arguments:" +} +expect { + timeout {puts "TESTING ERROR 2.6.2\n";exit} + "#arg1&tail#" +} +expect { + timeout {puts "TESTING ERROR 2.6.3\n";exit} + "#arg2&tail#" +} diff --git a/test/arguments/symrun.sh b/test/arguments/symrun.sh new file mode 100755 index 000000000..b46803ae2 --- /dev/null +++ b/test/arguments/symrun.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +mkdir symtest +ln -s /usr/bin/firejail symtest/argtest + +echo "TESTING: 2.1 - simple args" +symtest/argtest arg1 arg2 + +# simple quotes, testing spaces in file names +echo "TESTING: 2.2 - args with space and \"" +symtest/argtest "arg1 tail" "arg2 tail" + +echo "TESTING: 2.3 - args with space and '" +symtest/argtest 'arg1 tail' 'arg2 tail' + +# escaped space in file names +echo "TESTING: 2.4 - args with space and \\" +symtest/argtest arg1\ tail arg2\ tail + +# & char appears in URLs - URLs should be quoted +echo "TESTING: 2.5 - args with & and \"" +symtest/argtest "arg1&tail" "arg2&tail" + +echo "TESTING: 2.6 - args with & and '" +symtest/argtest 'arg1&tail' 'arg2&tail' + +rm -fr symtest -- cgit v1.2.3-54-g00ecf