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
|
summary: Ensure our osutil.Find{Uid,Gid} code work with libnss
details: |
The os/user code in go will behave differently when compiled with
or without cgo. This is confusing so we created the helpers
osutil.Find{Uid,Gid} that automatically fall back to calling
getent(1) when build without cgo. This test ensures these are
working correctly.
# only run on a well defined system where we know how to setup libnss
systems: [ubuntu-18.04-64]
prepare: |
echo "Save nsswitch.conf"
cp /etc/nsswitch.conf /etc/nsswitch.conf.save
echo "Install extrausers"
apt install libnss-extrausers
echo "Enable libnss-extrusers"
sed -i 's/^group:.*compat/\0 extrausers/' /etc/nsswitch.conf
sed -i 's/^passwd:.*compat/\0 extrausers/' /etc/nsswitch.conf
sed -i 's/^shadow:.*compat/\0 extrausers/' /etc/nsswitch.conf
echo "Workaround silly bug that causes extrausers to crash when missing"
for name in gshadow shadow; do
touch /var/lib/extrausers/$name
chmod 640 /var/lib/extrausers/$name
chown root:shadow /var/lib/extrausers/$name
done
echo "Add user"
adduser --extrausers --disabled-login --no-create-home --gecos '' --uid 9876 --shell /bin/false extratest
restore: |
mv /etc/nsswitch.conf.save /etc/nsswitch.conf
apt autoremove -y libnss-extrausers
rm -rf /var/lib/extrausers
execute: |
echo "Ensure tests run with both CGO and without"
su test -c 'CGO_ENABLED=1 go test -mod vendor github.com/snapcore/snapd/osutil'
su test -c 'CGO_ENABLED=0 go test -mod vendor github.com/snapcore/snapd/osutil'
CGO_ENABLED=1 go build -o findid-cgo ./findid.go
CGO_ENABLED=0 go build -o findid-no-cgo ./findid.go
# precondition check
getent passwd extratest
getent group extratest
echo "Run binaries (CGO, without) exercising the helpers"
test "$(./findid-cgo uid extratest)" = "9876"
test "$(./findid-cgo gid extratest)" = "9876"
test "$(./findid-no-cgo uid extratest)" = "9876"
test "$(./findid-no-cgo gid extratest)" = "9876"
|