load_lib lib.t
api_exit
api_start

test "modify-policy 2"
proc test2 {} {
    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_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MAX_LIFE}
    } $test] "AUTH_MODIFY"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test2 }

test "modify-policy 8"
proc test8 {} {
    global test
#    set prms_id 744
#    setup_xfail {*-*-*} $prms_id

    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test {
	kadm5_modify_policy $server_handle [simple_policy ""] \
		{KADM5_PW_MAX_LIFE}
    } "BAD_POLICY"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test8

test "modify-policy 9"
proc test9 {} {
    global test
    global prompt
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MIN_LIFE}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_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 {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test9

test "modify-policy 10"
proc test10 {} {
    global test
    global prompt
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle {"%s/a" 32 0 0 0 0 0} \
		{KADM5_PW_MIN_LIFE}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 1\n"
    expect {
	-re "32\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test10


test "modify-policy 11"
proc test11 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MAX_LIFE}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 2\n"
    expect {
	-re "0\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test11

test "modify-policy 12"
proc test12 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle {"%s/a" 0 32 0 0 0 0} \
		{KADM5_PW_MAX_LIFE}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 2\n"
    expect {
	-re "32\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test12

test "modify-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
    }

    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MIN_LENGTH}
    } $test] "BAD_LENGTH"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test13

test "modify-policy 14"
proc test14 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle {"%s/a" 0 0 8 0 0 0} \
		{KADM5_PW_MIN_LENGTH}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 3\n"
    expect {
	-re "8\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test14

test "modify-policy 15"
proc test15 {} {
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MIN_CLASSES}
    } $test] "BAD_CLASS"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test15

test "modify-policy 16"
proc test16 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle {"%s/a" 0 0 0 1 0 0} \
		{KADM5_PW_MIN_CLASSES}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 4\n"
    expect {
	-re "1\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    
    
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test16

test "modify-policy 17"
proc test17 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle {"%s/a" 0 0 0 5 0 0} \
		{KADM5_PW_MIN_CLASSES}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 4\n"
    expect {
	-re "5\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test17

test "modify-policy 18"
proc test18 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_modify_policy $server_handle {"%s/a" 0 0 0 6 0 0} \
		{KADM5_PW_MIN_CLASSES}
    } $test] "BAD_CLASS"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test18

test "modify-policy 19"
proc test19 {} {
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_HISTORY_NUM}
    } $test] "BAD_HISTORY"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test19

test "modify-policy 20"
proc test20 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle {"%s/a" 0 0 0 0 1 0} \
		{KADM5_PW_HISTORY_NUM}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_get_policy $server_handle "%s/a" policy
    } $test]]} {
	fail "$test: can not retrieve policy"
	return
    }
    send "lindex \$policy 5\n"
    expect {
	-re "1\n$prompt$"		{ pass "$test" }
	timeout				{ fail "$test" }
    }
    
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test20

test "modify-policy 21"
proc test21 {} {
    global test
    global prompt
    
    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_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    if {! [cmd [format {
	kadm5_modify_policy $server_handle {"%s/a" 0 0 0 0 10 0} \
		{KADM5_PW_HISTORY_NUM}
    } $test]]} {
	fail $test
	return
    }
    if {! [cmd [format {
	kadm5_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 {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test21

test "modify-policy 22"
proc test22 {} {
    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_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MAX_LIFE}
    } $test] "AUTH_MODIFY"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} test22

test "modify-policy 23"
proc test23 {} {
    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/get admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_fail_test [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MAX_LIFE}
    } $test] "AUTH_MODIFY"
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} test23

test "modify-policy 26"
proc test26 {} {
    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/modify admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	perror "$test: unexpected failure in init"
	return
    }
    one_line_succeed_test [format {
	kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
		{KADM5_PW_MAX_LIFE}
    } $test]
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	perror "$test: unexpected failure in destroy"
	return
    }
}
test26

test "modify-policy 30"
proc test30 {} {
    global test

    one_line_fail_test [format {
	kadm5_modify_policy null [simple_policy "%s/a"] \
		{KADM5_PW_MAX_LIFE}
    } $test] "BAD_SERVER_HANDLE"
}
test30

return ""
