diff options
author | Xi Ruoyao <xry111@mengyan1223.wang> | 2021-07-20 18:24:26 +0800 |
---|---|---|
committer | Xi Ruoyao <xry111@mengyan1223.wang> | 2021-07-20 18:24:26 +0800 |
commit | 908a3c34c998a42c4bb5bcebf179c85ce62c7f59 (patch) | |
tree | 11ffb7aa82a21867ba22c0ccf368b2d26fde0c22 | |
parent | 14e0b47d284bb1c12dda5220f56626bacef49fcc (diff) | |
parent | 94862dad6173cfd146f41cd1ca1b0149f8215451 (diff) |
Merge branch 'xry111/tester-nohack' into trunk
Use a fixed UID for "tester" user, instead of the tty owner's UID.
The problem using tty owner's UID is, when tty is owned by "root" the
UID of "tester" will be 0. This cause a namesis between "tester" and
root. And, the "tester" is introduced to run some tests which are not
expected to be ran as root. If "tester" has UID 0, it will have root
priviledge and the tests will fail again.
Bash tests require the user to own the tty. To satisify it, we use
Expect to spawn a new pseudoterminal to run Bash tests.
-rw-r--r-- | appendices/dependencies.xml | 2 | ||||
-rw-r--r-- | chapter07/createfiles.xml | 2 | ||||
-rw-r--r-- | chapter08/bash.xml | 13 |
3 files changed, 12 insertions, 5 deletions
diff --git a/appendices/dependencies.xml b/appendices/dependencies.xml index 2aeef52e0..70a84730e 100644 --- a/appendices/dependencies.xml +++ b/appendices/dependencies.xml @@ -218,7 +218,7 @@ <segmentedlist id="bash-testdeps"> <segtitle>&testsuites;</segtitle> <seglistitem> - <seg>Shadow</seg> + <seg>Expect and Shadow</seg> </seglistitem> </segmentedlist> diff --git a/chapter07/createfiles.xml b/chapter07/createfiles.xml index 93abeaf8e..c55d40836 100644 --- a/chapter07/createfiles.xml +++ b/chapter07/createfiles.xml @@ -175,7 +175,7 @@ EOF</userinput></screen> user. We add this user here and delete this account at the end of that chapter.</para> -<screen><userinput>echo "tester:x:$(ls -n $(tty) | cut -d" " -f3):101::/home/tester:/bin/bash" >> /etc/passwd +<screen><userinput>echo "tester:x:101:101::/home/tester:/bin/bash" >> /etc/passwd echo "tester:x:101:" >> /etc/group install -o tester -d /home/tester</userinput></screen> diff --git a/chapter08/bash.xml b/chapter08/bash.xml index bb0f2b0fb..5007c2d46 100644 --- a/chapter08/bash.xml +++ b/chapter08/bash.xml @@ -73,11 +73,18 @@ <screen><userinput remap="test">chown -Rv tester .</userinput></screen> - <para>Now, run the tests as the <systemitem + <para>The testsuite of the package is designed to be ran as a non-root + user, owning the terminal connected to standard input. To satisify the + requirement, spawn a new pseudoterminal using + <application>Expect</application> and run the tests as the <systemitem class="username">tester</systemitem> user:</para> -<screen><userinput remap="test">su tester << EOF -PATH=$PATH make tests < $(tty) +<screen><userinput remap="test">su -s /usr/bin/expect tester << EOF +set timeout -1 +spawn make tests +expect eof +lassign [wait] _ _ _ value +exit $value EOF</userinput></screen> <para>Install the package:</para> |