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 {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test \
	    {kadm5_delete_policy $server_handle ""} "BAD_POL"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$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 {
	kadm5_init admin admin $KADM5_CHANGEPW_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_delete_policy $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$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 {
	kadm5_init admin/none admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_delete_policy $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$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 {
	kadm5_init admin/add admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_delete_policy $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$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 {
	kadm5_init admin/delete admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if { ! [cmd [format {
	kadm5_delete_policy $server_handle  "%s/a"
    } $test]]} {
	fail "$test"
	return
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$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 {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test unexecpted failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_create_principal $server_handle [princ_w_pol "%s/a" \
		"%s/a"] {KADM5_PRINCIPAL KADM5_POLICY} \
		NotinTheDictionary
    } $test $test]]} {
	fail "$test: can not create principal"
	return;
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    if {! [cmd {
	kadm5_init admin/delete admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_succeed_test [format {
	kadm5_delete_policy $server_handle "%s/a"
    } $test]
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$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 {
	kadm5_delete_policy null "%s/a"
    } $test] "BAD_SERVER_HANDLE"
}
test13

return ""
