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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
|
load_lib lib.t
api_exit
api_start
if ![info exists RESOLVE] {
set RESOLVE [findfile $objdir/../../../tests/resolve/resolve]
}
proc get_hostname { } {
global RESOLVE
global hostname
if {[info exists hostname]} {
return 1
}
catch "exec $RESOLVE -q >myname" exec_output
if ![string match "" $exec_output] {
send_log "$exec_output\n"
verbose $exec_output
send_error "ERROR: can't get hostname\n"
return 0
}
set file [open myname r]
if { [ gets $file hostname ] == -1 } {
send_error "ERROR: no output from hostname\n"
return 0
}
close $file
catch "exec rm -f myname" exec_output
set hostname [string tolower $hostname]
verbose "hostname: $hostname"
return 1
}
test "init 101"
proc test101 {} {
global test
global hostname
get_hostname
tcl_cmd "set hostname $hostname"
# XXX Fix to work with a remote TEST_SERVER. For now, make sure
# it fails in that case.
one_line_succeed_test {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_ADMIN_SERVER KADM5_CONFIG_KADMIND_PORT} [list $hostname 1751]] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
}
one_line_fail_test {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_ADMIN_SERVER KADM5_CONFIG_KADMIND_PORT} [list $hostname 4]] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "RPC_ERROR"
}
if {$RPC} test101
test "init 102"
proc test102 {} {
global test
one_line_fail_test {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_ADMIN_SERVER} does.not.exist] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "CANT_RESOLVE"
}
if {$RPC} test102
test "init 103"
proc test103 {} {
global test
one_line_fail_test {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_DBNAME} /does-not-exist] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "ENOENT"
}
#if {! $RPC} test103
if {! $RPC} {
send_user "UNTESTED: test103: test needs updating for DAL changes (see MIT RT ticket 3202)\n"
untested "test103: test needs updating for DAL changes (see MIT RT ticket 3202)"
}
test "init 106"
proc test106 {} {
global test prompt
set prompting 0
send [string trim {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_MKEY_FROM_KBD} 1] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
}]
send "\n"
expect {
-re "\n\[^\n\]+:\[^\n\]*$" { set prompting 1}
-re "\nOK .*$prompt$" { fail "$test: premature success" }
-re "\nERROR .*$prompt$" { fail "$test: premature failure" }
timeout { fail "$test: timeout" }
eof { fail "$test: eof" }
}
if {$prompting} {
one_line_succeed_test mrroot
}
if {! [cmd {kadm5_destroy $server_handle}]} {
error_and_restart "$test: couldn't close database"
}
}
if {! $RPC} test106
test "init 107"
proc test107 {} {
global test
one_line_fail_test {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_STASH_FILE} /does-not-exist] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "KDB_CANTREAD_STORED"
}
if {! $RPC} test107
test "init 108"
proc test108 {} {
global test
one_line_fail_test {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_MKEY_NAME} does/not/exist] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "KRB5_KDB_CANTREAD_STORED"
}
if {! $RPC} test108
test "init 109-113"
proc test109 {} {
global test prompt
delete_principal "$test/a"
# I'd like to specify flags explicitly and check them, as in the
# following config_params, but tcl gets mighty confused if I do and
# I have no idea why.
# [config_params {KADM5_CONFIG_MAX_LIFE KADM5_CONFIG_MAX_RLIFE KADM5_CONFIG_EXPIRATION KADM5_CONFIG_FLAGS KADM5_CONFIG_ENCTYPES} {10 20 30 KRB5_KDB_DISALLOW_TGT_BASED {}} ]
if {! [cmd {
kadm5_init admin admin $KADM5_ADMIN_SERVICE \
[config_params {KADM5_CONFIG_MAX_LIFE KADM5_CONFIG_MAX_RLIFE KADM5_CONFIG_EXPIRATION KADM5_CONFIG_ENCTYPES} {10 20 30 {}} ] \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
}]} {
fail "$test: cannot init with max_life"
return
}
if {! [cmd [format {
kadm5_create_principal $server_handle [simple_principal "%s/a"] \
{KADM5_PRINCIPAL} testpass
} $test]]} {
fail "$test: can not create principal"
return;
}
if {! [cmd [format {
kadm5_get_principal $server_handle "%s/a" p \
{KADM5_PRINCIPAL_NORMAL_MASK KADM5_KEY_DATA}
} $test]]} {
fail "$test: can not get principal"
return;
}
send "puts \$p\n"
expect {
-re "$prompt" { }
timeout {
error_and_restart "$test: timeout getting prompt"
return
}
eof {
error_and_restart "$test: eof getting prompt"
return
}
}
send "lindex \$p 4\n"
expect {
-re "(\[0-9\]+)\n$prompt" {set max_life $expect_out(1,string) }
timeout {
error_and_restart "$test: timeout getting max_life"
return
}
eof {
error_and_restart "$test: eof getting max_life"
return
}
}
send "lindex \$p 12\n"
expect {
-re "(\[0-9\]+)\n$prompt" {set max_rlife $expect_out(1,string) }
timeout {
error_and_restart "$test: timeout getting max_rlife"
return
}
eof {
error_and_restart "$test: eof getting max_rlife"
return
}
}
send "lindex \$p 1\n"
expect {
-re "(\[0-9\]+)\n$prompt" {set expiration $expect_out(1,string) }
timeout {
error_and_restart "$test: timeout getting expiration"
return
}
eof {
error_and_restart "$test: eof getting expiration"
return
}
}
send "lindex \$p 7\n"
expect {
-re "(\[A-Z_\]*)\n$prompt" {set flags $expect_out(1,string) }
timeout {
error_and_restart "$test: timeout getting flags"
return
}
eof {
error_and_restart "$test: eof getting flags"
return
}
}
# This sorta worries me. Since the test is setting ENCTYPES to
# nothing, the principal has no keys. That means that nothing is
# printed for the keys in the correct case; but it feels too
# likely that nothing will be printed in the case of some problem.
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 flags"
return
}
eof {
error_and_restart "$test: eof getting flags"
return
}
}
if { ! [cmd {kadm5_destroy $server_handle}]} {
perror "$test: unexpected failure in destroy"
return
}
if {$max_life == 10} {
pass "$test"
} else {
fail "$test: $max_life is not 10"
}
if {$max_rlife == 20} {
pass "$test"
} else {
fail "$test: $max_rlife is not 20"
}
if {$expiration == 30} {
pass "$test"
} else {
fail "$test: $expiration is not 30"
}
if {$flags == ""} {
pass "$test"
} else {
fail "$test: flags $flags are wrong"
}
if {$key_data == {}} {
pass "$test"
} else {
fail "$test: key_data $key_data is wrong"
}
}
if {! $RPC} test109
test "init 116"
proc test116 {} {
global test
delete_principal "$test/a"
if {! [cmd {kadm5_init admin/get-add admin $KADM5_ADMIN_SERVICE \
null $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
get_add_handle}]} {
error_and_restart "$test: couldn't init with admin/get-add"
}
if {! [cmd {kadm5_init admin/mod-delete admin $KADM5_ADMIN_SERVICE \
null $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
mod_delete_handle}]} {
error_and_restart "$test: couldn't init with admin/get-add"
}
one_line_succeed_test {
kadm5_get_principal $get_add_handle testuser p \
KADM5_PRINCIPAL_NORMAL_MASK
}
one_line_succeed_test [format {
kadm5_create_principal $get_add_handle [simple_principal "%s/a"] \
{KADM5_PRINCIPAL} testpass
} $test]
one_line_fail_test {
kadm5_modify_principal $get_add_handle [simple_principal testuser] \
{KADM5_PRINC_EXPIRE_TIME}
} "AUTH_MODIFY"
one_line_fail_test {
kadm5_delete_principal $get_add_handle testuser
} "AUTH_DELETE"
one_line_fail_test {
kadm5_get_principal $mod_delete_handle testuser p \
KADM5_PRINCIPAL_NORMAL_MASK
} "AUTH_GET"
one_line_fail_test [format {
kadm5_create_principal $mod_delete_handle [simple_principal "%s/a"] \
{KADM5_PRINCIPAL} testpass
} $test] "AUTH_ADD"
one_line_succeed_test {
kadm5_modify_principal $mod_delete_handle [simple_principal testuser] \
{KADM5_PRINC_EXPIRE_TIME}
}
one_line_succeed_test [format {
kadm5_delete_principal $mod_delete_handle "%s/a"
} $test]
if {! [cmd {kadm5_destroy $get_add_handle}]} {
error_and_restart "$test: couldn't close get_add_handle"
}
if {! [cmd {kadm5_destroy $mod_delete_handle}]} {
error_and_restart "$test: couldn't close mod_delete_handle"
}
}
if {$RPC} test116
test "init 117"
proc test117 {} {
global test env prompt
if {[catch "exec grep max_life $env(KRB5_KDC_PROFILE)"] != 1} {
warning \
"$test: max_life in $env(KRB5_KDC_PROFILE), cannot perform test"
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
}]} {
fail "$test: unexpected failure in init"
return
}
if {! [cmd [format {
kadm5_create_principal $server_handle [simple_principal "%s/a"] \
{KADM5_PRINCIPAL} "%s/a"
} $test $test]]} {
perror "$test: unexpected failure creating principal"
}
if {! [cmd [format {
kadm5_get_principal $server_handle "%s/a" principal KADM5_MAX_LIFE
} $test]]} {
error_and_restart "$test: could not retrieve principal"
return
}
send "lindex \$principal 4\n"
expect {
-re "(\[0-9\]+)\n$prompt" {set max_life $expect_out(1,string) }
timeout {
error_and_restart "$test: timeout getting max_life"
return
}
eof {
error_and_restart "$test: eof getting max_life"
return
}
}
if {$max_life == 86400} {
pass "$test"
} else {
fail "$test: max_life $max_life should be 86400"
}
if {! [cmd {kadm5_destroy $server_handle}]} {
error_and_restart "$test: couldn't close server_handle"
}
}
test117
send "puts \$KADM5_ADMIN_SERVICE\n"
expect {
-re "(\[a-zA-Z/@\]+)\n$prompt" {
set KADM5_ADMIN_SERVICE $expect_out(1,string)
}
default {
error_and_restart "$test: timeout/eof getting admin_service"
return
}
}
send "puts \$KADM5_CHANGEPW_SERVICE\n"
expect {
-re "(\[a-zA-Z/@\]+)\n$prompt" {
set KADM5_CHANGEPW_SERVICE $expect_out(1,string)
}
default {
error_and_restart "$test: timeout/eof getting changepw_service"
return
}
}
test "init 150"
proc test150 {} {
global test KADM5_ADMIN_SERVICE
kdestroy
kinit testuser notathena "-S $KADM5_ADMIN_SERVICE"
one_line_succeed_test {
kadm5_init_with_creds testuser null $KADM5_ADMIN_SERVICE \
null $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
}
kdestroy
}
if {$RPC} test150
test "init 151"
proc test151 {} {
global test KADM5_CHANGEPW_SERVICE
kdestroy
kinit testuser notathena "-S $KADM5_CHANGEPW_SERVICE"
one_line_succeed_test {
kadm5_init_with_creds testuser null $KADM5_CHANGEPW_SERVICE \
null $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
}
kdestroy
}
if {$RPC} test151
test "init 152"
proc test152 {} {
global test KADM5_ADMIN_SERVICE
kdestroy
one_line_fail_test {
kadm5_init_with_creds testuser null $KADM5_ADMIN_SERVICE \
null $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "KRB5_FCC_NOFILE"
}
if {$RPC} test152
test "init 153"
proc test153 {} {
global test KADM5_ADMIN_SERVICE
kinit testuser notathena
one_line_fail_test {
kadm5_init_with_creds testuser null $KADM5_ADMIN_SERVICE \
null $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "KRB5_CC_NOTFOUND"
}
if {$RPC} test153
test "init 154"
proc test154 {} {
global test env
set orig $env(KRB5_KDC_PROFILE)
set env(KRB5_KDC_PROFILE) /does-not-exist
api_exit; api_start
set env(KRB5_KDC_PROFILE) $orig
one_line_fail_test {
kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
$KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
server_handle
} "ENOENT"
api_exit; lib_start_api
}
if {0 && ! $RPC} test154
return ""
|