do database expansion from tcl driver code
authorKen Raeburn <raeburn@mit.edu>
Wed, 9 Jan 2002 02:23:35 +0000 (02:23 +0000)
committerKen Raeburn <raeburn@mit.edu>
Wed, 9 Jan 2002 02:23:35 +0000 (02:23 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14097 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/rpc/unit-test/ChangeLog
src/lib/rpc/unit-test/Makefile.in
src/lib/rpc/unit-test/lib/helpers.exp

index 9b25f22f0fb4be67dc4662c005b49833d8a83621..8463dd8f3ccc303a8497c63768dd0727ca299ee6 100644 (file)
@@ -1,3 +1,11 @@
+2002-01-08  Ken Raeburn  <raeburn@mit.edu>
+
+       * lib/helpers.exp (set_from_env, expect_tcl_prompt,
+       send_tcl_cmd_await_echo, expect_kadm_ok, setup_database): New
+       procs.
+       (top level): Do database setup here...
+       * Makefile.in (unit-test-setup): ...not here.
+
 2001-07-26  Ezra Peisach  <epeisach@mit.edu>
 
        * client.c: Change local variable count from int to unsigned int.
index df937cd1b26c69bb43f6e939b3c6a40088f89879..148c3e20edd60d8b76f8bab5389db50845ebcd7b 100644 (file)
@@ -54,7 +54,7 @@ unit-test-body:
 
 unit-test-setup::
        $(ENV_SETUP) $(START_SERVERS)
-       RPC_TEST_SRVTAB=/tmp/rpc_test_v5srvtab $(ENV_SETUP) $(srcdir)/rpc_test_setup.sh
+#      RPC_TEST_SRVTAB=/tmp/rpc_test_v5srvtab $(ENV_SETUP) $(srcdir)/rpc_test_setup.sh
 
 unit-test-cleanup::
        $(ENV_SETUP) $(STOP_SERVERS)
index c4b76aa0ce2fb36188e1bf35a408098688a34dba..66b4d3054087bf8a23676b6e8b42b9819a68de9e 100644 (file)
@@ -16,6 +16,106 @@ if {$exp_version_4} {
        set wait_status_index 3
 }
                                
+proc set_from_env {varname default_value} {
+    global env
+    upvar $varname v
+
+    if [info exists env($varname)] {
+       set v $env($varname)
+    } else {
+       set v $default_value
+    }
+}
+proc expect_tcl_prompt {} {
+    global kadmin_tcl_spawn_id
+    expect {
+       -i $kadmin_tcl_spawn_id
+       "^% " { }
+       -re . { error "unexpected output {$expect_out(buffer)} from subprocess, expecting tcl prompt" }
+       timeout { perror "timeout waiting for tcl prompt" }
+       eof { perror "eof from subprocess when expecting tcl prompt" }
+    }
+}
+proc send_tcl_cmd_await_echo {cmd} {
+    global kadmin_tcl_spawn_id
+    send -i $kadmin_tcl_spawn_id "$cmd\n"
+    expect {
+       -i $kadmin_tcl_spawn_id
+       -ex "$cmd\r\n" { }
+       timeout { perror "timeout waiting for tcl subprocess to echo input" }
+       eof { perror "eof waiting for tcl subprocess to echo input" }
+    }
+}
+proc expect_kadm_ok {} {
+    global kadmin_tcl_spawn_id
+    expect {
+       -i $kadmin_tcl_spawn_id
+       -re "^OK OVSEC_KADM_OK \[^\n\]*\n" {}
+       default { error "didn't get ok back" }
+    }
+}
+# trying to translate rpc_test_setup.sh into inline tcl...
+proc setup_database {} {
+    global env spawn_id kadmin_tcl_spawn_id TESTDIR MAKE_KEYTAB CANON_HOST
+
+    # XXXXX
+    set_from_env TOP {/x/x/x/x/x}
+    send_user "TOP=$TOP\n"
+
+    set_from_env TESTDIR $env(TOP)/testing
+    set_from_env CLNTTCL $TESTDIR/util/ovsec_kadm_clnt_tcl
+    set_from_env TCLUTIL $TESTDIR/tcl/util.t
+    set env(TCLUTIL) $TCLUTIL
+    set_from_env MAKE_KEYTAB $TESTDIR/scripts/make-host-keytab.pl
+    set env(PATH) "$TOP/install/admin:$env(PATH)"
+
+    # $VERBOSE ?
+
+    if [info exists spawn_id] { set x $spawn_id }
+    spawn $CLNTTCL
+    set kadmin_tcl_spawn_id $spawn_id
+    if [info exists x] { set spawn_id $x }
+
+    expect_tcl_prompt
+    send_tcl_cmd_await_echo "source {$TCLUTIL}"
+    expect_tcl_prompt
+    send_tcl_cmd_await_echo "set h {$CANON_HOST}"
+    expect {
+       -ex "$CANON_HOST\r\n" { }
+       timeout { perror "timeout waiting for subprocess" }
+       eof { perror "eof from subprocess" }
+    }
+    expect_tcl_prompt
+
+    send_tcl_cmd_await_echo {ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null $OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 server_handle}
+    expect_kadm_ok
+    expect "^% "
+    send_tcl_cmd_await_echo {ovsec_kadm_create_principal $server_handle [simple_principal server/$h] {OVSEC_KADM_PRINCIPAL} admin}
+    expect_kadm_ok
+    expect "^% "
+    send_tcl_cmd_await_echo {ovsec_kadm_randkey_principal $server_handle server/$h key}
+    expect_kadm_ok
+    expect "^% "
+    send_tcl_cmd_await_echo {ovsec_kadm_create_principal $server_handle [simple_principal notserver/$h] {OVSEC_KADM_PRINCIPAL} admin}
+    expect_kadm_ok
+    expect "^% "
+    send_tcl_cmd_await_echo {ovsec_kadm_randkey_principal $server_handle notserver/$h key}
+    expect_kadm_ok
+    expect "^% "
+    send_tcl_cmd_await_echo {ovsec_kadm_destroy $server_handle}
+    expect_kadm_ok
+    expect "^% "
+    wait -nowait -i $spawn_id
+    close -i $spawn_id
+}
+
+if ![info exists CANON_HOST] {
+    set CANON_HOST [exec $env(QUALNAME)]
+    setup_database
+    file delete $env(RPC_TEST_SRVTAB)
+    exec $env(MAKE_KEYTAB) -princ "server/$CANON_HOST" $env(RPC_TEST_SRVTAB)
+}
+
 
 proc kinit {princ pass lifetime} {
        global kinit