diff options
| -rwxr-xr-x | bin/uid-zero | 6 | ||||
| -rw-r--r-- | test/uid_zero_test.bats | 9 |
2 files changed, 13 insertions, 2 deletions
diff --git a/bin/uid-zero b/bin/uid-zero index 2976cbb..9b2640f 100755 --- a/bin/uid-zero +++ b/bin/uid-zero @@ -1,7 +1,9 @@ #!/bin/bash +FILE=${1:-'/etc/passwd'} + if [[ "$OSTYPE" == "darwin"* ]]; then - cat /etc/passwd | cut -d: -f1,3 | grep ':0' + cat $FILE | cut -d: -f1,3 | grep ':0' else - cat /etc/passwd | grep -P '^\w+:[x]:\d+:0.*$' + cat $FILE | grep -P '^\w+:[x]:\d+:0.*$' fi diff --git a/test/uid_zero_test.bats b/test/uid_zero_test.bats new file mode 100644 index 0000000..397312e --- /dev/null +++ b/test/uid_zero_test.bats @@ -0,0 +1,9 @@ +#!/usr/bin/env bats + +load test_helper + +@test "it finds the user with uid 0" { + run ./bin/uid-zero test/fixtures/passwd + + assert_success $'root:0' +} |
