Return-Path: From: Wang Mingyu Date: Wed, 28 Nov 2018 07:47:39 -0800 Message-ID: <1543420064-1823-2-git-send-email-wangmy@cn.fujitsu.com> In-Reply-To: <1543420064-1823-1-git-send-email-wangmy@cn.fujitsu.com> References: <1543420064-1823-1-git-send-email-wangmy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Fuego] [PATCH] Add test case of command passwd. List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org Signed-off-by: Wang Mingyu --- .../tests/Functional.passwd/data/common-password | 27 +++++++++++++ engine/tests/Functional.passwd/fuego_test.sh | 19 +++++++++ engine/tests/Functional.passwd/parser.py | 22 +++++++++++ engine/tests/Functional.passwd/passwd_test.sh | 4 ++ engine/tests/Functional.passwd/spec.json | 7 ++++ engine/tests/Functional.passwd/tests/passwd.sh | 45 ++++++++++++++++++++++ 6 files changed, 124 insertions(+) create mode 100644 engine/tests/Functional.passwd/data/common-password create mode 100644 engine/tests/Functional.passwd/fuego_test.sh create mode 100644 engine/tests/Functional.passwd/parser.py create mode 100755 engine/tests/Functional.passwd/passwd_test.sh create mode 100644 engine/tests/Functional.passwd/spec.json create mode 100644 engine/tests/Functional.passwd/tests/passwd.sh diff --git a/engine/tests/Functional.passwd/data/common-password b/engine/tests/Functional.passwd/data/common-password new file mode 100644 index 0000000..7d3d3c5 --- /dev/null +++ b/engine/tests/Functional.passwd/data/common-password @@ -0,0 +1,27 @@ +# +# /etc/pam.d/common-password - password-related modules common to all services +# +# This file is included from other service-specific PAM config files, +# and should contain a list of modules that define the services to be +# used to change user passwords. The default is pam_unix. + +# Explanation of pam_unix options: +# +# The "sha512" option enables salted SHA512 passwords. Without this option, +# the default is Unix crypt. Prior releases used the option "md5". +# +# The "obscure" option replaces the old `OBSCURE_CHECKS_ENAB' option in +# login.defs. +# +# See the pam_unix manpage for other options. + +# here are the per-package modules (the "Primary" block) +password requisite pam_cracklib.so try_first_pass retry=3 type= +password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadow +# here's the fallback if no module succeeds +password requisite pam_deny.so +# prime the stack with a positive return value if there isn't one already; +# this avoids us returning an error just because nothing sets a success code +# since the modules above will each just jump around +password required pam_permit.so +# and here are more per-package modules (the "Additional" block) diff --git a/engine/tests/Functional.passwd/fuego_test.sh b/engine/tests/Functional.passwd/fuego_test.sh new file mode 100644 index 0000000..6d691f1 --- /dev/null +++ b/engine/tests/Functional.passwd/fuego_test.sh @@ -0,0 +1,19 @@ +function test_pre_check { + assert_has_program passwd + assert_has_program expect +} + +function test_deploy { + put $TEST_HOME/passwd_test.sh $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/tests $BOARD_TESTDIR/fuego.$TESTDIR/ + put -r $TEST_HOME/data $BOARD_TESTDIR/fuego.$TESTDIR/ +} + +function test_run { + report "cd $BOARD_TESTDIR/fuego.$TESTDIR;\ + ./passwd_test.sh" +} + +function test_processing { + log_compare "$TESTDIR" "0" "TEST-FAIL" "n" +} diff --git a/engine/tests/Functional.passwd/parser.py b/engine/tests/Functional.passwd/parser.py new file mode 100644 index 0000000..d85abd7 --- /dev/null +++ b/engine/tests/Functional.passwd/parser.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +# See common.py for description of command-line arguments + +import os, sys, collections + +sys.path.insert(0, os.environ['FUEGO_CORE'] + '/engine/scripts/parser') +import common as plib + +measurements = {} +measurements = collections.OrderedDict() + +regex_string = '^ -> (.*): TEST-(.*)$' +matches = plib.parse_log(regex_string) + +if matches: + for m in matches: + measurements['default.' + m[0]] = 'PASS' if m[1] == 'PASS' else 'FAIL' + +# split the output for each testcase +plib.split_output_per_testcase(regex_string, measurements) + +sys.exit(plib.process(measurements)) diff --git a/engine/tests/Functional.passwd/passwd_test.sh b/engine/tests/Functional.passwd/passwd_test.sh new file mode 100755 index 0000000..dd5ce37 --- /dev/null +++ b/engine/tests/Functional.passwd/passwd_test.sh @@ -0,0 +1,4 @@ +#!/bin/sh +for i in tests/*.sh; do + sh $i +done diff --git a/engine/tests/Functional.passwd/spec.json b/engine/tests/Functional.passwd/spec.json new file mode 100644 index 0000000..5332f79 --- /dev/null +++ b/engine/tests/Functional.passwd/spec.json @@ -0,0 +1,7 @@ +{ + "testName": "Functional.passwd", + "specs": { + "default": {} + } +} + diff --git a/engine/tests/Functional.passwd/tests/passwd.sh b/engine/tests/Functional.passwd/tests/passwd.sh new file mode 100644 index 0000000..5c10efa --- /dev/null +++ b/engine/tests/Functional.passwd/tests/passwd.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +# Add user test_for_fuego and change password for it. +# option: none + +test="pppoe-server" + +mv /etc/pam.d/common-password /etc/pam.d/common-password_bak +cp data/common-password /etc/pam.d/common-password + +create-cracklib-dict -o /usr/share/cracklib/pw_dict /usr/share/cracklib/cracklib-small + +sleep 1 + +useradd test_for_fuego + +sleep 1 + +expect <<-EOF +spawn passwd test_for_fuego + expect { + -re ".*password:.*" { + send_user " -> $test: passwd test_for_fuego executed.\n" + send "building\n" + exp_continue + } + -re "BAD PASSWORD.*Retype new password:.*" { + send_user " -> $test: retype passwd executed.\n" + send "building\n" + exp_continue + } + -re "passwd: password updated successfully" { + send_user " -> $test: TEST-PASS\n" + } + default { + send_user " -> $test: TEST-FAIL\n" + } +} +EOF + +userdel -r test_for_fuego + +rm -fr /home/test_for_fuego + +mv /etc/pam.d/common-password_bak /etc/pam.d/common-password -- 1.8.3.1