@@ -283,6 +283,62 @@ func TestClient_SetACL(t *testing.T) {
283
283
assert .EqualValues (t , expectedACL , actualACL )
284
284
}
285
285
286
+ func TestClient_SetAndGetACL (t * testing.T ) {
287
+ t .Parallel ()
288
+
289
+ client , server := NewTestHarness (t )
290
+ server .ResponseCode = http .StatusOK
291
+ server .ResponseHeader .Set ("ETag" , "abcdefg" )
292
+ in := ACL {
293
+ ACLs : []ACLEntry {
294
+ {
295
+ Action : "accept" ,
296
+ Ports : []string {"*:*" },
297
+ Users : []string {"*" },
298
+ },
299
+ },
300
+ TagOwners : map [string ][]string {
301
+ "tag:example" : {"group:example" },
302
+ },
303
+ Hosts : map [string ]string {
304
+ "example-host-1" : "100.100.100.100" ,
305
+ "example-host-2" : "100.100.101.100/24" ,
306
+ },
307
+ Groups : map [string ][]string {
308
+ "group:example" : {
309
+ "user1@example.com" ,
310
+ "user2@example.com" ,
311
+ },
312
+ },
313
+ Tests : []ACLTest {
314
+ {
315
+ User : "user1@example.com" ,
316
+ Allow : []string {"example-host-1:22" , "example-host-2:80" },
317
+ Deny : []string {"exapmle-host-2:100" },
318
+ },
319
+ {
320
+ User : "user2@example.com" ,
321
+ Allow : []string {"100.60.3.4:22" },
322
+ },
323
+ },
324
+ ETag : "abcdefg" ,
325
+ }
326
+ server .ResponseBody = in
327
+
328
+ out , err := client .PolicyFile ().SetAndGet (context .Background (), in , "abcdefg" )
329
+ assert .NoError (t , err )
330
+ assert .Equal (t , http .MethodPost , server .Method )
331
+ assert .Equal (t , "/api/v2/tailnet/example.com/acl" , server .Path )
332
+ assert .Equal (t , `"abcdefg"` , server .Header .Get ("If-Match" ))
333
+ assert .EqualValues (t , "application/json" , server .Header .Get ("Content-Type" ))
334
+ assert .EqualValues (t , & in , out )
335
+
336
+ var actualACL ACL
337
+ assert .NoError (t , json .Unmarshal (server .Body .Bytes (), & actualACL ))
338
+ in .ETag = ""
339
+ assert .EqualValues (t , in , actualACL )
340
+ }
341
+
286
342
func TestClient_SetACL_HuJSON (t * testing.T ) {
287
343
t .Parallel ()
288
344
0 commit comments