summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2019-10-12 14:43:26 -0600
committermo khan <mo.khan@gmail.com>2019-10-12 14:43:26 -0600
commitd5beeffb6247a8b0e115d059491255600dd70440 (patch)
treed16d5098da5bceac5df20aac99a15a5594693145
parentf87ad6a485a005890ae24b82caa643ef90c430e8 (diff)
Add test for passwd file without uid 0
-rw-r--r--test/fixtures/passwd_with_uid_zero13
-rw-r--r--test/fixtures/passwd_without_uid_zero12
-rw-r--r--test/uid_zero_test.bats8
3 files changed, 32 insertions, 1 deletions
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 $''
+}