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

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 <>
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)
# SPDX-License-Identifier: LGPL-2.1+
# Copyright (C) 2018 Collabora ltd.
# @author Emanuele Aina <>
test_description="Use nss_wrapper to pretend the current user is not in the db"
. /usr/share/sharness/
test_debug "export NSS_WRAPPER_DEBUGLEVEL=3"
get_passwd_entry () {
env -i \
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" = "/"'
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