#!/usr/bin/expect -f
# This file is part of Firejail project
# Copyright (C) 2014-2024 Firejail Authors
# License GPL v2

set timeout 10
match_max 100000
spawn $env(SHELL)
set id1 $spawn_id
spawn $env(SHELL)
set id2 $spawn_id

send -- "stty -echo\r"
after 100

#
# regular run
#
set spawn_id $id1
send --  "firejail --name=jointesting --debug\r"
expect {
	timeout {puts "TESTING ERROR 0\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 1\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.32 seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 2\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.protocol seccomp filter"
}
sleep 1

set spawn_id $id2

send --  "firejail --debug --join=jointesting\r"
expect {
	timeout {puts "TESTING ERROR 3\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 4\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.32 seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 5\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.protocol seccomp filter"
}
sleep 1

send -- "exit\r"
after 100
set spawn_id $id1
send -- "exit\r"
after 100



#
# block secondary
#
set spawn_id $id1
send --  "firejail --name=jointesting --seccomp.block-secondary --debug\r"
expect {
	timeout {puts "TESTING ERROR 10\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 11\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.32 seccomp filter" {puts "TESTING ERROR 12\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.block_secondary seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 13\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.protocol seccomp filter"
}
sleep 1

set spawn_id $id2
send --  "firejail --debug --join=jointesting\r"
expect {
	timeout {puts "TESTING ERROR 14\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 15\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.block_secondary seccomp filter"
}
expect {
	timeout {puts "TESTING ERROR 16\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.protocol seccomp filter"
}
sleep 1

send -- "exit\r"
after 100
set spawn_id $id1
send -- "exit\r"
after 100

#
# protocol
#
set spawn_id $id1
send --  "firejail --name=jointesting --noprofile --protocol=inet --debug\r"
expect {
	timeout {puts "TESTING ERROR 22\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.protocol seccomp filter"
}
sleep 1

set spawn_id $id2

send --  "firejail --debug --join=jointesting\r"
expect {
	timeout {puts "TESTING ERROR 23\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp seccomp filter" {puts "TESTING ERROR 24\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.32 seccomp filter" {puts "TESTING ERROR 25\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.protocol seccomp filter"
}
sleep 1

send -- "exit\r"
after 100
set spawn_id $id1
send -- "exit\r"
after 100

#
# memory deny write execute
#
set spawn_id $id1
send --  "firejail --name=jointesting --noprofile --memory-deny-write-execute --debug\r"
expect {
	timeout {puts "TESTING ERROR 32\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.mdwx seccomp filter"
}
sleep 1

set spawn_id $id2

send --  "firejail --debug --join=jointesting\r"
expect {
	timeout {puts "TESTING ERROR 33\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp seccomp filter" {puts "TESTING ERROR 34\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.32 seccomp filter" {puts "TESTING ERROR 35\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.protocol seccomp filter" {puts "TESTING ERROR 36\n";exit}
	"Installing /run/firejail/mnt/seccomp/seccomp.mdwx seccomp filter"
}
sleep 1

send -- "exit\r"
after 100
set spawn_id $id1
send -- "exit\r"
after 100

puts "all done\n"
