aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@protonmail.com>2023-02-27 17:50:02 -0500
committerLibravatar netblue30 <netblue30@protonmail.com>2023-02-27 17:50:02 -0500
commite4f9f36a47d5a0031bd181e77d9121fac1dd06ec (patch)
treee0c324bd24cf6d67f50f9dd6839e321c1d2bdb2c /test
parentminor clarify userns comments (#5686) (diff)
downloadfirejail-e4f9f36a47d5a0031bd181e77d9121fac1dd06ec.tar.gz
firejail-e4f9f36a47d5a0031bd181e77d9121fac1dd06ec.tar.zst
firejail-e4f9f36a47d5a0031bd181e77d9121fac1dd06ec.zip
random hostname by default; fix --hostname and --hosts-file
Diffstat (limited to 'test')
-rwxr-xr-xtest/private-etc/hostname.exp130
-rw-r--r--test/private-etc/hosts-file2
-rwxr-xr-xtest/private-etc/private-etc.sh3
3 files changed, 135 insertions, 0 deletions
diff --git a/test/private-etc/hostname.exp b/test/private-etc/hostname.exp
new file mode 100755
index 000000000..791445d49
--- /dev/null
+++ b/test/private-etc/hostname.exp
@@ -0,0 +1,130 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2023 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --hostname=foo cat /etc/hostname\r"
11expect {
12 timeout {puts "TESTING ERROR 0\n";exit}
13 "Child process initialized"
14}
15expect {
16 timeout {puts "TESTING ERROR 0.1\n";exit}
17 "foo"
18}
19sleep 1
20
21send -- "firejail --hostname=foo --private-etc cat /etc/hostname\r"
22expect {
23 timeout {puts "TESTING ERROR 1\n";exit}
24 "Child process initialized"
25}
26expect {
27 timeout {puts "TESTING ERROR 1.1\n";exit}
28 "foo"
29}
30sleep 1
31
32send -- "firejail --hosts-file=hosts-file cat /etc/hosts\r"
33expect {
34 timeout {puts "TESTING ERROR 2\n";exit}
35 "Child process initialized"
36}
37expect {
38 timeout {puts "TESTING ERROR 2.1\n";exit}
39 "blablabla"
40}
41sleep 1
42
43send -- "firejail --hosts-file=hosts-file --private-etc cat /etc/hosts\r"
44expect {
45 timeout {puts "TESTING ERROR 3\n";exit}
46 "Child process initialized"
47}
48expect {
49 timeout {puts "TESTING ERROR 3.1\n";exit}
50 "blablabla"
51}
52sleep 1
53
54send -- "firejail --hosts-file=hosts-file --hostname=foo cat /etc/hosts\r"
55expect {
56 timeout {puts "TESTING ERROR 4\n";exit}
57 "Child process initialized"
58}
59expect {
60 timeout {puts "TESTING ERROR 4.1\n";exit}
61 "foo"
62}
63expect {
64 timeout {puts "TESTING ERROR 4.2\n";exit}
65 "blablabla"
66}
67sleep 1
68
69send -- "firejail --hosts-file=hosts-file --hostname=foo --private-etc cat /etc/hosts\r"
70expect {
71 timeout {puts "TESTING ERROR 5\n";exit}
72 "Child process initialized"
73}
74expect {
75 timeout {puts "TESTING ERROR 5.1\n";exit}
76 "foo"
77}
78expect {
79 timeout {puts "TESTING ERROR 5.2\n";exit}
80 "blablabla"
81}
82sleep 1
83
84# ping test
85send -- "firejail --hostname=foo --private-etc ping -c 3 foo\r"
86expect {
87 timeout {puts "TESTING ERROR 6\n";exit}
88 "3 packets transmitted, 3 received"
89}
90sleep 1
91
92send -- "firejail --hosts-file=hosts-file --private-etc ping -c 3 blablabla\r"
93expect {
94 timeout {puts "TESTING ERROR 7\n";exit}
95 "3 packets transmitted, 3 received"
96}
97sleep 1
98
99# random hostname
100send -- "firejail cat /etc/hostname\r"
101expect {
102 timeout {puts "TESTING ERROR 8\n";exit}
103 "Child process initialized"
104}
105expect {
106 timeout {puts "TESTING ERROR 8.1\n";exit}
107 "hiko" {puts "1"}
108 "suke" {puts "2"}
109 "shi" {puts "3"}
110 "ro" {puts "4"}
111 "hito" {puts "5"}
112 "ka" {puts "6"}
113}
114sleep 1
115
116# run /bin/hostname
117send -- "firejail --noblacklist=/usr/bin/hostname --noblacklist=/bin/hostname --hostname=foo /usr/bin/hostname\r"
118expect {
119 timeout {puts "TESTING ERROR 9\n";exit}
120 "Child process initialized"
121}
122expect {
123 timeout {puts "TESTING ERROR 9.1\n";exit}
124 "foo"
125}
126
127
128after 500
129puts "all done\n"
130
diff --git a/test/private-etc/hosts-file b/test/private-etc/hosts-file
new file mode 100644
index 000000000..1fb39596a
--- /dev/null
+++ b/test/private-etc/hosts-file
@@ -0,0 +1,2 @@
1127.0.0.1 debian
2127.5.5.5 blablabla
diff --git a/test/private-etc/private-etc.sh b/test/private-etc/private-etc.sh
index c46b684af..0dd61cb82 100755
--- a/test/private-etc/private-etc.sh
+++ b/test/private-etc/private-etc.sh
@@ -18,3 +18,6 @@ echo "TESTING: groups (test/private-etc/groups.exp)"
18 18
19echo "TESTING: etc-cleanup (test/private-etc/etc-cleanup.exp)" 19echo "TESTING: etc-cleanup (test/private-etc/etc-cleanup.exp)"
20./etc-cleanup.exp 20./etc-cleanup.exp
21
22echo "TESTING: hostname (test/private-etc/hostname.exp)"
23./hostname.exp