diff options
| author | Marc Horowitz <marc@mit.edu> | 1996-07-22 20:49:46 +0000 |
|---|---|---|
| committer | Marc Horowitz <marc@mit.edu> | 1996-07-22 20:49:46 +0000 |
| commit | edf8b4d8a6a665c2aa150993cd813ea6c5cf12e1 (patch) | |
| tree | 6c2974a97b448c040fa4a31708ec5e02f187526c /src/kadmin/passwd/unit-test | |
| parent | 013bb1391582ed9e653ae706e398ddb8d08cfcc9 (diff) | |
this commit includes all the changes on the OV_9510_INTEGRATION and
OV_MERGE branches. This includes, but is not limited to, the new openvision
admin system, and major changes to gssapi to add functionality, and bring
the implementation in line with rfc1964. before committing, the
code was built and tested for netbsd and solaris.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@8774 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/kadmin/passwd/unit-test')
| -rw-r--r-- | src/kadmin/passwd/unit-test/Makefile.ov | 23 | ||||
| -rw-r--r-- | src/kadmin/passwd/unit-test/config/unix.exp | 36 | ||||
| -rw-r--r-- | src/kadmin/passwd/unit-test/helpers.exp | 217 | ||||
| -rw-r--r-- | src/kadmin/passwd/unit-test/kpasswd.0/changing.exp | 102 | ||||
| -rw-r--r-- | src/kadmin/passwd/unit-test/kpasswd.0/connecting.exp | 29 | ||||
| -rw-r--r-- | src/kadmin/passwd/unit-test/kpasswd.0/principal.exp | 55 | ||||
| -rw-r--r-- | src/kadmin/passwd/unit-test/kpasswd.0/usage.exp | 26 |
7 files changed, 488 insertions, 0 deletions
diff --git a/src/kadmin/passwd/unit-test/Makefile.ov b/src/kadmin/passwd/unit-test/Makefile.ov new file mode 100644 index 000000000..db042720b --- /dev/null +++ b/src/kadmin/passwd/unit-test/Makefile.ov @@ -0,0 +1,23 @@ +# +# $Id$ +# + +TOP = ../.. +include $(TOP)/config.mk/template + +USER = root + +unit-test:: unit-test-setup unit-test-body unit-test-cleanup + +unit-test-body:: + $(RUNTEST) KPASSWD=../kpasswd \ + KINIT=$(TOP)/../clients/kinit/kinit \ + KDESTROY=$(TOP)/../clients/kdestroy/kdestroy \ + USER=$(USER) --tool kpasswd + +unit-test-setup:: + $(START_SERVERS) + echo "source $(TCLUTIL); catch {ovsec_kadm_init admin admin \$$OVSEC_KADM_ADMIN_SERVICE null \$$OVSEC_KADM_STRUCT_VERSION \$$OVSEC_KADM_API_VERSION_1 server_handle; ovsec_kadm_create_principal \$$server_handle [simple_principal $(USER)] {OVSEC_KADM_PRINCIPAL} $(USER); ovsec_kadm_destroy \$$server_handle;}; if {[info exists errorInfo]} { puts stderr \$$errorInfo; exit 1; }" | $(CLNTTCL) + +unit-test-cleanup:: + $(STOP_SERVERS) diff --git a/src/kadmin/passwd/unit-test/config/unix.exp b/src/kadmin/passwd/unit-test/config/unix.exp new file mode 100644 index 000000000..c77aa016a --- /dev/null +++ b/src/kadmin/passwd/unit-test/config/unix.exp @@ -0,0 +1,36 @@ +# +# kpasswd_version -- extract and print the version number of kpasswd +# + +proc kpasswd_version {} { + global KPASSWD + catch "exec ident $KPASSWD" tmp + if [regexp {Id: kpasswd.c,v ([0-9]+\.[0-9]+)} $tmp \ + dummy version] then { + clone_output "$KPASSWD version $version\n" + } else { + clone_output "$KPASSWD version <unknown>\n" + } +} +# +# kpasswd_load -- loads the program +# +proc kpasswd_load {} { + # +} + +# kpasswd_exit -- clean up and exit +proc kpasswd_exit {} { + # +} + +# +# kpasswd_start -- start kpasswd running +# +proc kpasswd_start { args } { + global KPASSWD + global spawn_id + + verbose "% $KPASSWD $args" 1 + eval spawn $KPASSWD $args +} diff --git a/src/kadmin/passwd/unit-test/helpers.exp b/src/kadmin/passwd/unit-test/helpers.exp new file mode 100644 index 000000000..9dcfbcf01 --- /dev/null +++ b/src/kadmin/passwd/unit-test/helpers.exp @@ -0,0 +1,217 @@ +# +# $Id$ +# + +global s +set s "\[\r\n\t\ \]" + +if {[info commands exp_version] != {}} { + set exp_version_4 [regexp {^4} [exp_version]] +} else { + set exp_version_4 [regexp {^4} [expect_version]] +} + +# Backward compatibility until we're using expect 5 everywhere +if {$exp_version_4} { + global wait_error_index wait_errno_index wait_status_index + set wait_error_index 0 + set wait_errno_index 1 + set wait_status_index 1 +} else { + set wait_error_index 2 + set wait_errno_index 3 + set wait_status_index 3 +} + +proc myfail { comment } { + global mytest_name + global mytest_status + wait + fail "$mytest_name: $comment" + set mytest_status 1 +} + +proc mypass {} { +} + +## +## When you expect on an id, and eof is detected, the spawn_id is closed. +## It may be waited for, but calling expect or close on this id is an ERROR! +## + +proc mytest { name kpargs status args } { + global spawn_id + global timeout + global mytest_name + global mytest_status + global wait_error_index wait_errno_index wait_status_index + + verbose "starting test: $name" + + set mytest_name "$name" + + eval kpasswd_start $kpargs + + # at the end, eof is success + + lappend args { eof { if {[regexp "\[\r\n\]$" $expect_out(buffer)] == 0} { myfail "final status message not newline-terminated" } } } + + # for each test argument.... + # rep invariant: when this foreach ends, the id is close'd, but + # not wait'ed. + + foreach test $args { + set mytest_status 0 + + # treat the arg as an expect parameter + # if failure, the process will be closed and waited. + + uplevel 1 "expect { + $test + timeout { close; myfail \"timeout\"} + eof { myfail \"eof read before expected message string\" } + }" + + if {$mytest_status == 1} { return } + } + + # at this point, the id is closed and we can wait on it. + + set ret [wait] + verbose "% Exit $ret" 1 + if {[lindex $ret $wait_error_index] == -1} { + fail "$name: wait returned error [lindex $ret $wait_errno_index]" + } else { + if { [lindex $ret $wait_status_index] == $status || + (($status<0) && ([lindex $ret $wait_status_index] == ($status+256))) } { + pass "$name" + } else { + fail "$name: unexpected return status [lindex $ret $wait_status_index], should be $status" + } + } +} + +proc kinit { princ pass } { + global env; + global KINIT + spawn -noecho $KINIT $princ; + + expect { + -re {Password for .*: $} + {send "$pass\n"} + timeout {puts "Timeout waiting for prompt" ; close } + } + + # this necessary so close(1) in the child will not sleep waiting for + # the parent, which is us, to read pending data. + + expect { + eof {} + } + wait +} + +proc kdestroy {} { + global KDESTROY + global errorCode errorInfo + global env + + if {[info exists errorCode]} { + set saveErrorCode $errorCode + } + if {[info exists errorInfo]} { + set saveErrorInfo $errorInfo + } + catch "system $KDESTROY 2>/dev/null" + if {[info exists saveErrorCode]} { + set errorCode $saveErrorCode + } elseif {[info exists errorCode]} { + unset errorCode + } + if {[info exists saveErrorInfo]} { + set errorInfo $saveErrorInfo + } elseif {[info exists errorInfo]} { + unset errorInfo + } +} + +global initerr_str +global initerr_regexp +set initerr_str "Cannot establish a session with the Kerberos administrative server for realm \[^\r\n\]*\\. " +set initerr_regexp "Cannot establish a session with the Kerberos administrative server for$s+realm \[^\r\n\]*\\.$s+" + +proc test_win { args name princ pass1 { pass2 "\001\001" } } { + global s + global initerr_regexp + + if { $pass2 == "\001\001" } { set pass2 "$pass1" } + + mytest "$name" $args 0 { + -re "Changing password for $princ.*\\.$s+Old password:" + { send "$pass1\n" } + } { + -re "Old Kerberos password is incorrect. Please try again." + { close; myfail "Old password incorrect" } + -re "${initerr_regexp}(.+\[^\r\n\t\ \])\r\n" + { close; myfail "init error: $expect_out(1,string)" } + -re "^$s+New password:" + { send "$pass2\n" } + -re "^$s+.*$s+.*$s+.*$s+New password:" + { send "$pass2\n" } + } { + -re "^$s+New password \\(again\\):" + { send "$pass2\n" } + } { + -re "^$s+Kerberos password changed." + { mypass } + -re "^$s+Password changed." + { close; myfail "Wrong message on success." } + } +} + +proc test_initerr { args name princ pass status err } { + global s + global initerr_regexp + + regsub -all "$s+" $err "$s+" err2 + + mytest "$name" $args $status { + -re "Changing password for $princ.*\\.$s+Old password:" + { send "$pass\n" } + } { + -re "$err2" + { mypass } + -re "Old Kerberos password is incorrect. Please try again." + { close; myfail "Old password incorrect" } + -re "${initerr_regexp}(.+)\r\n" + { close; myfail "init error: $expect_out(1,string)" } + } +} + +proc test_3pass { args name princ pass1 pass2 pass3 status err } { + global s + global initerr_regexp + + regsub -all "$s+" $err "$s+" err2 + + mytest "$name" $args $status { + -re "Changing password for $princ.*\\.$s+Old password:" + { send "$pass1\n" } + } { + -re "Old Kerberos password is incorrect. Please try again." + { close; myfail "Old password incorrect" } + -re "${initerr_regexp}(.+)\r\n" + { close; myfail "init error: $expect_out(1,string)" } + -re "^$s+New password:" + { send "$pass2\n" } + -re "^$s+.*$s+.*$s+.*$s+New password:" + { send "$pass2\n" } + } { + -re "^$s+New password \\(again\\):" + { send "$pass3\n" } + } { + -re "$s+$err2" + { mypass } + } +} + diff --git a/src/kadmin/passwd/unit-test/kpasswd.0/changing.exp b/src/kadmin/passwd/unit-test/kpasswd.0/changing.exp new file mode 100644 index 000000000..4f0354c63 --- /dev/null +++ b/src/kadmin/passwd/unit-test/kpasswd.0/changing.exp @@ -0,0 +1,102 @@ +# +# $Id$ +# + +set timeout 15 + +load_lib "helpers.exp" + +if [info exist env(DEBUG)] { debug 1 } + +# +# Here are the tests +# + +test_3pass {test2} {D.5: different new passwords} test2 test2 test2 foobar \ + 4 {New passwords do not match - password not changed.} + +test_3pass {test2} {D.7.5: empty/empty} test2 test2 {} {} \ + 5 {You must type a password. Passwords must be at least one character long.} + +test_3pass {test2} {D.6: empty/non-empty} test2 test2 {} test2 \ + 4 {New passwords do not match - password not changed.} + +test_3pass {test2} {D.7: non-empty/empty} test2 test2 test2 {} \ + 4 {New passwords do not match - password not changed.} + + +test_win {test1} {D.8: change password} test1 test1 newpass + +test_win {test1} {D.9: test changed password} test1 newpass test1 + +mytest "D.22: No policy description was shown" test1 4 { + -re "Changing password for test1.*\\.$s+Old password:" + { send "test1\n" } +} { + -re "$s+.*$s+.*$s+.*char.*classes.*" + { myfail "policy description displayed" } + timeout { mypass } +} { + -re "^$s+New password:" + { send "newpass\n" } +} { + -re "^$s+New password \\(again\\):" + { send "ssapwen\n" } +} { + -re "$s+New passwords do not match - password not changed." + { mypass } +} + +test_3pass {pol1} {D.10: new password too short} pol1 pol111111 que que \ + 4 {New password is too short. Please choose a password which is at least [0-9]+ characters long.} + +test_3pass {pol1} {D.13: too few char classes in new password} pol1 \ + pol111111 123456789 123456789 \ + 4 {New password does not have enough character classes. The character classes are: - lower-case letters, - upper-case letters, - digits, - punctuation, and - all other characters \(e.g., control characters\). Please choose a password with at least [0-9]+ character classes.} + +test_3pass {pol1} {D.14: new password in dictionary} pol1 \ + pol111111 Discordianism Discordianism \ + 4 {New password was found in a dictionary of possible passwords and therefore may be easily guessed. Please choose another password. See the ovpasswd man page for help in choosing a good password.} + +test_win {pol1} {successful change} pol1 pol111111 polAAAAAA +# fail "successful change: XXXX password history is majorly broken" + +test_3pass {pol1} {D.11: new password same as old} pol1 \ + polAAAAAA polAAAAAA polAAAAAA \ + 4 {New password was used previously. Please choose a different password.} + +test_3pass {pol1} {D.12: new password in history} pol1 \ + polAAAAAA pol111111 pol111111 \ + 4 {New password was used previously. Please choose a different password.} + +mytest "D.18: Policy description was shown" pol1 4 { + -re "Changing password for pol1.*\\.$s+Old password:" + { send "polAAAAAA\n" } +} { + -re "$s+.*$s+.*$s+.*8 char.*2 classes.*$s+New password:" + { send "newpass1234\n" } +} { + -re "^$s+New password \\(again\\):" + { send "newpass4321\n" } +} { + -re "$s+New passwords do not match - password not changed." + { mypass } +} + +# restore pol1's password to its initial value; see discussion in +# secure-kpasswd/2204 about secure-releng/2191 if you are confused +test_win {pol1} {successful change} pol1 polAAAAAA polBBBBBB +test_win {pol1} {successful change} pol1 polBBBBBB polCCCCCC +test_win {pol1} {successful change} pol1 polCCCCCC pol111111 + +test_win {pol2} {successful change} pol2 pol222222 polbbbbbb + +test_3pass {pol2} {D.15: too soon to change password} pol2 \ + polbbbbbb pol222222 pol222222 \ + 4 {Password cannot be changed because it was changed too recently. Please wait until .*199[0-9] before you change it. If you need to change your password before then, contact your system security administrator.} + +verbose "(sleeping 30 seconds)" +catch "exec sleep 30" + +test_win {pol2} {password min life passed} pol2 polbbbbbb pol222222 + diff --git a/src/kadmin/passwd/unit-test/kpasswd.0/connecting.exp b/src/kadmin/passwd/unit-test/kpasswd.0/connecting.exp new file mode 100644 index 000000000..2cda17a6a --- /dev/null +++ b/src/kadmin/passwd/unit-test/kpasswd.0/connecting.exp @@ -0,0 +1,29 @@ +# +# $Id$ +# + +set timeout 15 + +load_lib "helpers.exp" + +if [info exist env(DEBUG)] { debug 1 } + +# +# Here are the tests +# + +test_initerr {test2} {C.4: empty old password (XXXX)} test2 {} \ + 5 {You must type a password. Passwords must be at least one character long.} + +test_initerr {test2} {C.5: incorrect old password} test2 foobar \ + 2 "Old Kerberos password is incorrect. Please try again." + +# set timeout 60 +# +#test_initerr {test2@SECURE-TEST-DEAD.OV.COM} {C.8: server up, daemon down} \ +# test2 test2 \ +# 3 "" +# +#test_initerr {test2@SECURE-TEST-DOWN.OV.COM} {C.8.5: server down} \ +# test2 test2 \ +# 3 "${initerr_str}Cannot contact any KDC for requested realm" diff --git a/src/kadmin/passwd/unit-test/kpasswd.0/principal.exp b/src/kadmin/passwd/unit-test/kpasswd.0/principal.exp new file mode 100644 index 000000000..e2bc20569 --- /dev/null +++ b/src/kadmin/passwd/unit-test/kpasswd.0/principal.exp @@ -0,0 +1,55 @@ +# +# $Id$ +# + +set timeout 15 + +load_lib "helpers.exp" + +if [info exist env(DEBUG)] { debug 1 } + +# +# Here are the tests +# + +if {[info exists env(KRB5CCNAME)]} { + unset env(KRB5CCNAME) +} +kdestroy + +#### no principal specified + +set whoami $USER +test_win {} {B.7: default nonexisting ccache(1)} $whoami $whoami newpass +test_win {} {B.7: default nonexisting ccache(2)} $whoami newpass $whoami + +kinit test2 test2 +test_win {} {B.4: default existing cache containing existing principal} \ + test2 test2 newpass +kdestroy + +set env(KRB5CCNAME) FILE:/tmp/ovsec_adm_test_ccache +kinit test2 newpass +test_win {} {B.3: specified existing cache containing existing principal} \ + test2 newpass test2 +kdestroy +unset env(KRB5CCNAME) + +#### principal on command line + +# +test_win {test2} {B.14: existing principal, no realm} test2 test2 newpass + +# +test_initerr {bogus} {B.15, C.6: non-existent principal, no realm} bogus bogus \ + 3 "${initerr_str}Client not found in Kerberos database" + +# +test_win {test2@SECURE-TEST.OV.COM} {B.16: existing principal, with realm} \ + test2 newpass test2 + +# +test_initerr {bogus@SECURE-TEST.OV.COM} \ + {B.17: non-existent principal, with realm} \ + bogus bogus \ + 3 "${initerr_str}Client not found in Kerberos database" diff --git a/src/kadmin/passwd/unit-test/kpasswd.0/usage.exp b/src/kadmin/passwd/unit-test/kpasswd.0/usage.exp new file mode 100644 index 000000000..e132bab2f --- /dev/null +++ b/src/kadmin/passwd/unit-test/kpasswd.0/usage.exp @@ -0,0 +1,26 @@ +# +# $Id$ +# + +set timeout 15 + +load_lib "helpers.exp" + +# +# Here are the tests +# + +mytest {A.1: two args} {foo bar} 7 { + -re {[a-z./]+passwd: Usage: [a-z./]+passwd \[principal_name\]} { mypass } +} + +mytest {A.2: three args} {foo bar baz} 7 { + -re {[a-z./]+passwd: Usage: [a-z./]+passwd \[principal_name\]} { mypass } +} + +set env(KRB5CCNAME) bogus_type:bogus_ccname +mytest {B.5: malformed ccache name} {} 6 { + -re {[a-z./]+passwd: Unknown credential cache type while reading principal name from credential cache} { mypass } +} +unset env(KRB5CCNAME) + |
