18
18
from src import srv_msg
19
19
from src import srv_control
20
20
from src .forge_cfg import world
21
+ from src .protosupport .multi_protocol_functions import fabric_sudo_command
21
22
22
23
# note: a lot of reconfigures in all those tests could be done by config-set, this would make tests cleaner
23
24
# but due to discovered bug https://gitlab.isc.org/isc-projects/kea/-/issues/2475 I choose to go with reconfigure
24
25
25
26
27
+ def create_user_and_passowrd_file (user , password ):
28
+ """create_user_and_passowrd_file Create a user and password file for the RBAC tests that are using basic authentication.
29
+ Usulally basic authentication uses one file with username and password. Let's use separate files for each user
30
+ in those tests.
31
+
32
+ :param user: The user to create in the file
33
+ :type user: str
34
+ :param password: The password to use
35
+ :type password: str
36
+ """
37
+ fabric_sudo_command (f'echo "{ user } " > { os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" , user )} ' ,
38
+ hide_all = not world .f_cfg .forge_verbose )
39
+ fabric_sudo_command (f'echo "{ password } " > { os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" , f"{ user } _password" )} ' ,
40
+ hide_all = not world .f_cfg .forge_verbose )
41
+
42
+ if world .f_cfg .install_method != 'make' :
43
+ if world .server_system in ['alpine' , 'redhat' , 'fedora' ]:
44
+ fabric_sudo_command (f'chown -R kea:kea { os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" )} ' ,
45
+ hide_all = not world .f_cfg .forge_verbose )
46
+ else :
47
+ fabric_sudo_command (f'chown -R _kea:_kea { os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" )} ' ,
48
+ hide_all = not world .f_cfg .forge_verbose )
49
+
50
+
51
+ # fixture to remove authentication files after the test
52
+ @pytest .fixture ()
53
+ def remove_authentication_files ():
54
+ """remove_authentication_files Remove authentication files after the test.
55
+ This fixture is used to create authentiaction directory and files before the test.
56
+ It is used to avoid conflicts with other tests.
57
+ """
58
+ fabric_sudo_command (f'mkdir -m 750 -p { os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" )} ' ,
59
+ hide_all = not world .f_cfg .forge_verbose )
60
+ yield
61
+ fabric_sudo_command (f'rm -rf { os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" )} ' ,
62
+ hide_all = not world .f_cfg .forge_verbose )
63
+
64
+
26
65
@pytest .mark .v4
27
66
@pytest .mark .v6
28
67
@pytest .mark .ca
@@ -359,6 +398,7 @@ def test_rbac_remote_address(dhcp_version, tls):
359
398
assert resp ['text' ] == 'Forbidden' , f"text message from response should be 'Forbidden' it is { resp } instead."
360
399
361
400
401
+ @pytest .mark .usefixtures ('remove_authentication_files' )
362
402
@pytest .mark .v4
363
403
@pytest .mark .v6
364
404
@pytest .mark .ca
@@ -382,17 +422,22 @@ def test_rbac_basic_authentication(dhcp_version, tls):
382
422
383
423
misc .test_setup ()
384
424
srv_control .add_unix_socket ()
425
+
426
+ create_user_and_passowrd_file ("admin" , "p@ssw0rd" )
427
+ create_user_and_passowrd_file ("admin2" , "p@ssw0rd" )
428
+
385
429
auth = {"authentication" : {
386
430
"type" : "basic" ,
431
+ "directory" : os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" ),
387
432
"clients" :
388
433
[
389
434
{
390
- "user" : "admin" ,
391
- "password" : "p@ssw0rd "
435
+ "user-file " : "admin" ,
436
+ "password-file " : "admin_password "
392
437
},
393
438
{
394
- "user" : "admin2" ,
395
- "password" : "p@ssw0rd "
439
+ "user-file " : "admin2" ,
440
+ "password-file " : "admin2_password "
396
441
}
397
442
]
398
443
}}
@@ -523,22 +568,26 @@ def _preconfigure_test():
523
568
misc .test_setup ()
524
569
srv_control .add_unix_socket ()
525
570
571
+ create_user_and_passowrd_file ("admin" , "p@ssw0rd" )
572
+ create_user_and_passowrd_file ("admin2" , "p@ssw0rd" )
573
+ create_user_and_passowrd_file ("admin3" , "p@ssw0rd" )
526
574
auth = {
527
575
"authentication" : {
528
576
"type" : "basic" ,
577
+ "directory" : os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" ),
529
578
"clients" :
530
579
[
531
580
{
532
- "user" : "admin" ,
533
- "password" : "p@ssw0rd "
581
+ "user-file " : "admin" ,
582
+ "password-file " : "admin_password "
534
583
},
535
584
{
536
- "user" : "admin2" ,
537
- "password" : "p@ssw0rd "
585
+ "user-file " : "admin2" ,
586
+ "password-file " : "admin2_password "
538
587
},
539
588
{
540
- "user" : "admin3" ,
541
- "password" : "p@ssw0rd "
589
+ "user-file " : "admin3" ,
590
+ "password-file " : "admin3_password "
542
591
}
543
592
]}}
544
593
@@ -586,6 +635,7 @@ def make_sure_file_is_correct():
586
635
srv_msg .execute_shell_cmd (f"cp ~/dhcp-disable.json.bk { f } " ) # restore backup after the test
587
636
588
637
638
+ @pytest .mark .usefixtures ('remove_authentication_files' )
589
639
@pytest .mark .v4
590
640
@pytest .mark .ca
591
641
@pytest .mark .v6
@@ -655,6 +705,7 @@ def test_rbac_access_by_read_write(dhcp_version, make_sure_file_is_correct):
655
705
_send_cmd ({"command" : "dhcp-disable" , "arguments" : {}}, result = 403 )
656
706
657
707
708
+ @pytest .mark .usefixtures ('remove_authentication_files' )
658
709
@pytest .mark .v4
659
710
@pytest .mark .v6
660
711
@pytest .mark .ca
@@ -707,6 +758,7 @@ def test_rbac_access_by_name_removed_file(dhcp_version, make_sure_file_is_correc
707
758
srv_control .start_srv ('CA' if world .f_cfg .control_agent else 'DHCP' , 'started' , should_succeed = False )
708
759
709
760
761
+ @pytest .mark .usefixtures ('remove_authentication_files' )
710
762
@pytest .mark .v4
711
763
@pytest .mark .v6
712
764
@pytest .mark .ca
@@ -792,6 +844,7 @@ def test_rbac_access_by_name_removed_file_2(dhcp_version, make_sure_file_is_corr
792
844
_send_cmd ({"command" : "dhcp-disable" , "arguments" : {}}, user = 'admin3' )
793
845
794
846
847
+ @pytest .mark .usefixtures ('remove_authentication_files' )
795
848
@pytest .mark .v4
796
849
@pytest .mark .v6
797
850
@pytest .mark .ca
@@ -915,6 +968,7 @@ def test_rbac_access_by_all_none(dhcp_version):
915
968
_send_cmd ({"command" : i , "arguments" : {}}, result = 403 )
916
969
917
970
971
+ @pytest .mark .usefixtures ('remove_authentication_files' )
918
972
@pytest .mark .v4
919
973
@pytest .mark .v6
920
974
@pytest .mark .ca
@@ -1037,6 +1091,7 @@ def test_rbac_access_by_commands_with_other_list(dhcp_version):
1037
1091
_send_cmd ({"command" : "lease4-get" , "arguments" : {}}, result = 2 )
1038
1092
1039
1093
1094
+ @pytest .mark .usefixtures ('remove_authentication_files' )
1040
1095
@pytest .mark .v4
1041
1096
@pytest .mark .v6
1042
1097
@pytest .mark .ca
@@ -1102,6 +1157,7 @@ def test_rbac_filter_responses(dhcp_version):
1102
1157
"We should get smaller number of commands back in second response"
1103
1158
1104
1159
1160
+ @pytest .mark .usefixtures ('remove_authentication_files' )
1105
1161
@pytest .mark .v4
1106
1162
@pytest .mark .v6
1107
1163
@pytest .mark .ca
@@ -1134,6 +1190,7 @@ def test_default_role(dhcp_version):
1134
1190
_send_cmd ({"command" : i , "arguments" : {}}, result = 403 )
1135
1191
1136
1192
1193
+ @pytest .mark .usefixtures ('remove_authentication_files' )
1137
1194
@pytest .mark .v4
1138
1195
@pytest .mark .v6
1139
1196
@pytest .mark .ca
@@ -1184,6 +1241,7 @@ def test_unknown_role(dhcp_version):
1184
1241
_send_cmd ({"command" : i , "arguments" : {}}, result = 403 )
1185
1242
1186
1243
1244
+ @pytest .mark .usefixtures ('remove_authentication_files' )
1187
1245
@pytest .mark .v4
1188
1246
@pytest .mark .v6
1189
1247
@pytest .mark .ca
@@ -1195,21 +1253,25 @@ def test_creating_access_list_for_multiple_use_cases(dhcp_version):
1195
1253
"""
1196
1254
misc .test_setup ()
1197
1255
srv_control .add_unix_socket ()
1256
+ create_user_and_passowrd_file ("admin" , "p@ssw0rd" )
1257
+ create_user_and_passowrd_file ("admin2" , "p@ssw0rd" )
1258
+ create_user_and_passowrd_file ("admin3" , "p@ssw0rd" )
1198
1259
auth = {"authentication" : {
1199
1260
"type" : "basic" ,
1261
+ "directory" : os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" ),
1200
1262
"clients" :
1201
1263
[
1202
1264
{
1203
- "user" : "admin" ,
1204
- "password" : "p@ssw0rd "
1265
+ "user-file " : "admin" ,
1266
+ "password-file " : "admin_password "
1205
1267
},
1206
1268
{
1207
- "user" : "admin2" ,
1208
- "password" : "p@ssw0rd "
1269
+ "user-file " : "admin2" ,
1270
+ "password-file " : "admin2_password "
1209
1271
},
1210
1272
{
1211
- "user" : "admin3" ,
1212
- "password" : "p@ssw0rd "
1273
+ "user-file " : "admin3" ,
1274
+ "password-file " : "admin3_password "
1213
1275
}
1214
1276
]
1215
1277
}}
@@ -1291,6 +1353,7 @@ def test_creating_access_list_for_multiple_use_cases(dhcp_version):
1291
1353
_send_cmd ({"command" : i , "arguments" : {}}, user = 'admin3' , result = 403 )
1292
1354
1293
1355
1356
+ @pytest .mark .usefixtures ('remove_authentication_files' )
1294
1357
@pytest .mark .v4
1295
1358
@pytest .mark .v6
1296
1359
@pytest .mark .ca
@@ -1302,13 +1365,15 @@ def test_mixed_roles(dhcp_version):
1302
1365
"""
1303
1366
misc .test_setup ()
1304
1367
srv_control .add_unix_socket ()
1368
+ create_user_and_passowrd_file ("admin" , "p@ssw0rd" )
1305
1369
auth = {"authentication" : {
1306
1370
"type" : "basic" ,
1371
+ "directory" : os .path .join (world .f_cfg .get_share_path (), "kea-creds-tmp" ),
1307
1372
"clients" :
1308
1373
[
1309
1374
{
1310
- "user" : "admin" ,
1311
- "password" : "p@ssw0rd "
1375
+ "user-file " : "admin" ,
1376
+ "password-file " : "admin_password "
1312
1377
}
1313
1378
]
1314
1379
}}
0 commit comments