Commit 58bd6d6a authored by Emanuele Aina's avatar Emanuele Aina

Test resolution of current unknown user

Test behaviour when resolving the current user with HOME set or unset,
pretending that the user is not in the passwd db by using nss_wrapper.

Use `meson test` to run the test.
Signed-off-by: Emanuele Aina's avatarEmanuele Aina <emanuele.aina@collabora.com>
parent 3faffd5f
......@@ -3,4 +3,9 @@ project('libnss-unknown',
version: '0.0.1')
sources = [ 'src/nss-unknown.c' ]
shared_library('nss_unknown', sources, soversion: '2', install: true)
shlib = shared_library('nss_unknown', sources, soversion: '2', install: true)
testenv = environment()
testenv.set('MESON_BUILD_ROOT', meson.build_root())
test('Resolve unknown current user', find_program('tests/resolve-unknown-current-user.t'), env: testenv, depends:shlib)
#!/bin/sh
# SPDX-License-Identifier: LGPL-2.1+
#
# Copyright (C) 2018 Collabora ltd.
# @author Emanuele Aina <emanuele.aina@collabora.com>
test_description="Use nss_wrapper to pretend the current user is not in the db"
. /usr/share/sharness/sharness.sh
test_debug "export NSS_WRAPPER_DEBUGLEVEL=3"
get_passwd_entry () {
USERID=$1
env -i \
${HOME+HOME=$HOME} \
${NSS_WRAPPER_DEBUGLEVEL+NSS_WRAPPER_DEBUGLEVEL=$NSS_WRAPPER_DEBUGLEVEL} \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_PASSWD=/dev/null \
NSS_WRAPPER_GROUP=/dev/null \
NSS_WRAPPER_MODULE_SO_PATH="${MESON_BUILD_ROOT}/libnss_unknown.so" \
NSS_WRAPPER_MODULE_FN_PREFIX=unknown \
getent passwd "$USERID"
}
export HOME="/fakehome"
entry=$(get_passwd_entry $(id -u))
test_debug "echo entry = '$entry'"
test_expect_success 'A passwd entry is returned' \
'test -n "$entry"'
username=$(echo "$entry" | cut -f 1 -d ":")
shell=$(echo "$entry" | cut -f 7 -d ":")
home=$(echo "$entry" | cut -f 6 -d ":")
test_debug "echo username = '$username'"
test_expect_success 'A made-up username is returned for the unknown user' \
'test "$username" = uid-$(id -u)'
test_debug "echo shell = '$shell'"
test_expect_success 'The nologin command is returned as the user shell' \
'test "$shell" = /sbin/nologin'
test_debug "echo home = '$home'"
test_expect_success 'The $HOME env var is returned as the user homedir' \
'test "$home" = "$HOME"'
unset HOME
entry=$(get_passwd_entry $(id -u))
home=$(echo "$entry" | cut -f 6 -d ":")
test_debug "echo entry = '$entry'"
test_debug "echo home = '$home'"
test_expect_success 'Fallback to "/" if $HOME is not set' \
'test "$home" = "/"'
test_done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment