diff options
| -rw-r--r-- | README.md | 2 | ||||
| -rwxr-xr-x | bin/no-password | 4 | ||||
| -rw-r--r-- | test/fixtures/passwd_with_missing_password | 3 | ||||
| -rw-r--r-- | test/no-password_test.bats | 15 |
4 files changed, 22 insertions, 2 deletions
@@ -1178,7 +1178,7 @@ Rootly Powers and Processes fi ``` - b. Find entries that have that have no password (needs /etc/shadow). + b. Find entries that have no password (needs /etc/shadow). ```bash #!/bin/bash diff --git a/bin/no-password b/bin/no-password index 7ed2797..bd32709 100755 --- a/bin/no-password +++ b/bin/no-password @@ -1,3 +1,5 @@ #!/bin/bash -grep -E '^\w+::.*' /etc/passwd +FILE=${1:-'/etc/passwd'} + +grep -E '^\w+::.*' $FILE diff --git a/test/fixtures/passwd_with_missing_password b/test/fixtures/passwd_with_missing_password new file mode 100644 index 0000000..37f51ad --- /dev/null +++ b/test/fixtures/passwd_with_missing_password @@ -0,0 +1,3 @@ +nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false +root:*:0:0:System Administrator:/var/root:/bin/sh +daemon::1:1:daemon:/tmp:/usr/bin/false diff --git a/test/no-password_test.bats b/test/no-password_test.bats new file mode 100644 index 0000000..815b25e --- /dev/null +++ b/test/no-password_test.bats @@ -0,0 +1,15 @@ +#!/usr/bin/env bats + +load test_helper + +@test "it finds a user without a password" { + run ./bin/no-password test/fixtures/passwd_with_missing_password + + assert_success $'daemon::1:1:daemon:/tmp:/usr/bin/false' +} + +@test "it does not find any users that are missing a password" { + run ./bin/no-password test/fixtures/passwd_with_uid_zero + + assert_failure $'' +} |
