xref: /aosp_15_r20/external/toybox/tests/id.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1*cf5a6c84SAndroid Build Coastguard Worker#!/bin/bash
2*cf5a6c84SAndroid Build Coastguard Worker
3*cf5a6c84SAndroid Build Coastguard Worker[ -f testing.sh ] && . testing.sh
4*cf5a6c84SAndroid Build Coastguard Worker
5*cf5a6c84SAndroid Build Coastguard Worker#testing "name" "command" "result" "infile" "stdin"
6*cf5a6c84SAndroid Build Coastguard Worker
7*cf5a6c84SAndroid Build Coastguard Worker# Systems with SELinux will have security context cruft,
8*cf5a6c84SAndroid Build Coastguard Worker# BSDs call the root group "wheel" instead,
9*cf5a6c84SAndroid Build Coastguard Worker# and Raspberry Pi OS has root also in the 117(lpadmin) group.
10*cf5a6c84SAndroid Build Coastguard WorkerCLEAN="sed 's/ context=.*//g' | sed 's/wheel/root/g' | \
11*cf5a6c84SAndroid Build Coastguard Workersed 's/117//g' | sed -E 's/\(?lpadmin\)?//g' | sed 's/[ ,]$//'"
12*cf5a6c84SAndroid Build Coastguard Worker
13*cf5a6c84SAndroid Build Coastguard Workertesting "0" "id 0 | $CLEAN" "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
14*cf5a6c84SAndroid Build Coastguard Workertesting "root" "id root | $CLEAN" \
15*cf5a6c84SAndroid Build Coastguard Worker  "uid=0(root) gid=0(root) groups=0(root)\n" "" ""
16*cf5a6c84SAndroid Build Coastguard Workertesting "-G root" "id -G root | $CLEAN" "0\n" "" ""
17*cf5a6c84SAndroid Build Coastguard Workertesting "-nG root" "id -nG root | $CLEAN" "root\n" "" ""
18*cf5a6c84SAndroid Build Coastguard Workertesting "-g root" "id -g root" "0\n" "" ""
19*cf5a6c84SAndroid Build Coastguard Workertesting "-ng root" "id -ng root | $CLEAN" "root\n" "" ""
20*cf5a6c84SAndroid Build Coastguard Workertesting "-u root" "id -u root" "0\n" "" ""
21*cf5a6c84SAndroid Build Coastguard Workertesting "-nu root" "id -nu root" "root\n" "" ""
22*cf5a6c84SAndroid Build Coastguard Workertesting "no-such-user" "id no-such-user 2>/dev/null ; echo \$?" "1\n" "" ""
23*cf5a6c84SAndroid Build Coastguard Workertesting "2147483647" "id 2147483647 2>/dev/null ; echo \$?" "1\n" "" ""
24