@@ -32,6 +32,7 @@ const VALUE: &str = "zenoh";
32
32
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 4 ) ]
33
33
async fn test_acl_pub_sub ( ) {
34
34
zenoh:: init_log_from_env_or ( "error" ) ;
35
+ test_acl_config_format ( 27447 ) . await ;
35
36
test_pub_sub_deny ( 27447 ) . await ;
36
37
test_pub_sub_allow ( 27447 ) . await ;
37
38
test_pub_sub_deny_then_allow ( 27447 ) . await ;
@@ -124,6 +125,224 @@ async fn close_sessions(s01: Session, s02: Session) {
124
125
ztimeout ! ( s02. close( ) ) . unwrap ( ) ;
125
126
}
126
127
128
+ async fn test_acl_config_format ( port : u16 ) {
129
+ println ! ( "test_acl_config_format" ) ;
130
+ let mut config_router = get_basic_router_config ( port) . await ;
131
+
132
+ // missing lists
133
+ config_router
134
+ . insert_json5 (
135
+ "access_control" ,
136
+ r#"{
137
+ "enabled": true,
138
+ "default_permission": "deny"
139
+ }"# ,
140
+ )
141
+ . unwrap ( ) ;
142
+ assert ! ( ztimeout!( zenoh:: open( config_router. clone( ) ) )
143
+ . is_err_and( |e| e. to_string( ) . contains( "config lists must be provided" ) ) ) ;
144
+
145
+ // repeated rule id
146
+ config_router
147
+ . insert_json5 (
148
+ "access_control" ,
149
+ r#"{
150
+ "enabled": true,
151
+ "default_permission": "deny",
152
+ "rules": [
153
+ {
154
+ "id": "r1",
155
+ "permission": "allow",
156
+ "flows": ["egress", "ingress"],
157
+ "messages": ["put"],
158
+ "key_exprs": ["foo"],
159
+ },
160
+ {
161
+ "id": "r1",
162
+ "permission": "allow",
163
+ "flows": ["egress", "ingress"],
164
+ "messages": ["put"],
165
+ "key_exprs": ["bar"],
166
+ },
167
+ ],
168
+ "subjects": [{id: "all"}],
169
+ "policies": [
170
+ {
171
+ rules: ["r1"],
172
+ subjects: ["all"],
173
+ }
174
+ ],
175
+ }"# ,
176
+ )
177
+ . unwrap ( ) ;
178
+ assert ! ( ztimeout!( zenoh:: open( config_router. clone( ) ) )
179
+ . is_err_and( |e| e. to_string( ) . contains( "Rule id must be unique" ) ) ) ;
180
+
181
+ // repeated subject id
182
+ config_router
183
+ . insert_json5 (
184
+ "access_control" ,
185
+ r#"{
186
+ "enabled": true,
187
+ "default_permission": "deny",
188
+ "rules": [
189
+ {
190
+ "id": "r1",
191
+ "permission": "allow",
192
+ "flows": ["egress", "ingress"],
193
+ "messages": ["put"],
194
+ "key_exprs": ["foo"],
195
+ },
196
+ ],
197
+ "subjects": [
198
+ {
199
+ id: "s1",
200
+ interfaces: ["lo"],
201
+ },
202
+ {
203
+ id: "s1",
204
+ interfaces: ["lo0"],
205
+ },
206
+ ],
207
+ "policies": [
208
+ {
209
+ rules: ["r1"],
210
+ subjects: ["s1"],
211
+ }
212
+ ],
213
+ }"# ,
214
+ )
215
+ . unwrap ( ) ;
216
+ assert ! ( ztimeout!( zenoh:: open( config_router. clone( ) ) )
217
+ . is_err_and( |e| e. to_string( ) . contains( "Subject id must be unique" ) ) ) ;
218
+
219
+ // repeated policy id
220
+ config_router
221
+ . insert_json5 (
222
+ "access_control" ,
223
+ r#"{
224
+ "enabled": true,
225
+ "default_permission": "deny",
226
+ "rules": [
227
+ {
228
+ "id": "r1",
229
+ "permission": "allow",
230
+ "flows": ["egress", "ingress"],
231
+ "messages": ["put"],
232
+ "key_exprs": ["foo"],
233
+ },
234
+ {
235
+ "id": "r2",
236
+ "permission": "allow",
237
+ "flows": ["egress", "ingress"],
238
+ "messages": ["put"],
239
+ "key_exprs": ["bar"],
240
+ },
241
+ ],
242
+ "subjects": [{id: "all"}],
243
+ "policies": [
244
+ {
245
+ id: "p1",
246
+ rules: ["r1"],
247
+ subjects: ["all"],
248
+ },
249
+ {
250
+ id: "p1",
251
+ rules: ["r2"],
252
+ subjects: ["all"],
253
+ }
254
+ ],
255
+ }"# ,
256
+ )
257
+ . unwrap ( ) ;
258
+ assert ! ( ztimeout!( zenoh:: open( config_router. clone( ) ) )
259
+ . is_err_and( |e| e. to_string( ) . contains( "Policy id must be unique" ) ) ) ;
260
+
261
+ // non-existent rule in policy
262
+ config_router
263
+ . insert_json5 (
264
+ "access_control" ,
265
+ r#"{
266
+ "enabled": true,
267
+ "default_permission": "deny",
268
+ "rules": [
269
+ {
270
+ "id": "r1",
271
+ "permission": "allow",
272
+ "flows": ["egress", "ingress"],
273
+ "messages": ["put"],
274
+ "key_exprs": ["foo"],
275
+ },
276
+ {
277
+ "id": "r2",
278
+ "permission": "allow",
279
+ "flows": ["egress", "ingress"],
280
+ "messages": ["put"],
281
+ "key_exprs": ["bar"],
282
+ },
283
+ ],
284
+ "subjects": [{id: "all"}],
285
+ "policies": [
286
+ {
287
+ id: "p1",
288
+ rules: ["r1"],
289
+ subjects: ["all"],
290
+ },
291
+ {
292
+ id: "p2",
293
+ rules: ["NON-EXISTENT"],
294
+ subjects: ["all"],
295
+ }
296
+ ],
297
+ }"# ,
298
+ )
299
+ . unwrap ( ) ;
300
+ assert ! ( ztimeout!( zenoh:: open( config_router. clone( ) ) )
301
+ . is_err_and( |e| e. to_string( ) . contains( "does not exist in rules list" ) ) ) ;
302
+
303
+ // non-existent subject in policy
304
+ config_router
305
+ . insert_json5 (
306
+ "access_control" ,
307
+ r#"{
308
+ "enabled": true,
309
+ "default_permission": "deny",
310
+ "rules": [
311
+ {
312
+ "id": "r1",
313
+ "permission": "allow",
314
+ "flows": ["egress", "ingress"],
315
+ "messages": ["put"],
316
+ "key_exprs": ["foo"],
317
+ },
318
+ {
319
+ "id": "r2",
320
+ "permission": "allow",
321
+ "flows": ["egress", "ingress"],
322
+ "messages": ["put"],
323
+ "key_exprs": ["bar"],
324
+ },
325
+ ],
326
+ "subjects": [{id: "all"}],
327
+ "policies": [
328
+ {
329
+ id: "p1",
330
+ rules: ["r1"],
331
+ subjects: ["all"],
332
+ },
333
+ {
334
+ id: "p2",
335
+ rules: ["r2"],
336
+ subjects: ["NON-EXISTENT"],
337
+ }
338
+ ],
339
+ }"# ,
340
+ )
341
+ . unwrap ( ) ;
342
+ assert ! ( ztimeout!( zenoh:: open( config_router. clone( ) ) )
343
+ . is_err_and( |e| e. to_string( ) . contains( "does not exist in subjects list" ) ) ) ;
344
+ }
345
+
127
346
async fn test_pub_sub_deny ( port : u16 ) {
128
347
println ! ( "test_pub_sub_deny" ) ;
129
348
0 commit comments