Imported Upstream version 1.15.1
[platform/upstream/krb5.git] / src / lib / kadm5 / unit-test / api.current / mod-policy.exp
1 load_lib lib.t
2 api_exit
3 api_start
4
5 test "modify-policy 2"
6 proc test2 {} {
7     global test
8
9     if {! ((  [policy_exists "$test/a"]) ||
10            [create_policy "$test/a"])} {
11             error_and_restart "$test: couldn't create policy \"$test/a\""
12             return
13     }
14
15     if {! [cmd {
16         kadm5_init admin admin $KADM5_CHANGEPW_SERVICE null \
17                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
18                 server_handle
19     }]} {
20         perror "$test: unexpected failure in init"
21         return
22     }
23     one_line_fail_test [format {
24         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
25                 {KADM5_PW_MAX_LIFE}
26     } $test] "AUTH_MODIFY"
27     if { ! [cmd {kadm5_destroy $server_handle}]} {
28         perror "$test: unexpected failure in destroy"
29         return
30     }
31 }
32 if {$RPC} { test2 }
33
34 test "modify-policy 8"
35 proc test8 {} {
36     global test
37 #    set prms_id 744
38 #    setup_xfail {*-*-*} $prms_id
39
40     if {! ((  [policy_exists "$test/a"]) ||
41            [create_policy "$test/a"])} {
42             error_and_restart "$test: couldn't create policy \"$test/a\""
43             return
44     }
45
46     if {! [cmd {
47         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
48                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
49                 server_handle
50     }]} {
51         perror "$test: unexpected failure in init"
52         return
53     }
54     one_line_fail_test {
55         kadm5_modify_policy $server_handle [simple_policy ""] \
56                 {KADM5_PW_MAX_LIFE}
57     } "BAD_POLICY"
58     if { ! [cmd {kadm5_destroy $server_handle}]} {
59         perror "$test: unexpected failure in destroy"
60         return
61     }
62 }
63 test8
64
65 test "modify-policy 9"
66 proc test9 {} {
67     global test
68     global prompt
69     if {! ((  [policy_exists "$test/a"]) ||
70            [create_policy "$test/a"])} {
71             error_and_restart "$test: couldn't create policy \"$test/a\""
72             return
73     }
74
75     if {! [cmd {
76         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
77                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
78                 server_handle
79     }]} {
80         perror "$test: unexpected failure in init"
81         return
82     }
83     if {! [cmd [format {
84         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
85                 {KADM5_PW_MIN_LIFE}
86     } $test]]} {
87         fail $test
88         return
89     }
90     if {! [cmd [format {
91         kadm5_get_policy $server_handle "%s/a" policy
92     } $test]]} {
93         fail "$test: can not retrieve policy"
94         return
95     }
96     send "lindex \$policy 1\n"
97     expect {
98         -re "0\n$prompt$"               { pass "$test" }
99         timeout                         { fail "$test" }
100     }
101     
102     if { ! [cmd {kadm5_destroy $server_handle}]} {
103         perror "$test: unexpected failure in destroy"
104         return
105     }
106 }
107 test9
108
109 test "modify-policy 10"
110 proc test10 {} {
111     global test
112     global prompt
113     if {! ((  [policy_exists "$test/a"]) ||
114            [create_policy "$test/a"])} {
115             error_and_restart "$test: couldn't create policy \"$test/a\""
116             return
117     }
118     if {! [cmd {
119         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
120                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
121                 server_handle
122     }]} {
123         perror "$test: unexpected failure in init"
124         return
125     }
126     if {! [cmd [format {
127         kadm5_modify_policy $server_handle {"%s/a" 32 0 0 0 0 0 0 0 0} \
128                 {KADM5_PW_MIN_LIFE}
129     } $test]]} {
130         fail $test
131         return
132     }
133     if {! [cmd [format {
134         kadm5_get_policy $server_handle "%s/a" policy
135     } $test]]} {
136         fail "$test: can not retrieve policy"
137         return
138     }
139     send "lindex \$policy 1\n"
140     expect {
141         -re "32\n$prompt$"              { pass "$test" }
142         timeout                         { fail "$test" }
143     }
144     if { ! [cmd {kadm5_destroy $server_handle}]} {
145         perror "$test: unexpected failure in destroy"
146         return
147     }
148 }
149 test10
150
151
152 test "modify-policy 11"
153 proc test11 {} {
154     global test
155     global prompt
156     
157     if {! ((  [policy_exists "$test/a"]) ||
158            [create_policy "$test/a"])} {
159             error_and_restart "$test: couldn't create policy \"$test/a\""
160             return
161     }
162
163     if {! [cmd {
164         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
165                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
166                 server_handle
167     }]} {
168         perror "$test: unexpected failure in init"
169         return
170     }
171     if {! [cmd [format {
172         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
173                 {KADM5_PW_MAX_LIFE}
174     } $test]]} {
175         fail $test
176         return
177     }
178     if {! [cmd [format {
179         kadm5_get_policy $server_handle "%s/a" policy
180     } $test]]} {
181         fail "$test: can not retrieve policy"
182         return
183     }
184     send "lindex \$policy 2\n"
185     expect {
186         -re "0\n$prompt$"               { pass "$test" }
187         timeout                         { fail "$test" }
188     }
189     if { ! [cmd {kadm5_destroy $server_handle}]} {
190         perror "$test: unexpected failure in destroy"
191         return
192     }
193 }
194 test11
195
196 test "modify-policy 12"
197 proc test12 {} {
198     global test
199     global prompt
200     
201     if {! ((  [policy_exists "$test/a"]) ||
202            [create_policy "$test/a"])} {
203             error_and_restart "$test: couldn't create policy \"$test/a\""
204             return
205     }
206
207     if {! [cmd {
208         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
209                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
210                 server_handle
211     }]} {
212         perror "$test: unexpected failure in init"
213         return
214     }
215     if {! [cmd [format {
216         kadm5_modify_policy $server_handle {"%s/a" 0 32 0 0 0 0 0 0 0} \
217                 {KADM5_PW_MAX_LIFE}
218     } $test]]} {
219         fail $test
220         return
221     }
222     if {! [cmd [format {
223         kadm5_get_policy $server_handle "%s/a" policy
224     } $test]]} {
225         fail "$test: can not retrieve policy"
226         return
227     }
228     send "lindex \$policy 2\n"
229     expect {
230         -re "32\n$prompt$"              { pass "$test" }
231         timeout                         { fail "$test" }
232     }
233     if { ! [cmd {kadm5_destroy $server_handle}]} {
234         perror "$test: unexpected failure in destroy"
235         return
236     }
237 }
238 test12
239
240 test "modify-policy 13"
241 proc test13 {} {
242     global test
243     if {! ((  [policy_exists "$test/a"]) ||
244            [create_policy "$test/a"])} {
245             error_and_restart "$test: couldn't create policy \"$test/a\""
246             return
247     }
248
249     if {! [cmd {
250         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
251                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
252                 server_handle
253     }]} {
254         perror "$test: unexpected failure in init"
255         return
256     }
257     one_line_fail_test [format {
258         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
259                 {KADM5_PW_MIN_LENGTH}
260     } $test] "BAD_LENGTH"
261     if { ! [cmd {kadm5_destroy $server_handle}]} {
262         perror "$test: unexpected failure in destroy"
263         return
264     }
265 }
266 test13
267
268 test "modify-policy 14"
269 proc test14 {} {
270     global test
271     global prompt
272     
273     if {! ((  [policy_exists "$test/a"]) ||
274            [create_policy "$test/a"])} {
275             error_and_restart "$test: couldn't create policy \"$test/a\""
276             return
277     }
278
279     if {! [cmd {
280         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
281                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
282                 server_handle
283     }]} {
284         perror "$test: unexpected failure in init"
285         return
286     }
287     if {! [cmd [format {
288         kadm5_modify_policy $server_handle {"%s/a" 0 0 8 0 0 0 0 0 0} \
289                 {KADM5_PW_MIN_LENGTH}
290     } $test]]} {
291         fail $test
292         return
293     }
294     if {! [cmd [format {
295         kadm5_get_policy $server_handle "%s/a" policy
296     } $test]]} {
297         fail "$test: can not retrieve policy"
298         return
299     }
300     send "lindex \$policy 3\n"
301     expect {
302         -re "8\n$prompt$"               { pass "$test" }
303         timeout                         { fail "$test" }
304     }
305     if { ! [cmd {kadm5_destroy $server_handle}]} {
306         perror "$test: unexpected failure in destroy"
307         return
308     }
309 }
310 test14
311
312 test "modify-policy 15"
313 proc test15 {} {
314     global test
315     if {! ((  [policy_exists "$test/a"]) ||
316            [create_policy "$test/a"])} {
317             error_and_restart "$test: couldn't create policy \"$test/a\""
318             return
319     }
320
321     if {! [cmd {
322         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
323                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
324                 server_handle
325     }]} {
326         perror "$test: unexpected failure in init"
327         return
328     }
329     one_line_fail_test [format {
330         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
331                 {KADM5_PW_MIN_CLASSES}
332     } $test] "BAD_CLASS"
333     if { ! [cmd {kadm5_destroy $server_handle}]} {
334         perror "$test: unexpected failure in destroy"
335         return
336     }
337 }
338 test15
339
340 test "modify-policy 16"
341 proc test16 {} {
342     global test
343     global prompt
344     
345     if {! ((  [policy_exists "$test/a"]) ||
346            [create_policy "$test/a"])} {
347             error_and_restart "$test: couldn't create policy \"$test/a\""
348             return
349     }
350
351     if {! [cmd {
352         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
353                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
354                 server_handle
355     }]} {
356         perror "$test: unexpected failure in init"
357         return
358     }
359     if {! [cmd [format {
360         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 1 0 0 0 0 0} \
361                 {KADM5_PW_MIN_CLASSES}
362     } $test]]} {
363         fail $test
364         return
365     }
366     if {! [cmd [format {
367         kadm5_get_policy $server_handle "%s/a" policy
368     } $test]]} {
369         fail "$test: can not retrieve policy"
370         return
371     }
372     send "lindex \$policy 4\n"
373     expect {
374         -re "1\n$prompt$"               { pass "$test" }
375         timeout                         { fail "$test" }
376     }
377     
378     
379     if { ! [cmd {kadm5_destroy $server_handle}]} {
380         perror "$test: unexpected failure in destroy"
381         return
382     }
383 }
384 test16
385
386 test "modify-policy 17"
387 proc test17 {} {
388     global test
389     global prompt
390     
391     if {! ((  [policy_exists "$test/a"]) ||
392            [create_policy "$test/a"])} {
393             error_and_restart "$test: couldn't create policy \"$test/a\""
394             return
395     }
396
397     if {! [cmd {
398         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
399                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
400                 server_handle
401     }]} {
402         perror "$test: unexpected failure in init"
403         return
404     }
405     if {! [cmd [format {
406         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 5 0 0 0 0 0} \
407                 {KADM5_PW_MIN_CLASSES}
408     } $test]]} {
409         fail $test
410         return
411     }
412     if {! [cmd [format {
413         kadm5_get_policy $server_handle "%s/a" policy
414     } $test]]} {
415         fail "$test: can not retrieve policy"
416         return
417     }
418     send "lindex \$policy 4\n"
419     expect {
420         -re "5\n$prompt$"               { pass "$test" }
421         timeout                         { fail "$test" }
422     }
423     
424     if { ! [cmd {kadm5_destroy $server_handle}]} {
425         perror "$test: unexpected failure in destroy"
426         return
427     }
428 }
429 test17
430
431 test "modify-policy 18"
432 proc test18 {} {
433     global test
434     global prompt
435     
436     if {! ((  [policy_exists "$test/a"]) ||
437            [create_policy "$test/a" ])} {
438             error_and_restart "$test: couldn't create policy \"$test/a\""
439             return
440     }
441
442     if {! [cmd {
443         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
444                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
445                 server_handle
446     }]} {
447         perror "$test: unexpected failure in init"
448         return
449     }
450     one_line_fail_test [format {
451         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 6 0 0 0 0 0} \
452                 {KADM5_PW_MIN_CLASSES}
453     } $test] "BAD_CLASS"
454     if { ! [cmd {kadm5_destroy $server_handle}]} {
455         perror "$test: unexpected failure in destroy"
456         return
457     }
458 }
459 test18
460
461 test "modify-policy 19"
462 proc test19 {} {
463     global test
464     
465     if {! ((  [policy_exists "$test/a"]) ||
466            [create_policy "$test/a" ])} {
467             error_and_restart "$test: couldn't create policy \"$test/a\""
468             return
469     }
470
471     if {! [cmd {
472         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
473                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
474                 server_handle
475     }]} {
476         perror "$test: unexpected failure in init"
477         return
478     }
479     one_line_fail_test [format {
480         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
481                 {KADM5_PW_HISTORY_NUM}
482     } $test] "BAD_HISTORY"
483     if { ! [cmd {kadm5_destroy $server_handle}]} {
484         perror "$test: unexpected failure in destroy"
485         return
486     }
487 }
488 test19
489
490 test "modify-policy 20"
491 proc test20 {} {
492     global test
493     global prompt
494     
495     if {! ((  [policy_exists "$test/a"]) ||
496            [create_policy "$test/a" ])} {
497             error_and_restart "$test: couldn't create policy \"$test/a\""
498             return
499     }
500
501     if {! [cmd {
502         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
503                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
504                 server_handle
505     }]} {
506         perror "$test: unexpected failure in init"
507         return
508     }
509     if {! [cmd [format {
510         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 0 1 0 0 0 0} \
511                 {KADM5_PW_HISTORY_NUM}
512     } $test]]} {
513         fail $test
514         return
515     }
516     if {! [cmd [format {
517         kadm5_get_policy $server_handle "%s/a" policy
518     } $test]]} {
519         fail "$test: can not retrieve policy"
520         return
521     }
522     send "lindex \$policy 5\n"
523     expect {
524         -re "1\n$prompt$"               { pass "$test" }
525         timeout                         { fail "$test" }
526     }
527     
528     if { ! [cmd {kadm5_destroy $server_handle}]} {
529         perror "$test: unexpected failure in destroy"
530         return
531     }
532 }
533 test20
534
535 test "modify-policy 21"
536 proc test21 {} {
537     global test
538     global prompt
539     
540     if {! ((  [policy_exists "$test/a"]) ||
541            [create_policy "$test/a" ])} {
542             error_and_restart "$test: couldn't create policy \"$test/a\""
543             return
544     }
545
546     if {! [cmd {
547         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
548                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
549                 server_handle
550     }]} {
551         perror "$test: unexpected failure in init"
552         return
553     }
554     if {! [cmd [format {
555         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 0 10 0 0 0 0} \
556                 {KADM5_PW_HISTORY_NUM}
557     } $test]]} {
558         fail $test
559         return
560     }
561     if {! [cmd [format {
562         kadm5_get_policy $server_handle "%s/a" policy
563     } $test]]} {
564         fail "$test: can not retrieve policy"
565         return
566     }
567     send "lindex \$policy 5\n"
568     expect {
569         -re "10\n$prompt$"              { pass "$test" }
570         timeout                         { fail "$test" }
571     }
572     
573     if { ! [cmd {kadm5_destroy $server_handle}]} {
574         perror "$test: unexpected failure in destroy"
575         return
576     }
577 }
578 test21
579
580 test "modify-policy 22"
581 proc test22 {} {
582     global test
583     if {! ((  [policy_exists "$test/a"]) ||
584            [create_policy "$test/a" ])} {
585             error_and_restart "$test: couldn't create policy \"$test/a\""
586             return
587     }
588
589     if {! [cmd {
590         kadm5_init admin/none admin $KADM5_ADMIN_SERVICE null \
591                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
592                 server_handle
593     }]} {
594         perror "$test: unexpected failure in init"
595         return
596     }
597     one_line_fail_test [format {
598         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
599                 {KADM5_PW_MAX_LIFE}
600     } $test] "AUTH_MODIFY"
601     if { ! [cmd {kadm5_destroy $server_handle}]} {
602         perror "$test: unexpected failure in destroy"
603         return
604     }
605 }
606 if {$RPC} test22
607
608 test "modify-policy 23"
609 proc test23 {} {
610     global test
611     if {! ((  [policy_exists "$test/a"]) ||
612            [create_policy "$test/a" ])} {
613             error_and_restart "$test: couldn't create policy \"$test/a\""
614             return
615     }
616
617     if {! [cmd {
618         kadm5_init admin/get admin $KADM5_ADMIN_SERVICE null \
619                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
620                 server_handle
621     }]} {
622         perror "$test: unexpected failure in init"
623         return
624     }
625     one_line_fail_test [format {
626         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
627                 {KADM5_PW_MAX_LIFE}
628     } $test] "AUTH_MODIFY"
629     if { ! [cmd {kadm5_destroy $server_handle}]} {
630         perror "$test: unexpected failure in destroy"
631         return
632     }
633 }
634 if {$RPC} test23
635
636 test "modify-policy 26"
637 proc test26 {} {
638     global test
639     if {! ((  [policy_exists "$test/a"]) ||
640            [create_policy "$test/a" ])} {
641             error_and_restart "$test: couldn't create policy \"$test/a\""
642             return
643     }
644
645     if {! [cmd {
646         kadm5_init admin/modify admin $KADM5_ADMIN_SERVICE null \
647                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
648                 server_handle
649     }]} {
650         perror "$test: unexpected failure in init"
651         return
652     }
653     one_line_succeed_test [format {
654         kadm5_modify_policy $server_handle [simple_policy "%s/a"] \
655                 {KADM5_PW_MAX_LIFE}
656     } $test]
657     if { ! [cmd {kadm5_destroy $server_handle}]} {
658         perror "$test: unexpected failure in destroy"
659         return
660     }
661 }
662 test26
663
664 test "modify-policy 30"
665 proc test30 {} {
666     global test
667
668     one_line_fail_test [format {
669         kadm5_modify_policy null [simple_policy "%s/a"] \
670                 {KADM5_PW_MAX_LIFE}
671     } $test] "BAD_SERVER_HANDLE"
672 }
673 test30
674
675 test "modify-policy 31"
676 proc test31 {} {
677     global test
678     if {! ((  [policy_exists "$test/a"]) ||
679            [create_policy "$test/a" ])} {
680             error_and_restart "$test: couldn't create policy \"$test/a\""
681             return
682     }
683
684     if {! [cmd {
685         kadm5_init admin/modify admin $KADM5_ADMIN_SERVICE null \
686                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_3 \
687                 server_handle
688     }]} {
689         perror "$test: unexpected failure in init"
690         return
691     }
692     one_line_succeed_test [format {
693         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 0 0 0 2 0 0} \
694                 {KADM5_PW_MAX_FAILURE}
695     } $test]
696     one_line_succeed_test [format {
697         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 1 0 0 0 90 0} \
698                 {KADM5_PW_FAILURE_COUNT_INTERVAL}
699     } $test]
700     one_line_succeed_test [format {
701         kadm5_modify_policy $server_handle {"%s/a" 0 0 0 1 0 0 0 0 180} \
702                 {KADM5_PW_LOCKOUT_DURATION}
703     } $test]
704     if { ! [cmd {kadm5_destroy $server_handle}]} {
705         perror "$test: unexpected failure in destroy"
706         return
707     }
708 }
709 test31
710
711 return ""