From 126c317d5ceee7802d52fc6be1b695f759aa6725 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 2 Nov 2019 22:58:42 -0700 Subject: id: support numeric lookup. Fall back to converting the "name" to an integer and calling getpwuid(). We need to update `username` for the later call to getgrouplist(). Also fix the separator printing logic to avoid a trailing ',' on `id 0`. Switch to FLAG() and move some declarations down to where they can be initialized, both for clarity. Also add simple tests. Sadly, there's no always-present user that is in multiple groups. --- tests/id.test | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 tests/id.test (limited to 'tests') diff --git a/tests/id.test b/tests/id.test new file mode 100755 index 00000000..6d0f63a8 --- /dev/null +++ b/tests/id.test @@ -0,0 +1,10 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +testing "id 0" "id 0" "uid=0(root) gid=0(root) groups=0(root)\n" "" "" +testing "id root" "id root" "uid=0(root) gid=0(root) groups=0(root)\n" "" "" +testing "id no-such-user" "id no-such-user 2>/dev/null ; echo \$?" "1\n" "" "" +testing "id 9999999" "id 9999999 2>/dev/null ; echo \$?" "1\n" "" "" -- cgit v1.2.3