load_lib lib.t
api_exit
api_start

# Description: (1) Fails for mask with undefined bit set.
# 01/24/94: pshuang: untried.
test "create-policy 1"
proc test1 {} {
    global test
    if {! (( ! [policy_exists "$test/a"]) ||
           [delete_policy "$test/a"])} {
            error_and_restart "$test: couldn't delete policy \"$test/a\""
            return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		0xF01000
    } $test] "BAD_MASK"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
        error "$test: unexpected failure in destroy"
        return
    }
}
test1

# Description: (2) Fails if caller connected with CHANGEPW_SERVICE.
test "create-policy 2"
proc test2 {} {
    global test
    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_CHANGEPW_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy";
	return
    }
}
if {$RPC} { test2 }

# Description: (3) Fails for mask without POLICY bit set.
# 01/24/94: pshuang: untried.
test "create-policy 3"
proc test3 {} {
    global test
    if {! (( ! [policy_exists "$test/a"]) ||
           [delete_policy "$test/a"])} {
            error_and_restart "$test: couldn't delete policy \"$test/a\""
            return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		0x000000
    } $test] "BAD_MASK"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
        error "$test: unexpected failure in destroy"
        return
    }
}
test3

# Description: (4) Fails for mask with REF_COUNT bit set.
test "create-policy 4"
proc test4 {} {
    global test
    
    if {! (( ! [policy_exists "$test/a"]) ||
           [delete_policy "$test/a"])} {
            error_and_restart "$test: couldn't delete policy \"$test/a\""
            return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY OVSEC_KADM_REF_COUNT}
    } $test] "BAD_MASK"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
        error "$test: unexpected failure in destroy"
        return
    }
}
test4

# Description: (5) Fails for invalid policy name.
# 01/24/94: pshuang: untried.
test "create-policy 5"
proc test5 {} {
    global test
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/"] \
		{OVSEC_KADM_POLICY}
    } $test] "BAD_POLICY"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
        error "$test: unexpected failure in destroy"
        return
    }
}
test5

# Description: (6) Fails for existing policy name.
test "create-policy 6"
proc test6 {} {
    global test
#    set prms_id 777
#    setup_xfail {*-*-*} $prms_id

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test {
	ovsec_kadm_create_policy $server_handle [simple_policy test-pol] \
		{OVSEC_KADM_POLICY}
    } "DUP"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test6

# Description: (7) Fails for null policy name.
# 01/24/94: pshuang: untried.
test "create-policy 7"
proc test7 {} {
    global test
#    set prms_id 1977
#    setup_xfail {*-*-*} $prms_id
    
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test {
	ovsec_kadm_create_policy $server_handle [simple_policy null] \
		{OVSEC_KADM_POLICY}
    } "EINVAL"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
        error "$test: unexpected failure in destroy"
        return
    }
}
test7

# Description: (8) Fails for empty-string policy name.
test "create-policy 8"
proc test8 {} {
    global test

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test {
	ovsec_kadm_create_policy $server_handle [simple_policy ""] \
		{OVSEC_KADM_POLICY}
    } "BAD_POLICY"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test8

# Description: (9) Accepts 0 for pw_min_life.
test "create-policy 9"
proc test9 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if { ! [cmd [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_LIFE}
    } $test]]} {
	fail "$test: create failed"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 1\n"
    expect {
	-re "0\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test9

# Description: (10) Accepts non-zero for pw_min_life.
test "create-policy 10"
proc test10 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if { ! [cmd [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 32 0 0 0 0 0 } \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_LIFE}
    } $test]]} {
	fail "$test"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retreuve policy"
	return
    }
    send "lindex \$policy 1\n"
    expect {
	-re "32\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test10

# Description: (11) Accepts 0 for pw_max_life.
test "create-policy 11"
proc test11 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MAX_LIFE}
    } $test]]} {
	fail "$test"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retreuve policy"
	return
    }
    send "lindex \$policy 2\n"
    expect {
	-re "0\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test11

# Description: (12) Accepts non-zero for pw_max_life.
test "create-policy 12"
proc test12 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 32 0 0 0 0 } \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MAX_LIFE}
    } $test]]} {
	fail "$test"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retreuve policy"
	return
    }
    send "lindex \$policy 2\n"
    expect {
	-re "32\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test12

# Description: (13) Rejects 0 for pw_min_length.
test "create-policy 13"
proc test13 {} {
    global test
    global prompt


    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_LENGTH}
    } $test] "BAD_LENGTH"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test13

