From 62a19b0cac1646b0187e860f9edfb0843f572d1e Mon Sep 17 00:00:00 2001 From: netblue30 Date: Tue, 8 Nov 2016 11:55:57 -0500 Subject: testing --- test/fs/fs.sh | 8 ++++- test/fs/private-home-dir.exp | 70 ++++++++++++++++++++++++++++++++++++++++++++ test/fs/private-home.exp | 45 ++++++++++++++++++++++++++++ test/fs/private.exp | 51 ++++++++++++++++---------------- 4 files changed, 147 insertions(+), 27 deletions(-) create mode 100755 test/fs/private-home-dir.exp create mode 100755 test/fs/private-home.exp (limited to 'test/fs') diff --git a/test/fs/fs.sh b/test/fs/fs.sh index 3139b8eae..812da02b0 100755 --- a/test/fs/fs.sh +++ b/test/fs/fs.sh @@ -22,7 +22,13 @@ echo "TESTING: read/write /dev/shm (test/fs/fs_dev_shm.exp)" ./fs_dev_shm.exp echo "TESTING: private (test/fs/private.exp)" -./private.exp `whoami` +./private.exp + +echo "TESTING: private home (test/fs/private-home.exp)" +./private-home.exp + +echo "TESTING: private home dir (test/fs/private-home-dir.exp)" +./private-home-dir.exp echo "TESTING: private-etc (test/fs/private-etc.exp)" ./private-etc.exp diff --git a/test/fs/private-home-dir.exp b/test/fs/private-home-dir.exp new file mode 100755 index 000000000..5491be834 --- /dev/null +++ b/test/fs/private-home-dir.exp @@ -0,0 +1,70 @@ +#!/usr/bin/expect -f +# This file is part of Firejail project +# Copyright (C) 2014-2016 Firejail Authors +# License GPL v2 + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + + +if {[file exists ~/.asoundrc]} { + puts "found .asoundrc file\n" +} else { + send -- "touch ~/.asoundrc\r" +} +after 100 + +if {[file exists ~/.Xauthority]} { + puts "found .Xauthority file\n" +} else { + send -- "touch ~/.Xauthority\r" +} +after 100 +send -- "mkdir ~/_firejail_test_dir_\r" +sleep 1 + +# testing profile and private +send -- "firejail --private=~/_firejail_test_dir_\r" +expect { + timeout {puts "TESTING ERROR 0\n";exit} + "Child process initialized" +} +sleep 1 + +send -- "ls -l ~\r" +expect { + timeout {puts "TESTING ERROR 1\n";exit} + "total 0" +} +after 100 + +send -- "ls -al ~\r" +expect { + timeout {puts "TESTING ERROR 2\n";exit} + ".asoundrc" +} +expect { + timeout {puts "TESTING ERROR 3\n";exit} + ".bashrc" +} +expect { + timeout {puts "TESTING ERROR 4\n";exit} + ".Xauthority" +} +after 100 + +send -- "exit\r" +sleep 1 + + +# testing profile and private +send -- "firejail --private=/etc\r" +expect { + timeout {puts "TESTING ERROR 5\n";exit} + "private directory should be owned by the current user" +} +sleep 1 + + +puts "all done\n" diff --git a/test/fs/private-home.exp b/test/fs/private-home.exp new file mode 100755 index 000000000..de5a88dea --- /dev/null +++ b/test/fs/private-home.exp @@ -0,0 +1,45 @@ +#!/usr/bin/expect -f +# This file is part of Firejail project +# Copyright (C) 2014-2016 Firejail Authors +# License GPL v2 + +set timeout 10 +spawn $env(SHELL) +match_max 100000 + +# create some test files in user home directory +send -- "touch ~/_firejail_test_file1\r" +send -- "touch ~/_firejail_test_file2\r" +send -- "mkdir ~/_firejail_test_dir1\r" +send -- "mkdir ~/_firejail_test_dir1/_firejail_test_dir2\r" +send -- "touch ~/_firejail_test_dir1/_firejail_test_dir2/_firejail_test_file3\r" +after 100 + +send -- "firejail --private-home=_firejail_test_file1,_firejail_test_file2,_firejail_test_dir1\r" +expect { + timeout {puts "TESTING ERROR 1\n";exit} + "Child process initialized" +} +after 100 + +send -- "find ~\r" +expect { + timeout {puts "TESTING ERROR 2\n";exit} + "_firejail_test_file3" +} +expect { + timeout {puts "TESTING ERROR 3\n";exit} + "_firejail_test_file2" +} +expect { + timeout {puts "TESTING ERROR 4\n";exit} + "_firejail_test_file1" +} +after 100 + +send -- "rm -f ~/_firejail_test_file*\r" +send -- "rm -fr ~/_firejail_test_dir*\r" +after 100 + +puts "\nall done\n" + diff --git a/test/fs/private.exp b/test/fs/private.exp index 67435b888..8114ee45d 100755 --- a/test/fs/private.exp +++ b/test/fs/private.exp @@ -7,53 +7,52 @@ set timeout 10 spawn $env(SHELL) match_max 100000 -if { $argc != 1 } { - puts "TESTING ERROR: argument missing" - puts "Usage: private.exp username" - puts "where username is the name of the current user" - exit + +if {[file exists ~/.asoundrc]} { + puts "found .asoundrc file\n" +} else { + send -- "touch ~/.asoundrc\r" } +after 100 + +if {[file exists ~/.Xauthority]} { + puts "found .Xauthority file\n" +} else { + send -- "touch ~/.Xauthority\r" +} +after 100 # testing profile and private -send -- "firejail --private --profile=/etc/firejail/default.profile\r" +send -- "firejail --private\r" expect { timeout {puts "TESTING ERROR 0\n";exit} "Child process initialized" } sleep 1 -send -- "exit\r" -sleep 1 -send -- "firejail --private --noprofile\r" +send -- "ls -l ~\r" expect { timeout {puts "TESTING ERROR 1\n";exit} - "Child process initialized" + "total 0" } +after 100 -sleep 1 -send -- "cd ~; ls -al; echo done\r" +send -- "ls -al ~\r" expect { timeout {puts "TESTING ERROR 2\n";exit} - ".bashrc" + ".asoundrc" } expect { timeout {puts "TESTING ERROR 3\n";exit} - done -} - -# owner /tmp -send -- "stat -c %U%a /tmp;echo done\r" -expect { - timeout {puts "TESTING ERROR 10\n";exit} - "root777" {puts "version 1\n";} - "root1777" {puts "version 2\n";} - "nobody777" {puts "version 3\n";} - "nobody1777" {puts "version 4\n";} + ".bashrc" } expect { - timeout {puts "TESTING ERROR 11\n";exit} - "done" + timeout {puts "TESTING ERROR 4\n";exit} + ".Xauthority" } after 100 +send -- "exit\r" +sleep 1 + puts "all done\n" -- cgit v1.2.3-54-g00ecf