This commit was manufactured by cvs2svn to create tag
[krb5.git] / src / lib / kadm5 / unit-test / api.2 / get-principal-v2.exp
1 load_lib lib.t
2 api_exit
3 api_start
4
5 test "get-principal 100"
6 proc test100 {} {
7     global test prompt
8
9     if {! [cmd {
10         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
11                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
12                 server_handle
13     }]} {
14         error "$test: unexpected failure in init"
15         return
16     }
17     if {! [cmd {
18         kadm5_get_principal $server_handle testuser p \
19                 {KADM5_PRINCIPAL_NORMAL_MASK}
20     }]} {
21         error "$test: unexpected failure in get_principal"
22     }
23     send "lindex \$p 16\n"
24     expect {
25         -re "(\[0-9\]+)\n$prompt" { set num_keys $expect_out(1,string) }
26         timeout {
27             error_and_restart "$test: timeout getting num_keys"
28             return
29         }
30         eof {
31             error_and_restart "$test: eof getting num_keys"
32             return
33         }
34     }
35     send "lindex \$p 17\n"
36     expect {
37         -re "(\[0-9\]+)\n$prompt" { set num_tl $expect_out(1,string) }
38         timeout {
39             error_and_restart "$test: timeout getting num_tl"
40             return
41         }
42         eof {
43             error_and_restart "$test: eof getting num_tl"
44             return
45         }
46     }
47     send "lindex \$p 18\n"
48     expect {
49         -re "({.*})\n$prompt" {set key_data $expect_out(1,string) }
50         -re "\n$prompt" { set key_data {} }
51         timeout {
52             error_and_restart "$test: timeout getting key_data"
53             return
54         }
55         eof {
56             error_and_restart "$test: eof getting key_data"
57             return
58         }
59     }
60     send "lindex \$p 19\n"
61     expect {
62         -re "({.*})\n$prompt" {set tl_data $expect_out(1,string) }
63         -re "\n$prompt" { set tl_data {} }
64         timeout {
65             error_and_restart "$test: timeout getting tl_data"
66             return
67         }
68         eof {
69             error_and_restart "$test: eof getting tl_data"
70             return
71         }
72     }
73     
74     set failed 0
75     if {$num_keys != 0} {
76         fail "$test: num_keys $num_keys should be 0"
77         set failed 1
78     }
79     if {$num_tl != 0} {
80         fail "$test: num_tl $num_tl should be 0"
81         set failed 1
82     }
83     if {$key_data != {}} {
84         fail "$test: key_data $key_data should be {}"
85         set failed 1
86     }
87     if {$tl_data != "{}"} {
88         fail "$test: tl_data $tl_data should be empty"
89         set failed 1
90     }
91     if {$failed == 0} {
92         pass "$test"
93     }
94
95     if { ! [cmd {kadm5_destroy $server_handle}]} {
96         error "$test: unexpected failure in destroy"
97         return
98     }
99 }
100 test100
101
102 proc test101_102 {rpc} {
103     global test prompt
104
105     if {! [cmd {
106         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
107                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
108                 server_handle
109     }]} {
110         error "$test: unexpected failure in init"
111         return
112     }
113     if {! [cmd {
114         kadm5_get_principal $server_handle testuser p \
115                 {KADM5_PRINCIPAL_NORMAL_MASK KADM5_KEY_DATA}
116     }]} {
117         error "$test: unexpected failure in get_principal"
118     }
119     send "lindex \$p 16\n"
120     expect {
121         -re "(\[0-9\]+)\n$prompt" { set num_keys $expect_out(1,string) }
122         timeout {
123             error_and_restart "$test: timeout getting num_keys"
124             return
125         }
126         eof {
127             error_and_restart "$test: eof getting num_keys"
128             return
129         }
130     }
131     send "lindex \$p 18\n"
132     expect {
133         -re "({.*})\n$prompt" {set key_data $expect_out(1,string) }
134         -re "\n$prompt" { set key_data {} }
135         timeout {
136             error_and_restart "$test: timeout getting key_data"
137             return
138         }
139         eof {
140             error_and_restart "$test: eof getting key_data"
141             return
142         }
143     }
144
145     set failed 0
146     if {$num_keys != 3} {
147         fail "$test: num_keys $num_keys should be 3"
148         set failed 1
149     }
150     for {set i 0} {$i < $num_keys} {incr i} {
151         set key "[lindex [lindex $key_data $i] 2]"
152         if {($rpc && [string compare $key ""] != 0) ||
153             ((! $rpc) && [string compare $key ""] == 0)} {
154             fail "$test: key_data $key is wrong"
155             set failed 1
156             
157         }
158     }
159     if {$failed == 0} { pass "$test" }
160     
161     if { ! [cmd {kadm5_destroy $server_handle}]} {
162         error "$test: unexpected failure in destroy"
163         return
164     }
165 }
166 test "get-principal 101" 
167 if {$RPC} {test101_102 $RPC}
168 test "get-principal 102" 
169 if {! $RPC} {test101_102 $RPC}
170
171 test "get-principal 103"
172 proc test103 {} {
173     global test prompt
174
175     if {! ((  [principal_exists "$test/a"]) ||
176            [create_principal "$test/a"])} {
177             error_and_restart "$test: couldn't create principal \"$test/a\""
178             return
179     }
180
181     if {! [cmd {
182         kadm5_init admin admin $KADM5_ADMIN_SERVICE null \
183                 $KADM5_STRUCT_VERSION $KADM5_API_VERSION_2 \
184                 server_handle
185     }]} {
186         error "$test: unexpected failure in init"
187         return
188     }
189
190     if { ! [cmd [format {
191         kadm5_modify_principal $server_handle \
192                 "{%s/a} 0 0 0 0 {%s/a} 0 0 0 0 null 0 0 0 0 0 0 1 {} {{999 6 foobar}}" \
193                 {KADM5_TL_DATA}
194     } $test $test]]} {
195         fail "$test: cannot set TL_DATA"
196         return
197     }
198
199     if {! [cmd [format {
200         kadm5_get_principal $server_handle {%s/a} p \
201                 {KADM5_PRINCIPAL_NORMAL_MASK KADM5_TL_DATA}
202     } $test]]} {
203         error "$test: unexpected failure in get_principal"
204     }
205     send "lindex \$p 17\n"
206     expect {
207         -re "(\[0-9\]+)\n$prompt" { set num_tl $expect_out(1,string) }
208         timeout {
209             error_and_restart "$test: timeout getting num_tl"
210             return
211         }
212         eof {
213             error_and_restart "$test: eof getting num_tl"
214             return
215         }
216     }
217     send "lindex \$p 19\n"
218     expect {
219         -re "({.*})\n$prompt" {set tl_data $expect_out(1,string) }
220         -re "\n$prompt" { set tl_data {} }
221         timeout {
222             error_and_restart "$test: timeout getting tl_data"
223             return
224         }
225         eof {
226             error_and_restart "$test: eof getting tl_data"
227             return
228         }
229     }
230     
231     if {$num_tl == 0} {
232         fail "$test: num_tl $num_tl should not be 0"
233     } elseif {$tl_data == "{{999 6 foobar}}"} {
234         pass "$test"
235     } else {
236         fail "$test: tl_data $tl_data should be {{999 6 foobar}}"
237     }
238
239     if { ! [cmd {kadm5_destroy $server_handle}]} {
240         error "$test: unexpected failure in destroy"
241         return
242     }
243 }
244 test103
245
246 return ""
247
248
249
250