aboutsummaryrefslogtreecommitdiff
path: root/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp
blob: 0e3e1b5a8fd1696071bdd827f3899a16b4e952cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
load_lib lib.t
api_exit
api_start

test "get-principal 100"
proc test100 {} {
    global test prompt

    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd {
	kadm5_get_principal $server_handle testuser p \
		{KADM5_PRINCIPAL_NORMAL_MASK}
    }]} {
	error "$test: unexpected failure in get_principal"
    }
    send "lindex \$p 16\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" { set num_keys $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting num_keys"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting num_keys"
	    return
	}
    }
    send "lindex \$p 17\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" { set num_tl $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting num_tl"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting num_tl"
	    return
	}
    }
    send "lindex \$p 18\n"
    expect {
	-re "({.*})\n$prompt" {set key_data $expect_out(1,string) }
	-re "\n$prompt" { set key_data {} }
	timeout {
	    error_and_restart "$test: timeout getting key_data"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting key_data"
	    return
	}
    }
    send "lindex \$p 19\n"
    expect {
	-re "({.*})\n$prompt" {set tl_data $expect_out(1,string) }
	-re "\n$prompt" { set tl_data {} }
	timeout {
	    error_and_restart "$test: timeout getting tl_data"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting tl_data"
	    return
	}
    }
    
    set failed 0
    if {$num_keys != 0} {
	fail "$test: num_keys $num_keys should be 0"
	set failed 1
    }
    if {$num_tl != 0} {
	fail "$test: num_tl $num_tl should be 0"
	set failed 1
    }
    if {$key_data != {}} {
	fail "$test: key_data $key_data should be {}"
	set failed 1
    }
    if {$tl_data != "{}"} {
	fail "$test: tl_data $tl_data should be empty"
	set failed 1
    }
    if {$failed == 0} {
	pass "$test"
    }

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

proc test101_102 {rpc} {
    global test prompt

    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }
    if {! [cmd {
	kadm5_get_principal $server_handle testuser p \
		{KADM5_PRINCIPAL_NORMAL_MASK KADM5_KEY_DATA}
    }]} {
	error "$test: unexpected failure in get_principal"
    }
    send "lindex \$p 16\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" { set num_keys $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting num_keys"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting num_keys"
	    return
	}
    }
    send "lindex \$p 18\n"
    expect {
	-re "({.*})\n$prompt" {set key_data $expect_out(1,string) }
	-re "\n$prompt" { set key_data {} }
	timeout {
	    error_and_restart "$test: timeout getting key_data"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting key_data"
	    return
	}
    }

    set failed 0
    if {$num_keys != 2} {
	fail "$test: num_keys $num_keys should be 2"
	set failed 1
    }
    for {set i 0} {$i < $num_keys} {incr i} {
	set key "[lindex [lindex $key_data $i] 2]"
	if {($rpc && [string compare $key ""] != 0) ||
	    ((! $rpc) && [string compare $key ""] == 0)} {
	    fail "$test: key_data $key is wrong"
	    set failed 1
	    
	}
    }
    if {$failed == 0} { pass "$test" }
    
    if { ! [cmd {kadm5_destroy $server_handle}]} {
	error "$test: unexpected failure in destroy"
	return
    }
}
test "get-principal 101" 
if {$RPC} {test101_102 $RPC}
test "get-principal 102" 
if {! $RPC} {test101_102 $RPC}

test "get-principal 103"
proc test103 {} {
    global test prompt

    if {! ((  [principal_exists "$test/a"]) ||
	   [create_principal "$test/a"])} {
	    error_and_restart "$test: couldn't create principal \"$test/a\""
	    return
    }

    if {! [cmd {
	kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
		$KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
		server_handle
    }]} {
	error "$test: unexpected failure in init"
	return
    }

    if { ! [cmd [format {
	kadm5_modify_principal $server_handle \
		"{%s/a} 0 0 0 0 {%s/a} 0 0 0 0 null 0 0 0 0 0 0 1 {} {{999 6 foobar}}" \
		{KADM5_TL_DATA}
    } $test $test]]} {
	fail "$test: cannot set TL_DATA"
	return
    }

    if {! [cmd [format {
	kadm5_get_principal $server_handle {%s/a} p \
		{KADM5_PRINCIPAL_NORMAL_MASK KADM5_TL_DATA}
    } $test]]} {
	error "$test: unexpected failure in get_principal"
    }
    send "lindex \$p 17\n"
    expect {
	-re "(\[0-9\]+)\n$prompt" { set num_tl $expect_out(1,string) }
	timeout {
	    error_and_restart "$test: timeout getting num_tl"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting num_tl"
	    return
	}
    }
    send "lindex \$p 19\n"
    expect {
	-re "({.*})\n$prompt" {set tl_data $expect_out(1,string) }
	-re "\n$prompt" { set tl_data {} }
	timeout {
	    error_and_restart "$test: timeout getting tl_data"
	    return
	}
	eof {
	    error_and_restart "$test: eof getting tl_data"
	    return
	}
    }
    
    if {$num_tl == 0} {
	fail "$test: num_tl $num_tl should not be 0"
    } elseif {$tl_data == "{{999 6 foobar}}"} {
	pass "$test"
    } else {
	fail "$test: tl_data $tl_data should be {{999 6 foobar}}"
    }

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

return ""