From ccae41df0071b6460c876e1bf770ed40683c3bba Mon Sep 17 00:00:00 2001 From: Barry Jaspan Date: Mon, 23 Sep 1996 20:34:32 +0000 Subject: [PATCH] * changes to use runtest --srcdir: - Makefile.in: rewrote [csapi].* links to work in srcdir (boo, hiss) - move lib.t to lib/lib.t - api.*/*.exp: s/source lib.t/load_lib lib.t/ git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@9108 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kadm5/unit-test/ChangeLog | 8 + src/lib/kadm5/unit-test/Makefile.in | 47 ++- .../unit-test/api.0/chpass-principal.exp | 2 +- src/lib/kadm5/unit-test/api.0/crte-policy.exp | 2 +- .../kadm5/unit-test/api.0/crte-principal.exp | 2 +- src/lib/kadm5/unit-test/api.0/destroy.exp | 2 +- src/lib/kadm5/unit-test/api.0/dlte-policy.exp | 2 +- .../kadm5/unit-test/api.0/dlte-principal.exp | 2 +- src/lib/kadm5/unit-test/api.0/get-policy.exp | 2 +- .../kadm5/unit-test/api.0/get-principal.exp | 2 +- src/lib/kadm5/unit-test/api.0/init.exp | 2 +- src/lib/kadm5/unit-test/api.0/mod-policy.exp | 2 +- .../kadm5/unit-test/api.0/mod-principal.exp | 2 +- .../unit-test/api.0/randkey-principal.exp | 2 +- .../unit-test/api.0/rename-principal.exp | 2 +- src/lib/kadm5/unit-test/api.1/lock.exp | 2 +- .../unit-test/api.2/chpass-principal-v2.exp | 2 +- .../unit-test/api.2/chpass-principal.exp | 2 +- src/lib/kadm5/unit-test/api.2/crte-policy.exp | 2 +- .../kadm5/unit-test/api.2/crte-principal.exp | 2 +- src/lib/kadm5/unit-test/api.2/destroy.exp | 2 +- src/lib/kadm5/unit-test/api.2/dlte-policy.exp | 2 +- .../kadm5/unit-test/api.2/dlte-principal.exp | 2 +- src/lib/kadm5/unit-test/api.2/get-policy.exp | 2 +- .../unit-test/api.2/get-principal-v2.exp | 2 +- .../kadm5/unit-test/api.2/get-principal.exp | 2 +- src/lib/kadm5/unit-test/api.2/init-v2.exp | 2 +- src/lib/kadm5/unit-test/api.2/init.exp | 2 +- src/lib/kadm5/unit-test/api.2/mod-policy.exp | 2 +- .../kadm5/unit-test/api.2/mod-principal.exp | 2 +- .../unit-test/api.2/randkey-principal-v2.exp | 2 +- .../unit-test/api.2/randkey-principal.exp | 2 +- src/lib/kadm5/unit-test/config/unix.exp | 1 + src/lib/kadm5/unit-test/lib/lib.t | 367 ++++++++++++++++++ 34 files changed, 436 insertions(+), 47 deletions(-) create mode 100644 src/lib/kadm5/unit-test/lib/lib.t diff --git a/src/lib/kadm5/unit-test/ChangeLog b/src/lib/kadm5/unit-test/ChangeLog index 1e58383c1..1f8057854 100644 --- a/src/lib/kadm5/unit-test/ChangeLog +++ b/src/lib/kadm5/unit-test/ChangeLog @@ -1,3 +1,11 @@ +Mon Sep 23 16:31:24 1996 Barry Jaspan + + * changes to use runtest --srcdir: + - Makefile.in: rewrote [csapi].* links to work in srcdir (boo, + hiss) + - move lib.t to lib/lib.t + - api.*/*.exp: s/source lib.t/load_lib lib.t/ + Fri Sep 20 16:51:26 1996 Barry Jaspan * created Makefile.in and configure.in diff --git a/src/lib/kadm5/unit-test/Makefile.in b/src/lib/kadm5/unit-test/Makefile.in index 3544beea7..915c70ebe 100644 --- a/src/lib/kadm5/unit-test/Makefile.in +++ b/src/lib/kadm5/unit-test/Makefile.in @@ -87,28 +87,41 @@ unit-test-server-setup:: unit-test-server-cleanup:: $(ENV_SETUP) $(STOP_SERVERS_LOCAL) -capi.0: api.0 - -rm -f capi.0 - ln -s api.0 capi.0 - -capi.2: api.2 - -rm -f capi.2 - ln -s api.2 capi.2 - unit-test-client-body: capi.0 capi.2 site.exp test-noauth test-destroy test-handle-client test-sizes $(ENV_SETUP) $(RUNTEST) --tool capi API=$(CLNTTCL) KINIT=$(BUILDTOP)/clients/kinit/kinit KDESTROY=$(BUILDTOP)/clients/kdestroy/kdestroy KADMIN_LOCAL=$(BUILDTOP)/kadmin/cli/kadmin.local RPC=1 -sapi.0: api.0 - -rm -f sapi.0 - ln -s api.0 sapi.0 +# +# This is unfortunate. We want to have a single set of directories +# api.* but treat them as two separate tools (capi and sapi). We +# specify --srcdir in $(RUNTEST) so that unit tests files do not need +# to exist as symlinks in the source tree. However, we can't check in +# the capi and sapi symlinks into CVS. Therefore, we need to create +# them *in the source tree* at run time. +# +# Another alternative would be to run $(RUNTEST) without --srcdir in +# this one directory, or just stop using a separate tool name for +# client and server tests; that would prevent us from keeping the +# separate log files around, and might bite us in the future. +# +capi.0: $(srcdir)/api.0 + -rm -f $(srcdir)/capi.0 + ln -s $(srcdir)/api.0 $(srcdir)/capi.0 + +capi.2: $(srcdir)/api.2 + -rm -f $(srcdir)/capi.2 + ln -s $(srcdir)/api.2 $(srcdir)/capi.2 + +sapi.0: $(srcdir)/api.0 + -rm -f $(srcdir)/sapi.0 + ln -s $(srcdir)/api.0 $(srcdir)/sapi.0 -sapi.1: api.1 - -rm -f sapi.1 - ln -s api.1 sapi.1 +sapi.1: $(srcdir)/api.1 + -rm -f $(srcdir)/sapi.1 + ln -s $(srcdir)/api.1 $(srcdir)/sapi.1 -sapi.2: api.2 - -rm -f sapi.2 - ln -s api.2 sapi.2 +sapi.2: $(srcdir)/api.2 + -rm -f $(srcdir)/sapi.2 + ln -s $(srcdir)/api.2 $(srcdir)/sapi.2 unit-test-server-body: sapi.0 sapi.1 sapi.2 site.exp randkey-test test-handle-server lock-test test-sizes $(ENV_SETUP) $(RUNTEST) --tool sapi API=$(SRVTCL) LOCKTEST=./lock-test KADMIN_LOCAL=$(BUILDTOP)/kadmin/cli/kadmin.local RPC=0 diff --git a/src/lib/kadm5/unit-test/api.0/chpass-principal.exp b/src/lib/kadm5/unit-test/api.0/chpass-principal.exp index 12fa3b9d1..6e69e5700 100644 --- a/src/lib/kadm5/unit-test/api.0/chpass-principal.exp +++ b/src/lib/kadm5/unit-test/api.0/chpass-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/crte-policy.exp b/src/lib/kadm5/unit-test/api.0/crte-policy.exp index dbf4f1cbc..685631b06 100644 --- a/src/lib/kadm5/unit-test/api.0/crte-policy.exp +++ b/src/lib/kadm5/unit-test/api.0/crte-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/crte-principal.exp b/src/lib/kadm5/unit-test/api.0/crte-principal.exp index 12c300793..7e2c65d03 100644 --- a/src/lib/kadm5/unit-test/api.0/crte-principal.exp +++ b/src/lib/kadm5/unit-test/api.0/crte-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/destroy.exp b/src/lib/kadm5/unit-test/api.0/destroy.exp index 31b844786..a8572518d 100644 --- a/src/lib/kadm5/unit-test/api.0/destroy.exp +++ b/src/lib/kadm5/unit-test/api.0/destroy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/dlte-policy.exp b/src/lib/kadm5/unit-test/api.0/dlte-policy.exp index 7f349b02c..28ab827d3 100644 --- a/src/lib/kadm5/unit-test/api.0/dlte-policy.exp +++ b/src/lib/kadm5/unit-test/api.0/dlte-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/dlte-principal.exp b/src/lib/kadm5/unit-test/api.0/dlte-principal.exp index bb52301df..255252eac 100644 --- a/src/lib/kadm5/unit-test/api.0/dlte-principal.exp +++ b/src/lib/kadm5/unit-test/api.0/dlte-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/get-policy.exp b/src/lib/kadm5/unit-test/api.0/get-policy.exp index 329e7886a..813bf3899 100644 --- a/src/lib/kadm5/unit-test/api.0/get-policy.exp +++ b/src/lib/kadm5/unit-test/api.0/get-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/get-principal.exp b/src/lib/kadm5/unit-test/api.0/get-principal.exp index 05937055e..83c86b3fd 100644 --- a/src/lib/kadm5/unit-test/api.0/get-principal.exp +++ b/src/lib/kadm5/unit-test/api.0/get-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/init.exp b/src/lib/kadm5/unit-test/api.0/init.exp index 03b9284fd..08fed8b18 100644 --- a/src/lib/kadm5/unit-test/api.0/init.exp +++ b/src/lib/kadm5/unit-test/api.0/init.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t # Assumptions: # diff --git a/src/lib/kadm5/unit-test/api.0/mod-policy.exp b/src/lib/kadm5/unit-test/api.0/mod-policy.exp index 67f8457b6..c0dd93e64 100644 --- a/src/lib/kadm5/unit-test/api.0/mod-policy.exp +++ b/src/lib/kadm5/unit-test/api.0/mod-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/mod-principal.exp b/src/lib/kadm5/unit-test/api.0/mod-principal.exp index c4bc2bed1..0577e5800 100644 --- a/src/lib/kadm5/unit-test/api.0/mod-principal.exp +++ b/src/lib/kadm5/unit-test/api.0/mod-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/randkey-principal.exp b/src/lib/kadm5/unit-test/api.0/randkey-principal.exp index 259cd8f03..1a10ad578 100644 --- a/src/lib/kadm5/unit-test/api.0/randkey-principal.exp +++ b/src/lib/kadm5/unit-test/api.0/randkey-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.0/rename-principal.exp b/src/lib/kadm5/unit-test/api.0/rename-principal.exp index 56e412955..c318249af 100644 --- a/src/lib/kadm5/unit-test/api.0/rename-principal.exp +++ b/src/lib/kadm5/unit-test/api.0/rename-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.1/lock.exp b/src/lib/kadm5/unit-test/api.1/lock.exp index 504a110ad..d6d3faf4d 100644 --- a/src/lib/kadm5/unit-test/api.1/lock.exp +++ b/src/lib/kadm5/unit-test/api.1/lock.exp @@ -3,7 +3,7 @@ # (whichs runs through all api tests) will still have it locked, and # these tests will fail. -source lib.t +load_lib lib.t api_exit diff --git a/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp b/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp index 88aed8bca..40a78c985 100644 --- a/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp +++ b/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/chpass-principal.exp b/src/lib/kadm5/unit-test/api.2/chpass-principal.exp index 3efdfa9b9..c4ac30f6b 100644 --- a/src/lib/kadm5/unit-test/api.2/chpass-principal.exp +++ b/src/lib/kadm5/unit-test/api.2/chpass-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/crte-policy.exp b/src/lib/kadm5/unit-test/api.2/crte-policy.exp index b0ea04630..273af3fa6 100644 --- a/src/lib/kadm5/unit-test/api.2/crte-policy.exp +++ b/src/lib/kadm5/unit-test/api.2/crte-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/crte-principal.exp b/src/lib/kadm5/unit-test/api.2/crte-principal.exp index 653d1222a..e4731f828 100644 --- a/src/lib/kadm5/unit-test/api.2/crte-principal.exp +++ b/src/lib/kadm5/unit-test/api.2/crte-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/destroy.exp b/src/lib/kadm5/unit-test/api.2/destroy.exp index 808f0b401..5de40ef03 100644 --- a/src/lib/kadm5/unit-test/api.2/destroy.exp +++ b/src/lib/kadm5/unit-test/api.2/destroy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/dlte-policy.exp b/src/lib/kadm5/unit-test/api.2/dlte-policy.exp index 95a57dc20..8fdea0b04 100644 --- a/src/lib/kadm5/unit-test/api.2/dlte-policy.exp +++ b/src/lib/kadm5/unit-test/api.2/dlte-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/dlte-principal.exp b/src/lib/kadm5/unit-test/api.2/dlte-principal.exp index fe157e880..43a4238a4 100644 --- a/src/lib/kadm5/unit-test/api.2/dlte-principal.exp +++ b/src/lib/kadm5/unit-test/api.2/dlte-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/get-policy.exp b/src/lib/kadm5/unit-test/api.2/get-policy.exp index ff41c17b9..5afece9dc 100644 --- a/src/lib/kadm5/unit-test/api.2/get-policy.exp +++ b/src/lib/kadm5/unit-test/api.2/get-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp b/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp index 486d1a6ab..191a2f3df 100644 --- a/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp +++ b/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/get-principal.exp b/src/lib/kadm5/unit-test/api.2/get-principal.exp index 4f91b33bb..6d3391002 100644 --- a/src/lib/kadm5/unit-test/api.2/get-principal.exp +++ b/src/lib/kadm5/unit-test/api.2/get-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/init-v2.exp b/src/lib/kadm5/unit-test/api.2/init-v2.exp index 61736b80f..140ff86e8 100644 --- a/src/lib/kadm5/unit-test/api.2/init-v2.exp +++ b/src/lib/kadm5/unit-test/api.2/init-v2.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/init.exp b/src/lib/kadm5/unit-test/api.2/init.exp index ef9573c67..9707d3bf3 100644 --- a/src/lib/kadm5/unit-test/api.2/init.exp +++ b/src/lib/kadm5/unit-test/api.2/init.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t # Assumptions: # diff --git a/src/lib/kadm5/unit-test/api.2/mod-policy.exp b/src/lib/kadm5/unit-test/api.2/mod-policy.exp index 07e2e62db..4ca0e3e85 100644 --- a/src/lib/kadm5/unit-test/api.2/mod-policy.exp +++ b/src/lib/kadm5/unit-test/api.2/mod-policy.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/mod-principal.exp b/src/lib/kadm5/unit-test/api.2/mod-principal.exp index 5e24e08b0..d7713909d 100644 --- a/src/lib/kadm5/unit-test/api.2/mod-principal.exp +++ b/src/lib/kadm5/unit-test/api.2/mod-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp b/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp index c3dfd18df..5c8fdc5e5 100644 --- a/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp +++ b/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/api.2/randkey-principal.exp b/src/lib/kadm5/unit-test/api.2/randkey-principal.exp index d693a2ac1..fb11c4801 100644 --- a/src/lib/kadm5/unit-test/api.2/randkey-principal.exp +++ b/src/lib/kadm5/unit-test/api.2/randkey-principal.exp @@ -1,4 +1,4 @@ -source lib.t +load_lib lib.t api_exit api_start diff --git a/src/lib/kadm5/unit-test/config/unix.exp b/src/lib/kadm5/unit-test/config/unix.exp index 7b8e2ea4f..ed576ce35 100644 --- a/src/lib/kadm5/unit-test/config/unix.exp +++ b/src/lib/kadm5/unit-test/config/unix.exp @@ -1,3 +1,4 @@ +set prompt "% " set stty_init {-onlcr -opost intr \^C kill \^U} set kadmin_local $KADMIN_LOCAL diff --git a/src/lib/kadm5/unit-test/lib/lib.t b/src/lib/kadm5/unit-test/lib/lib.t new file mode 100644 index 000000000..110514de8 --- /dev/null +++ b/src/lib/kadm5/unit-test/lib/lib.t @@ -0,0 +1,367 @@ +global timeout +set timeout 60 + +proc cmd {command} { + global prompt + global spawn_id + global test + + send "[string trim $command]\n" + expect { + -re "OK .*$prompt$" { return 1 } + -re "ERROR .*$prompt$" { return 0 } + "wrong # args" { error "$test: wrong number args"; return 0 } + timeout { fail "$test: timeout"; return 0 } + eof { fail "$test: eof"; api_exit; api_start; return 0 } + } +} + +proc tcl_cmd {command} { + global prompt + global spawn_id + + send "[string trim $command]\n" + expect { + -re "$prompt$" { return 1} + "wrong # args" { error "$test: wrong number args"; return 0 } + timeout { error_and_restart "timeout" } + eof { api_exit; api_start; return 0 } + } +} + +proc one_line_succeed_test {command} { + global prompt + global spawn_id + global test + + send "[string trim $command]\n" + expect { + -re "OK .*$prompt$" { pass "$test"; return 1 } + -re "ERROR .*$prompt$" { + fail "$test: $expect_out(buffer)"; return 0 + } + "wrong # args" { error "$test: wrong number args"; return 0 } + timeout { fail "$test: timeout"; return 0 } + eof { fail "$test: eof"; api_exit; api_start; return 0 } + } +} + +proc one_line_fail_test {command code} { + global prompt + global spawn_id + global test + + send "[string trim $command]\n" + expect { + -re "ERROR .*$code.*$prompt$" { pass "$test"; return 1 } + -re "ERROR .*$prompt$" { fail "$test: bad failure"; return 0 } + -re "OK .*$prompt$" { fail "$test: bad success"; return 0 } + "wrong # args" { error "$test: wrong number args"; return 0 } + timeout { fail "$test: timeout"; return 0 } + eof { fail "$test: eof"; api_exit; api_start; return 0 } + } +} + +proc one_line_fail_test_nochk {command} { + global prompt + global spawn_id + global test + + send "[string trim $command]\n" + expect { + -re "ERROR .*$prompt$" { pass "$test:"; return 1 } + -re "OK .*$prompt$" { fail "$test: bad success"; return 0 } + "wrong # args" { error "$test: wrong number args"; return 0 } + timeout { fail "$test: timeout"; return 0 } + eof { fail "$test: eof"; api_exit; api_start; return 0 } + } +} + +proc resync {} { + global prompt + global spawn_id + + expect { + -re "$prompt$" {} + "wrong # args" { error "$test: wrong number args"; return 0 } + eof { api_exit; api_start } + } +} + +proc create_principal {name} { + api_exit + api_start + + set ret [expr { + [cmd { + ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \ + $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \ + server_handle + }] && + [cmd [format { + ovsec_kadm_create_principal $server_handle [simple_principal \ + "%s"] {OVSEC_KADM_PRINCIPAL} "%s" + } $name $name]] + }] + + cmd {ovsec_kadm_destroy $server_handle} + + api_exit + api_start + + return $ret +} + +proc create_policy {name} { + api_exit + api_start + + set ret [expr { + [cmd { + ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \ + $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \ + server_handle + }] && + [cmd [format { + ovsec_kadm_create_policy $server_handle [simple_policy "%s"] \ + {OVSEC_KADM_POLICY} + } $name $name]] + }] + + cmd {ovsec_kadm_destroy $server_handle} + + api_exit + api_start + + return $ret +} + +proc create_principal_pol {name policy} { + api_exit + api_start + + set ret [expr { + [cmd { + ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \ + $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \ + server_handle + }] && + [cmd [format { + ovsec_kadm_create_principal $server_handle [princ_w_pol "%s" \ + "%s"] {OVSEC_KADM_PRINCIPAL OVSEC_KADM_POLICY} "%s" + } $name $policy $name]] + }] + + cmd {ovsec_kadm_destroy $server_handle} + + api_exit + api_start + + return $ret +} + +proc delete_principal {name} { + api_exit + api_start + + set ret [expr { + [cmd { + ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \ + $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \ + server_handle + }] && + [cmd [format { + ovsec_kadm_delete_principal $server_handle "%s" + } $name]] + }] + + cmd {ovsec_kadm_destroy $server_handle} + + api_exit + api_start + + return $ret +} + +proc delete_policy {name} { + api_exit + api_start + + set ret [expr { + [cmd { + ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \ + $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \ + server_handle + }] && + [cmd [format {ovsec_kadm_delete_policy $server_handle "%s"} $name]] + }] + + cmd {ovsec_kadm_destroy $server_handle} + + api_exit + api_start + + return $ret +} + +proc principal_exists {name} { + api_exit + api_start + +# puts stdout "Starting principal_exists." + + set ret [expr { + [cmd { + ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \ + $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \ + server_handle + }] && + [cmd [format { + ovsec_kadm_get_principal $server_handle "%s" principal + } $name]] + }] + + cmd {ovsec_kadm_destroy $server_handle} + + api_exit + api_start + +# puts stdout "Finishing principal_exists." + + return $ret +} + +proc policy_exists {name} { + api_exit + api_start + +# puts stdout "Starting policy_exists." + + set ret [expr { + [cmd { + ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \ + $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \ + server_handle + }] && + [cmd [format { + ovsec_kadm_get_policy $server_handle "%s" policy + } $name]] + }] + + cmd {ovsec_kadm_destroy $server_handle} + + api_exit + api_start + +# puts stdout "Finishing policy_exists." + + return $ret +} + +proc error_and_restart {error} { + api_exit + api_start + error $error +} + +proc test {name} { + global test verbose + + set test $name + if {$verbose >= 1} { + puts stdout "At $test" + } +} + +proc begin_dump {} { + global TOP + global RPC + + if { ! $RPC } { +# exec $env(SIMPLE_DUMP) > /tmp/dump.before + } +} + +proc end_dump_compare {name} { + global file + global TOP + global RPC + + if { ! $RPC } { +# set file $TOP/admin/lib/unit-test/diff-files/$name +# exec $env(SIMPLE_DUMP) > /tmp/dump.after +# exec $env(COMPARE_DUMP) /tmp/dump.before /tmp/dump.after $file + } +} + +proc kinit { princ pass {opts ""} } { + global env; + global KINIT + + eval spawn $KINIT $opts $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 + } +} + +proc create_principal_with_keysalts {name keysalts} { + global kadmin_local + + spawn $kadmin_local -e "$keysalts" + expect { + "kadmin.local:" {} + default { error "waiting for kadmin.local prompt"; return 1} + } + send "ank -pw \"$name\" \"$name\"\n" + expect { + -re "Principal \"$name.*\" created." {} + "kadmin.local:" { + error "expecting principal created message"; + return 1 + } + default { error "waiting for principal created message"; return 1 } + } + expect { + "kadmin.local:" {} + default { error "waiting for kadmin.local prompt"; return 1 } + } + close + wait + return 0 +} + + -- 2.26.2