Split run.exp and run.exp2 in separate tests for each

options/combinations.
This commit is contained in:
nekral-guest
2008-01-06 20:34:19 +00:00
parent 4cff2127e3
commit e4d00c832f
55 changed files with 946 additions and 315 deletions

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su --login, make a login shell
#
#=============================================================================
send "/bin/su --login $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be empty"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su --preserve-environment, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be 'bar'"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su -, make a login shell
#
#=============================================================================
send "/bin/su - $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be empty"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su -l -m, make a login shell, but preserve environment
#
#=============================================================================
send "/bin/su -l -m $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be 'bar'"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su -l, make a login shell
#
#=============================================================================
send "/bin/su - $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be empty"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su -m, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be 'bar'"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su -p -, make a login shell, but preserve environment
#
#=============================================================================
send "/bin/su -p $command - myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be 'bar'"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# su -m, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be 'bar'"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,48 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# Regular su, preserve environment
#
#=============================================================================
send "/bin/su myuser $command\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# FOO should be 'bar'"
send "\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,55 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "# "
#=============================================================================
#
# su -m -l, make a login shell, but preserve environment
# However, PATH is not preserved, but set to what it would be with login
#
#=============================================================================
send "/bin/su -p $command -l myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# PATH should be '/usr/local/bin:/usr/bin:/bin:/usr/games'"
send "\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,54 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "# "
#=============================================================================
#
# su -l, make a login shell
#
#=============================================================================
send "/bin/su - $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# PATH should be '/usr/local/bin:/usr/bin:/bin:/usr/games'"
send "\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/home/'myuser'myuser'/bin/sh'\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,56 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect -re "PATH=\"(.*)\"\r" {set PATH $expect_out(1,string)}
send_user "PATH='$PATH'"
expect "# "
#=============================================================================
#
# su -m, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# PATH should be '$PATH'"
send "\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"$PATH\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,55 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "# "
#=============================================================================
#
# Regular su, preserve environment
# However, PATH is reset
#
#=============================================================================
send "/bin/su myuser $command\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send_user "\n# PATH should be '/usr/local/bin:/usr/bin:/bin:/usr/games'"
send "\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/home/'myuser'myuser'/bin/sh'\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,57 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "# "
#=============================================================================
#
# su -l -p root, make a login shell, but preserve environment
# However, PATH is not preserved, but set to what it would be with login
# for root
#
#=============================================================================
send "/bin/su -p $command - root\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send_user "\n# PATH should be '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'"
send "\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,54 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "# "
#=============================================================================
#
# su -l root, make a login shell
#
#=============================================================================
send "/bin/su $command -l root\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send_user "\n# PATH should be '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'"
send "\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,56 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect -re "PATH=\"(.*)\"\r" {set PATH $expect_out(1,string)}
send_user "PATH='$PATH'"
expect "# "
#=============================================================================
#
# su -p root, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send_user "\n# PATH should be '$PATH'"
send "\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"$PATH\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -0,0 +1,55 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "# "
#=============================================================================
#
# Regular su to root, preserve environment
# However, PATH is reset
#
#=============================================================================
send "/bin/su $command\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send_user "\n# PATH should be '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'"
send "\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -0,0 +1 @@
run_env_test.sh

View File

@@ -1,44 +0,0 @@
#!/bin/sh
set -e
cd $(dirname $0)
# Rational:
# Test that su can be used to switch to root and to a normal account
# no testsuite password
# root password: rootF00barbaz
# myuser password: myuserF00barbaz
save()
{
[ ! -d tmp ] && mkdir tmp
for i in passwd group shadow gshadow
do
[ -f /etc/$i ] && cp /etc/$i tmp/$i
done
true
}
restore()
{
for i in passwd group shadow gshadow
do
[ -f tmp/$i ] && cp tmp/$i /etc/$i && rm tmp/$i
done
rmdir tmp
}
save
# restore the files on exit
trap 'restore' 0
cp data/{passwd,shadow,group,gshadow} /etc/
./run.exp
./run.exp "-c bash"
./run.exp2
./run.exp2 "-c bash"

View File

@@ -1,103 +0,0 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export FOO=bar\r"
expect "# "
#=============================================================================
#
# Regular su, preserve environment
#
#=============================================================================
send "/bin/su myuser $command\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# su -, make a login shell
#
#=============================================================================
send "/bin/su - $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"\"\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# su -m, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# su -m -, make a login shell, but preserve environment
#
#=============================================================================
send "/bin/su -p $command - myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"FOO=\\\"\$FOO\\\"\"\r"
expect "FOO=\"bar\"\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

View File

@@ -1,168 +0,0 @@
#!/usr/bin/expect
if {$argc == 1} {
set command [lindex $argv 0]
} else {
set command ""
}
set timeout 2
expect_after default {puts "\nFAIL"; exit 1}
spawn /bin/bash
expect "# "
send "id\r"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "export PATH=bar:\$PATH\r"
expect "# "
#=============================================================================
#
# Regular su, preserve environment
# However, PATH is reset
#
#=============================================================================
send "/bin/su myuser $command\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/home/'myuser'myuser'/bin/sh'\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# su -, make a login shell
#
#=============================================================================
send "/bin/su - $command myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/home/'myuser'myuser'/bin/sh'\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# Regular su to root, preserve environment
# However, PATH is reset
#
#=============================================================================
send "/bin/su $command\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
#=============================================================================
#
# su - root, make a login shell
#
#=============================================================================
send "/bin/su $command - root\r"
expect "# "
send "id\n"
expect "uid=0(root) gid=0(root) groups=0(root)\r"
expect "# "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "# "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "# "
send "exit\r"
expect "# "
#=============================================================================
#
# su -m, as for regular su, environment is preserved
#
#=============================================================================
send "/bin/su $command -m myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"bar:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "$ "
send "exit\r"
expect "# "
#=============================================================================
#
# su -m -, make a login shell, but preserve environment
# However, PATH is not preserved, but set to what it would be with login
#
#=============================================================================
send "/bin/su -p $command - myuser\r"
expect "$ "
send "id\n"
expect "uid=424242(myuser) gid=424242(myuser) groups=424242(myuser)\r"
expect "$ "
send "echo \"PATH=\\\"\$PATH\\\"\"\r"
expect "PATH=\"/usr/local/bin:/usr/bin:/bin:/usr/games\"\r"
expect "$ "
send "echo \"'\$HOME'\$USER'\$LOGNAME'\$SHELL'\"\r"
expect "'/root'root'root'/bin/bash'\r"
expect "$ "
send "exit\r"
expect "# "
puts "\nPASS"
exit 0

38
tests/su/02/run_env_test.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
set -e
cd $(dirname $0)
testname=$(basename $0)
. ../../common/config.sh
. ../../common/log.sh
command=""
case "$testname" in
*_bash)
log_start "$0" "propagation of environment variable FOO in command bash: $testname"
testname=$(echo "$testname" | sed -s 's/_bash$//')
command="-c bash"
echo testname: $testname
;;
*)
log_start "$0" "propagation of environment variable FOO: $test"
;;
esac
save_config
# restore the files on exit
trap 'log_status "$0" "FAILURE"; restore_config' 0
change_config
"./$testname.exp" "$command"
log_status "$0" "SUCCESS"
restore_config
trap '' 0