OILS / test / manual.sh View on Github | oils.pub

71 lines, 19 significant
1#!/usr/bin/env bash
2#
3# Manual tests
4#
5# Usage:
6# test/manual.sh <function name>
7
8: ${LIB_OSH=stdlib/osh}
9source $LIB_OSH/bash-strict.sh
10source $LIB_OSH/task-five.sh
11
12readonly OSHRC=_tmp/manual-oshrc
13
14setup() {
15 cat >$OSHRC <<EOF
16OILS_COMP_UI=nice
17EOF
18}
19
20test-osh() {
21 # Test it manually
22 bin/osh --rcfile $OSHRC
23}
24
25test-ysh() {
26 # same OSHRC? Should it respect ENV.OILS_COMP_UI?
27 bin/ysh --rcfile $OSHRC
28}
29
30no-home-dir() {
31 ### Trying to tickle code path hit via oily-pine
32
33 local sh=${1:-bash}
34 # env -i gets rid of $HOME
35 # unshare allows us to fake /etc/passwd
36 env -i -- unshare --user --mount --map-root-user bash -c '
37 sh=$1
38
39 #set -x
40
41 cmd="wc -l /etc/passwd; echo home \$HOME; echo tilde ~"
42
43 whoami
44 $sh -c "$cmd"
45 echo
46
47 #mount --bind /dev/null /etc/passwd
48 echo "bob:x:1001:1001:Bob:/tmp:/bin/bash" > /tmp/passwd
49 mount --bind /tmp/passwd /etc/passwd
50
51 echo "bob:x:1001:h" > /tmp/group
52 mount --bind /tmp/group /etc/group
53
54 getent passwd bob
55 su - bob
56 #sudo -u bob bash
57
58 #wc -l /etc/passwd
59 #cat /etc/passwd
60
61 #su -s $sh "#1001" -c "$cmd"
62 #su -s $sh bob -c "$cmd"
63
64 #setuidgid 1000 $sh -c "$cmd"
65
66 #setpriv --reuid=1001 --regid=1001 --clear-groups -- $sh -c "$cmd"
67 #sudo -u "#1001" $sh -c "$cmd"
68 ' dummy0 $sh
69}
70
71task-five "$@"