From d5beeffb6247a8b0e115d059491255600dd70440 Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 12 Oct 2019 14:43:26 -0600 Subject: Add test for passwd file without uid 0 --- test/fixtures/passwd_with_uid_zero | 13 +++++++++++++ test/fixtures/passwd_without_uid_zero | 12 ++++++++++++ test/uid_zero_test.bats | 8 +++++++- 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/passwd_with_uid_zero create mode 100644 test/fixtures/passwd_without_uid_zero diff --git a/test/fixtures/passwd_with_uid_zero b/test/fixtures/passwd_with_uid_zero new file mode 100644 index 0000000..125dee4 --- /dev/null +++ b/test/fixtures/passwd_with_uid_zero @@ -0,0 +1,13 @@ +## +# User Database +# +# Note that this file is consulted directly only when the system is running +# in single-user mode. At other times this information is provided by +# Open Directory. +# +# See the opendirectoryd(8) man page for additional information about +# Open Directory. +## +nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false +root:*:0:0:System Administrator:/var/root:/bin/sh +daemon:*:1:1:System Services:/var/root:/usr/bin/false diff --git a/test/fixtures/passwd_without_uid_zero b/test/fixtures/passwd_without_uid_zero new file mode 100644 index 0000000..055d52e --- /dev/null +++ b/test/fixtures/passwd_without_uid_zero @@ -0,0 +1,12 @@ +## +# User Database +# +# Note that this file is consulted directly only when the system is running +# in single-user mode. At other times this information is provided by +# Open Directory. +# +# See the opendirectoryd(8) man page for additional information about +# Open Directory. +## +nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false +daemon:*:1:1:System Services:/var/root:/usr/bin/false diff --git a/test/uid_zero_test.bats b/test/uid_zero_test.bats index 397312e..f1f1dcb 100644 --- a/test/uid_zero_test.bats +++ b/test/uid_zero_test.bats @@ -3,7 +3,13 @@ load test_helper @test "it finds the user with uid 0" { - run ./bin/uid-zero test/fixtures/passwd + run ./bin/uid-zero test/fixtures/passwd_with_uid_zero assert_success $'root:0' } + +@test "it does not find a user with uid 0" { + run ./bin/uid-zero test/fixtures/passwd_without_uid_zero + + assert_failure $'' +} -- cgit v1.2.3