diff options
author | Yuri Pankov <yuripv@FreeBSD.org> | 2018-10-21 14:23:56 +0000 |
---|---|---|
committer | Yuri Pankov <yuripv@FreeBSD.org> | 2018-10-21 14:23:56 +0000 |
commit | 68d1891dcd9562dd914b16bfb34223c430b16b3f (patch) | |
tree | 07eafb5df450a00006db46ca1c247a1ebddf24ae | |
parent | ccc84708d81c35b2f56e57c1818bdebd12426d3c (diff) | |
download | pw-darwin-68d1891dcd9562dd914b16bfb34223c430b16b3f.tar.gz pw-darwin-68d1891dcd9562dd914b16bfb34223c430b16b3f.tar.zst pw-darwin-68d1891dcd9562dd914b16bfb34223c430b16b3f.zip |
pw: fix the checks in boolean_str() after r326738. Add related test
cases for `pw useradd -D -w`.
PR: 231649
Reviewed by: eugen
Approved by: kib (mentor)
Differential Revision: https://reviews.freebsd.org/D17299
-rw-r--r-- | pw/pw_conf.c | 12 | ||||
-rwxr-xr-x | pw/tests/pw_useradd_test.sh | 22 |
2 files changed, 29 insertions, 5 deletions
diff --git a/pw/pw_conf.c b/pw/pw_conf.c index 9dff3fe..c446a66 100644 --- a/pw/pw_conf.c +++ b/pw/pw_conf.c @@ -221,12 +221,14 @@ passwd_val(char const * str, int dflt) char const * boolean_str(int val) { - if (val == -1) - return "random"; - else if (val == -2) - return "none"; + if (val == P_NO) + return (boolfalse[0]); + else if (val == P_RANDOM) + return ("random"); + else if (val == P_NONE) + return ("none"); else - return val ? booltrue[0] : boolfalse[0]; + return (booltrue[0]); } char * diff --git a/pw/tests/pw_useradd_test.sh b/pw/tests/pw_useradd_test.sh index 3a88967..a50f018 100755 --- a/pw/tests/pw_useradd_test.sh +++ b/pw/tests/pw_useradd_test.sh @@ -421,6 +421,7 @@ user_add_with_pw_conf_body() atf_check -s exit:0 \ ${PW} useradd foo -C ${HOME}/pw.conf } + atf_test_case user_add_defaultgroup user_add_defaultgroup_body() { @@ -435,6 +436,25 @@ user_add_defaultgroup_body() ${PW} usershow foo } +atf_test_case user_add_conf_defaultpasswd +user_add_conf_defaultpasswd_body() +{ + populate_etc_skel + + atf_check -s exit:0 ${PW} useradd -D -w no + atf_check -o inline:"defaultpasswd = \"no\"\n" \ + grep defaultpasswd ${HOME}/pw.conf + atf_check -s exit:0 ${PW} useradd -D -w none + atf_check -o inline:"defaultpasswd = \"none\"\n" \ + grep defaultpasswd ${HOME}/pw.conf + atf_check -s exit:0 ${PW} useradd -D -w random + atf_check -o inline:"defaultpasswd = \"random\"\n" \ + grep defaultpasswd ${HOME}/pw.conf + atf_check -s exit:0 ${PW} useradd -D -w yes + atf_check -o inline:"defaultpasswd = \"yes\"\n" \ + grep defaultpasswd ${HOME}/pw.conf +} + atf_init_test_cases() { atf_add_test_case user_add atf_add_test_case user_add_noupdate @@ -472,4 +492,6 @@ atf_init_test_cases() { atf_add_test_case user_add_w_yes atf_add_test_case user_add_with_pw_conf atf_add_test_case user_add_defaultgroup + + atf_add_test_case user_add_conf_defaultpasswd } |