Browse Source

Initial test to check for a root password

Joe Ferguson 10 years ago
parent
commit
67c4396c85
2 changed files with 12 additions and 0 deletions
  1. 4 0
      test/config.sh
  2. 8 0
      test/tests/no-root-password/run.sh

+ 4 - 0
test/config.sh

@@ -4,6 +4,7 @@ set -e
 globalTests=(
 	utc
 	cve-2014--shellshock
+	no-root-password
 )
 
 declare -A testAlias=(
@@ -110,6 +111,9 @@ declare -A globalExcludeTests=(
 	# single-binary images
 	[hello-world_utc]=1
 	[swarm_utc]=1
+	
+	[hello-world_no-root-password]=1
+	[swarm_no-root-password]=1
 
 	# no "native" dependencies
 	[ruby:slim_ruby-bundler]=1

+ 8 - 0
test/tests/no-root-password/run.sh

@@ -0,0 +1,8 @@
+#!/bin/bash
+set -e
+
+pass="$(docker run --rm --entrypoint awk "$1" -F ':' '$1 == "root" { print $2 }' /etc/passwd)"
+if [ "$pass" = 'x' ]; then
+	pass="$(docker run --rm --entrypoint awk --user root "$1" -F ':' '$1 == "root" { print $2 }' /etc/shadow)"
+fi
+[ -z "$pass" -o "$pass" = '*' ]