# Description: (14) Accepts non-zero for pw_min_length.
test "create-policy 14"
proc test14 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 0 8 0 0 0 } \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_LENGTH}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retreuve policy"
	return
    }
    send "lindex \$policy 3\n"
    expect {
	-re "8\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test14

# Description: (15) Rejects 0 for pw_min_classes.
test "create-policy 15"
proc test15 {} {
    global test

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_CLASSES}
    } $test] "BAD_CLASS"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test15

# Description: (16) Accepts 1 for pw_min_classes.
test "create-policy 16"
proc test16 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 0 0 1 0 0 } \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_CLASSES}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retreuve policy"
	return
    }
    send "lindex \$policy 4\n"
    expect {
	-re "1\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test16

# Description: (17) Accepts 4 for pw_min_classes.
test "create-policy 17"
proc test17 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 0 0 5 0 0} \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_CLASSES}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retreuve policy"
	return
    }
    send "lindex \$policy 4\n"
    expect {
	-re "5\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test17

# Description: (18) Rejects 5 for pw_min_classes.
test "create-policy 18"
proc test18 {} {
    global test

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 0 0 6 0 0} \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_MIN_CLASSES}
    } $test] "BAD_CLASS"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test18

# Description: (19) Rejects 0 for pw_history_num.
test "create-policy 19"
proc test19 {} {
    global test

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_HISTORY_NUM}
    } $test] "BAD_HISTORY"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test19

# Description: (20) Accepts 1 for pw_history_num.
test "create-policy 20"
proc test20 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd  [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 0 0 0 1 0} \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_HISTORY_NUM}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retreuve policy"
	return
    }
    send "lindex \$policy 5\n"
    expect {
	-re "1\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test20

# Description: (21) Accepts 10 for pw_history_num.
test "create-policy 21"
proc test21 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 0 0 0 10 0} \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_HISTORY_NUM}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	ovsec_kadm_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 5\n"
    expect {
	-re "10\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test21
    
# Description: (21.5) Rejects 11 for pw_history_num.
# 01/24/94: pshuang: untried.

test "create-policy 21.5"
proc test215 {} {
    global test
    global prompt

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }

    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle {"%s/a" 0 0 0 0 11 0} \
		{OVSEC_KADM_POLICY OVSEC_KADM_PW_HISTORY_NUM}
    } $test] "BAD_HISTORY"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test215


# Description: (22) Fails for user with no access bits.
test "create-policy 22"
proc test22 {} {
    global test
    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin/none admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} test22

# Description: (23) Fails for user with "get" but not "add".
test "create-policy 23"
proc test23 {} {
    global test
    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin/get admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} test23

# Description: (24) Fails for user with "modify" but not "add".
# 01/24/94: pshuang: untried.
test "create-policy 24"
proc test24 {} {
    global test
    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin/modify admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} test24

# Description: (25) Fails for user with "delete" but not "add".
# 01/24/94: pshuang: untried.
test "create-policy 25"
proc test25 {} {
    global test
    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }

    if {! [cmd {
	ovsec_kadm_init admin/delete admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} test25

# Description: Succeeds for user with "add".
test "create-policy 26"
proc test26 {} {
    global test

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/add admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_succeed_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test]
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test26

# Description: Succeeds for user with "get" and "add".
# 01/24/94: pshuang: untried.
test "create-policy 27"
proc test27 {} {
    global test

    if {! (( ! [policy_exists "$test/a"]) ||
	   [delete_policy "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/get-add admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_succeed_test [format {
	ovsec_kadm_create_policy $server_handle [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test]
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test27

# Description: (28) Rejects null policy argument.
# 01/24/94: pshuang: untried.
test "create-policy 28"
proc test28 {} {
    global test
    if {! [cmd {
	ovsec_kadm_init admin admin $OVSEC_KADM_ADMIN_SERVICE null \
		$OVSEC_KADM_STRUCT_VERSION $OVSEC_KADM_API_VERSION_1 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    one_line_fail_test {
	ovsec_kadm_create_policy $server_handle null {OVSEC_KADM_POLICY}
    } "EINVAL"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
        error "$test: unexpected failure in destroy"
        return
    }
}
test28

test "create-policy 30"
proc test30 {} {
    global test
    one_line_fail_test [format {
	ovsec_kadm_create_policy null [simple_policy "%s/a"] \
		{OVSEC_KADM_POLICY}
    } $test] "BAD_SERVER_HANDLE"
}
test30

return ""
