aboutsummaryrefslogtreecommitdiffstats
path: root/test/fnetfilter
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2017-11-18 08:39:02 -0500
committerLibravatar netblue30 <netblue30@yahoo.com>2017-11-18 08:39:02 -0500
commitead4ec3089b97eda1b438da248caf76f169345ad (patch)
tree31bc22bcba4e6530b5f0daba3f332702efa7a4b9 /test/fnetfilter
parentConsistent home directory nomenclature (diff)
downloadfirejail-ead4ec3089b97eda1b438da248caf76f169345ad.tar.gz
firejail-ead4ec3089b97eda1b438da248caf76f169345ad.tar.zst
firejail-ead4ec3089b97eda1b438da248caf76f169345ad.zip
netfilter template support
Diffstat (limited to 'test/fnetfilter')
-rwxr-xr-xtest/fnetfilter/cmdline.exp37
-rwxr-xr-xtest/fnetfilter/copy.exp52
-rwxr-xr-xtest/fnetfilter/default.exp40
-rwxr-xr-xtest/fnetfilter/fnetfilter.sh28
-rw-r--r--test/fnetfilter/outlocked0
-rwxr-xr-xtest/fnetfilter/template.exp82
-rw-r--r--test/fnetfilter/test1.net19
-rw-r--r--test/fnetfilter/test2.net19
-rw-r--r--test/fnetfilter/test3.net1
9 files changed, 278 insertions, 0 deletions
diff --git a/test/fnetfilter/cmdline.exp b/test/fnetfilter/cmdline.exp
new file mode 100755
index 000000000..1a0b1c5aa
--- /dev/null
+++ b/test/fnetfilter/cmdline.exp
@@ -0,0 +1,37 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2017 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "fnetfilter\r"
11expect {
12 timeout {puts "TESTING ERROR 1\n";exit}
13 "Usage:"
14}
15after 100
16
17send -- "fnetfilter -h\r"
18expect {
19 timeout {puts "TESTING ERROR 2\n";exit}
20 "Usage:"
21}
22after 100
23
24send -- "fnetfilter -h a b c d\r"
25expect {
26 timeout {puts "TESTING ERROR 2\n";exit}
27 "Usage:"
28}
29after 100
30
31send -- "fnetfilter a b c d\r"
32expect {
33 timeout {puts "TESTING ERROR 2\n";exit}
34 "Usage:"
35}
36after 100
37puts "\nall done\n"
diff --git a/test/fnetfilter/copy.exp b/test/fnetfilter/copy.exp
new file mode 100755
index 000000000..65145ec4b
--- /dev/null
+++ b/test/fnetfilter/copy.exp
@@ -0,0 +1,52 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2017 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "rm outfile\r"
11after 100
12
13send -- "fnetfilter test1.net outfile\r"
14after 100
15
16send -- "cat outfile\r"
17expect {
18 timeout {puts "TESTING ERROR 1\n";exit}
19 "test1"
20}
21expect {
22 timeout {puts "TESTING ERROR 2\n";exit}
23 "*filter"
24}
25expect {
26 timeout {puts "TESTING ERROR 3\n";exit}
27 "INPUT -m state --state RELATED,ESTABLISHED"
28}
29expect {
30 timeout {puts "TESTING ERROR 4\n";exit}
31 "disable STUN"
32}
33after 100
34
35send -- "fnetfilter foo outfile\r"
36expect {
37 timeout {puts "TESTING ERROR 5\n";exit}
38 "cannot open foo"
39}
40after 100
41
42send -- "fnetfilter test1.net outlocked\r"
43expect {
44 timeout {puts "TESTING ERROR 6\n";exit}
45 "cannot open outlocked"
46}
47after 100
48
49send -- "rm outfile\r"
50after 100
51
52puts "\nall done\n"
diff --git a/test/fnetfilter/default.exp b/test/fnetfilter/default.exp
new file mode 100755
index 000000000..d7c9d91d5
--- /dev/null
+++ b/test/fnetfilter/default.exp
@@ -0,0 +1,40 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2017 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "rm outfile\r"
11after 100
12
13send -- "fnetfilter outfile\r"
14after 100
15
16send -- "cat outfile\r"
17expect {
18 timeout {puts "TESTING ERROR 1\n";exit}
19 "*filter"
20}
21expect {
22 timeout {puts "TESTING ERROR 2\n";exit}
23 "INPUT -m state --state RELATED,ESTABLISHED"
24}
25expect {
26 timeout {puts "TESTING ERROR 3\n";exit}
27 "disable STUN"
28}
29after 100
30
31send -- "fnetfilter test1.net,33\r"
32expect {
33 timeout {puts "TESTING ERROR 4\n";exit}
34 "invalid destination file in netfilter command"
35}
36after 100
37send -- "rm outfile\r"
38after 100
39
40puts "\nall done\n"
diff --git a/test/fnetfilter/fnetfilter.sh b/test/fnetfilter/fnetfilter.sh
new file mode 100755
index 000000000..5fd08d186
--- /dev/null
+++ b/test/fnetfilter/fnetfilter.sh
@@ -0,0 +1,28 @@
1#!/bin/bash
2# This file is part of Firejail project
3# Copyright (C) 2014-2017 Firejail Authors
4# License GPL v2
5
6export MALLOC_CHECK_=3
7export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
8
9if [ -f /etc/debian_version ]; then
10 libdir=$(dirname "$(dpkg -L firejail | grep fcopy)")
11 export PATH="$PATH:$libdir"
12fi
13
14export PATH="$PATH:/usr/lib/firejail"
15
16echo "TESTING: fnetfilter cmdline (test/fnetfilter/cmdline.exp)"
17./cmdline.exp
18
19echo "TESTING: fnetfilter default (test/fnetfilter/default.exp)"
20./default.exp
21
22echo "TESTING: fnetfilter copy (test/fnetfilter/copy.exp)"
23./copy.exp
24
25echo "TESTING: fnetfilter template (test/fnetfilter/template.exp)"
26./template.exp
27
28rm -f outfile
diff --git a/test/fnetfilter/outlocked b/test/fnetfilter/outlocked
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/fnetfilter/outlocked
diff --git a/test/fnetfilter/template.exp b/test/fnetfilter/template.exp
new file mode 100755
index 000000000..eb57313bd
--- /dev/null
+++ b/test/fnetfilter/template.exp
@@ -0,0 +1,82 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2017 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "rm outfile\r"
11after 100
12
13send -- "fnetfilter test2.net,icmp-type,destination-unreachable,time-exceeded,echo-request,3478,3479 outfile\r"
14after 100
15
16send -- "cat outfile\r"
17expect {
18 timeout {puts "TESTING ERROR 1\n";exit}
19 "*filter"
20}
21expect {
22 timeout {puts "TESTING ERROR 2\n";exit}
23 "INPUT -m state --state RELATED,ESTABLISHED"
24}
25expect {
26 timeout {puts "TESTING ERROR 3\n";exit}
27 "icmp-type echo-reply"
28}
29expect {
30 timeout {puts "TESTING ERROR 4\n";exit}
31 "icmp-type destination-unreachable"
32}
33expect {
34 timeout {puts "TESTING ERROR 5\n";exit}
35 "icmp-type time-exceeded"
36}
37expect {
38 timeout {puts "TESTING ERROR 6\n";exit}
39 "icmp-type echo-request"
40}
41expect {
42 timeout {puts "TESTING ERROR 7\n";exit}
43 "dport 3478"
44}
45expect {
46 timeout {puts "TESTING ERROR 8\n";exit}
47 "dport 3479"
48}
49expect {
50 timeout {puts "TESTING ERROR 8\n";exit}
51 "dport 3478"
52}
53expect {
54 timeout {puts "TESTING ERROR 10\n";exit}
55 "dport 3479"
56}
57after 100
58
59send -- "fnetfilter test2.net,icmp-type,destination-unreachable,time-exceeded,echo-request outfile\r"
60expect {
61 timeout {puts "TESTING ERROR 11\n";exit}
62 "ARG5 on line 14 was not defined"
63}
64after 100
65
66send -- "fnetfilter test2.net,icmp-type,destination-unreachable,time-exceeded,echo-request\r"
67expect {
68 timeout {puts "TESTING ERROR 12\n";exit}
69 "invalid destination file in netfilter command"
70}
71after 100
72
73send -- "fnetfilter test3.net,44 outfile\r"
74expect {
75 timeout {puts "TESTING ERROR 13\n";exit}
76 "invalid template argument on line 1"
77}
78after 100
79send -- "rm outfile\r"
80after 100
81
82puts "\nall done\n"
diff --git a/test/fnetfilter/test1.net b/test/fnetfilter/test1.net
new file mode 100644
index 000000000..59bef1443
--- /dev/null
+++ b/test/fnetfilter/test1.net
@@ -0,0 +1,19 @@
1*filter
2# test2
3:INPUT DROP [0:0]
4:FORWARD DROP [0:0]
5:OUTPUT ACCEPT [0:0]
6-A INPUT -i lo -j ACCEPT
7-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
8# echo replay is handled by -m state RELATED/ESTABLISHED above
9#-A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
10-A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
11-A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
12-A INPUT -p icmp --icmp-type echo-request -j ACCEPT
13# disable STUN
14-A OUTPUT -p udp --dport 3478 -j DROP
15-A OUTPUT -p udp --dport 3479 -j DROP
16-A OUTPUT -p tcp --dport 3478 -j DROP
17-A OUTPUT -p tcp --dport 3479 -j DROP
18COMMIT
19
diff --git a/test/fnetfilter/test2.net b/test/fnetfilter/test2.net
new file mode 100644
index 000000000..a02785413
--- /dev/null
+++ b/test/fnetfilter/test2.net
@@ -0,0 +1,19 @@
1*filter
2# test2
3:INPUT DROP [0:0]
4:FORWARD DROP [0:0]
5:OUTPUT ACCEPT [0:0]
6-A INPUT -i lo -j ACCEPT
7-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
8# echo replay is handled by -m state RELATED/ESTABLISHED above
9#-A INPUT -p icmp --$ARG1 echo-reply -j ACCEPT
10-A INPUT -p icmp --$ARG1 $ARG2 -j ACCEPT
11-A INPUT -p icmp --$ARG1 $ARG3 -j ACCEPT
12-A INPUT -p icmp --$ARG1 $ARG4 -j ACCEPT
13# disable STUN
14-A OUTPUT -p udp --dport $ARG5 -j DROP
15-A OUTPUT -p udp --dport $ARG6 -j DROP
16-A OUTPUT -p tcp --dport $ARG5 -j DROP
17-A OUTPUT -p tcp --dport $ARG6 -j DROP
18COMMIT
19
diff --git a/test/fnetfilter/test3.net b/test/fnetfilter/test3.net
new file mode 100644
index 000000000..702cb06b3
--- /dev/null
+++ b/test/fnetfilter/test3.net
@@ -0,0 +1 @@
asdfasdf $ARG asdfasdfdasf