load_lib lib.t

api_exit
api_start

#test "delete-principal 1"
#proc test1 {} {
#	global test
#	one_line_fail_test [format {
#	    kadm5_delete_principal $server_handle "%s/a"
#	} $test] "NOT_INIT"
#}
#test1

test "delete-principal 2"
proc test2 {} {
    global test
   
    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/delete 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_principal $server_handle null} "EINVAL"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	error_and_restart "$test: unexpected failure in destroy"
	return
    }
}
test2

test "delete-principal 5"
proc test5 {} {
    global test
   
    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/delete 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_principal $server_handle "%s/a"
    } $test] "UNK_PRINC"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test5

test "delete-principal 6"
proc test6 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal_pol "$test/a" test-pol])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/delete 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_principal $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-principal 7"
proc test7 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$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_principal $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-principal 8"
proc test8 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/modify 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_principal $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test8 }

test "delete-principal 9"
proc test9 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	kadm5_init admin/get 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_principal $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test9 }

test "delete-principal 10"
proc test10 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$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_principal $server_handle "%s/a"
    } $test] "AUTH_DELETE"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test10 }

test "delete-principal 11"
proc test11 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't delete principal \"$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_principal $server_handle "%s/a"
    } $test]]} {
	fail "$test: delete failed"
	return;
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
    if { [principal_exists "$test/a"] } {
	fail "$test"
	return
    }
}
test11

test "delete-principal 13"
proc test13 {} {
	global test
	one_line_fail_test [format {
	    kadm5_delete_principal null "%s/a"
	} $test] "BAD_SERVER_HANDLE"
}
test13
    
return ""





