-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.sh
More file actions
executable file
·131 lines (101 loc) · 2.99 KB
/
tests.sh
File metadata and controls
executable file
·131 lines (101 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# Note: idealy, we'd use python, but the base-docker image does not have it
# installed!
set -euo pipefail
failed=0
success() {
echo "OK: $*"
}
failure() {
echo "FAIL: $*"
failed=1
}
# test string is an executable on the path
test_executable() {
local exe=$1
if command -v "$exe" > /dev/null; then
success "$exe was present and executable"
else
failure "$exe - could not find $exe"
fi
}
output=$(mktemp /tmp/output.XXXX)
# test that the entrypoint is invoked properly
test_entrypoint() {
if ./entrypoint.sh "$@" > "$output" 2>&1; then
success "entrypoint.sh $*"
else
failure "'entrypoint.sh $* exited with $?"
fi
}
assert_output() {
local file=$1
shift
if grep -q "$@" "$file"; then
success "'$*' found in $file"
else
failure "'$*' not found in $file"
fi
}
test_executable iostat
test_executable lsof
test_executable netstat
test_executable tcpdump
test_executable vi
test_executable strace
# test install works w/o UPDATE=yes
/root/docker-apt-install.sh make
# test ubuntu pro
if grep -q 'VERSION_ID="20.04"' /etc/os-release; then
# check we are using packages from ESM archives
dpkg-query -W -f='${Package}\t${Version}\n' libssl1.1 > "$output"
assert_output "$output" "esm"
# check we have not left any files with the token on the image
if test ! -e /tmp/pro-attach-config.yaml &&
test ! -d /etc/ubuntu-advantage &&
test ! -d /var/lib/ubuntu-advantage &&
test ! -e /var/log/ubuntu-advantage.log &&
! dpkg -l | grep -q ubuntu-pro-client; then
success "no Ubuntu Pro files found"
else
failure "Found Ubuntu Pro file that should not be in the image"
fi
fi
# test script that just echos its arguments for testing
script=$(mktemp /tmp/action_exec.XXXX.sh)
chmod +x "$script"
# Quoting EOF disables expansion. Obvs.
cat > "$script" << 'EOF'
#!/bin/bash
echo "$0" "$@"
EOF
export ACTION_EXEC=$script
# no args
test_entrypoint " "
assert_output "$output" "$script"
# passes args
test_entrypoint a -b --ccc
assert_output "$output" "$script a -b --ccc"
# test default bash ACTION_EXEC works
unset ACTION_EXEC
test_entrypoint "$script" a -b --ccc
assert_output "$output" "$script a -b --ccc"
# check an elf executable is executed directly
test_entrypoint dash -c 'echo SUCCESS'
assert_output "$output" "SUCCESS"
# check we dereference symlinks
# create a symlink to bash in the current dir, so we can use it mounted in /workspace
ln -sf "/usr/bin/bash" "bash.link"
test_entrypoint ./bash.link -c "echo SUCCESS"
assert_output "$output" "SUCCESS"
non_exec_script=$(mktemp /tmp/user_script.XXXX)
echo SUCCESS > "$non_exec_script"
# this should result in 'cat $non_exec_script'
export ACTION_EXEC=cat
test_entrypoint "$non_exec_script"
assert_output "$output" "SUCCESS"
# test windows mounted filesystem behavior: file has execute permission but is not actually executable
chmod +x "$non_exec_script"
test_entrypoint "$non_exec_script"
assert_output "$output" "SUCCESS"
exit $failed