load_lib lib.t
api_exit
api_start

test "delete-policy 2"
proc test2 {} {
    global test
#    set prms_id 744
#    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_delete_policy $server_handle ""} "BAD_POL"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test2

test "delete-policy 5"
proc test5 {} {
    global test
    if {! ((  [policy_exists "$test/a"]) ||
	   [create_policy "$test/a"])} {
	    error_and_restart "$test: couldn't create policy \"$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_delete_policy $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if ${RPC} test5

test "delete-policy 6"
proc test6 {} {
    global test
    if {! ((  [policy_exists "$test/a"]) ||
	   [create_policy "$test/a"])} {
	    error_and_restart "$test: couldn't create policy \"$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_delete_policy $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if ${RPC} test6

test "delete-policy 7"
proc test7 {} {
    global test
    if {! ((  [policy_exists "$test/a"]) ||
	   [create_policy "$test/a"])} {
	    error_and_restart "$test: couldn't create policy \"$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_fail_test [format {
	ovsec_kadm_delete_policy $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} test7

test "delete-policy 10"
proc test10 {} {
    global test
    if {! ((  [policy_exists "$test/a"]) ||
	   [create_policy "$test/a"])} {
	    error_and_restart "$test: couldn't create policy \"$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
    }
    if { ! [cmd [format {
	ovsec_kadm_delete_policy $server_handle  "%s/a"
    } $test]]} {
	fail "$test"
	return
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
    if { [policy_exists "$test/a"]} {
	fail "$test"
	return
    }
}
test10

test "delete-policy 12"
proc test12 {} {
    global test
    if {! ((  [policy_exists "$test/a"]) ||
	   [create_policy "$test/a"])} {
	    error_and_restart "$test: couldn't create policy \"$test/a\""
	    return
    }
    if {! ((! [principal_exists "$test/a"]) ||
	   [delete_principal "$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 unexecpted failure in init"
	return
    }
    if {! [cmd [format {
	ovsec_kadm_create_principal $server_handle [princ_w_pol "%s/a" \
		"%s/a"] {OVSEC_KADM_PRINCIPAL OVSEC_KADM_POLICY} \
		NotinTheDictionary
    } $test $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	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 \
	    {ovsec_kadm_delete_policy $server_handle test-pol} "POLICY_REF"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test12

test "delete-policy 13"
proc test13 {} {
    global test
    if {! ((  [policy_exists "$test/a"]) ||
	   [create_policy "$test/a"])} {
	    error_and_restart "$test: couldn't create policy \"$test/a\""
	    return
    }
    one_line_fail_test [format {
	ovsec_kadm_delete_policy null "%s/a"
    } $test] "BAD_SERVER_HANDLE"
}
test13

return ""
