load_lib lib.t
api_exit
api_start

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

test "rename-principal 2"
proc test2 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "INSUFFICIENT"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }

}
if {$RPC} { test2 }

test "rename-principal 3"
proc test3 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_INSUFFICIENT"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test3 }

test "rename-principal 4"
proc test4 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_INSUFFICIENT"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test4 }

test "rename-principal 5"
proc test5 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_INSUFFICIENT"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test5 }

test "rename-principal 6"
proc test6 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/mod-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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_DELETE"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test6 }

test "rename-principal 7"
proc test7 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/mod-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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test7 }

test "rename-principal 8"
proc test8 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    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_fail_test [format {
	ovsec_kadm_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_DELETE"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test8 }

test "rename-principal 9"
proc test9 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/get-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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test9 }

test "rename-principal 10"
proc test10 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/no-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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_DELETE"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test10 }

test "rename-principal 11"
proc test11 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/no-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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH_ADD"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test11 }

test "rename-principal 12"
proc test12 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    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_fail_test [format {
	ovsec_kadm_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test12 }


test "rename-principal 13"
proc test13 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "AUTH"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
if {$RPC} { test13 }

test "rename-principal 14"
proc test14 {} {
    global test
    
    if {[principal_exists "$test/a"]} {
	delete_principal "$test/a"
    }

    if {[create_principal_with_keysalts "$test/a" "des-cbc-crc:v4"]} {
	error_and_restart "$test: couldn't create no-salt principal \"$test/a\""
	return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/rename 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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test]
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test14

test "rename-principal 15"
proc test15 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( [principal_exists "$test/b"]) ||
	   [create_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/rename 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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "DUP"
    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test15

test "rename-principal 16"
proc test16 {} {
	global test
	one_line_fail_test [format {
	    ovsec_kadm_rename_principal null "%s/a" "%s/b"
	} $test $test] "BAD_SERVER_HANDLE"
}
test16

test "rename-principal 18"
proc test18 {} {
    global test
    
    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }
    if {! (( ! [principal_exists "$test/b"]) ||
	   [delete_principal "$test/b"])} {
	    error_and_restart "$test: couldn't delete principal \"$test/a\""
	    return
    }
    if {! [cmd {
	ovsec_kadm_init admin/rename 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_rename_principal $server_handle "%s/a" "%s/b"
    } $test $test] "NO_RENAME_SALT"

    if { ! [cmd {ovsec_kadm_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test18

return ""
