22import logging
33from typing import Dict
44
5+ import pytest
56from test_integration import get_log_from_pod # pylint: disable=E0611
67
78from conftest import is_pod_with_field_selector_successfully_completed # pylint: disable=E0611
@@ -18,66 +19,52 @@ def setup_class(cls):
1819 cls .create_from_yaml (cls , f"{ cls .tempdir } /vapi-auth-service.yaml" )
1920 assert wait_until_ready (label_selector = "app=vapi-auth" )
2021
21- def test_http_basic_authentication (self ):
22- """Test rapidast with HTTP Basic authentication configured"""
22+ @pytest .mark .parametrize (
23+ "auth_type,expected_log,header_name,header_value_func" ,
24+ [
25+ (
26+ "http-basic" ,
27+ "ZAP configured with HTTP Basic Authentication" ,
28+ "Authorization" ,
29+ lambda : f"Basic { base64 .b64encode (b'user:mypassw0rd' ).decode ('utf-8' )} " ,
30+ ),
31+ (
32+ "http-header" ,
33+ "ZAP configured with Authentication using HTTP Header" ,
34+ "Authorization" ,
35+ lambda : "MySecretHeader" ,
36+ ),
37+ ("cookie" , "ZAP configured with Cookie authentication" , "Cookie" , lambda : "session_id=abc123testcookie" ),
38+ ],
39+ )
40+ def test_authentication (self , auth_type , expected_log , header_name , header_value_func ):
41+ """Test rapidast with various authentication methods configured"""
42+
43+ self .create_from_yaml (f"{ self .tempdir } /rapidast-vapi-configmap-{ auth_type } .yaml" )
44+ self .create_from_yaml (f"{ self .tempdir } /rapidast-vapi-pod-{ auth_type } .yaml" )
2345
24- self .create_from_yaml (f"{ self .tempdir } /rapidast-vapi-configmap-http-basic.yaml" )
25- self .create_from_yaml (f"{ self .tempdir } /rapidast-vapi-pod-http-basic.yaml" )
2646 assert is_pod_with_field_selector_successfully_completed (
27- field_selector = "metadata.name=rapidast-vapi-http-basic " , timeout = 360
47+ field_selector = f "metadata.name=rapidast-vapi-{ auth_type } " , timeout = 360
2848 )
2949
30- logs = get_log_from_pod (self .tempdir , "rapidast-vapi-http-basic " , container = "rapidast" , log_format = "text" )
50+ logs = get_log_from_pod (self .tempdir , f "rapidast-vapi-{ auth_type } " , container = "rapidast" , log_format = "text" )
3151 data = get_log_from_pod (
3252 self .tempdir ,
33- "rapidast-vapi-http-basic " ,
53+ f "rapidast-vapi-{ auth_type } " ,
3454 filename_suffix = "results" ,
3555 container = "results" ,
3656 log_format = "json" ,
3757 )
3858
39- # Verify that HTTP Basic authentication was configured correctly in logs
40- assert (
41- "ZAP configured with HTTP Basic Authentication" in logs
42- ), "ZAP logs should indicate HTTP Basic authentication was configured"
43-
44- # Verify that the Authorization Basic header with correct credentials is present
45- # NOTE: "user:mypassw0rd" are dummy test credentials for e2e testing - not real secrets
46- expected_credentials = base64 .b64encode (b"user:mypassw0rd" ).decode ("utf-8" )
47- basic_auth_header_found = verify_specific_auth_header_value (
48- data , "Authorization" , f"Basic { expected_credentials } "
49- )
50- assert (
51- basic_auth_header_found
52- ), "Authorization header with correct Basic credentials should be found in scan results"
53-
54- def test_http_header_authentication (self ):
55- """Test rapidast with HTTP Header authentication configured"""
56-
57- self .create_from_yaml (f"{ self .tempdir } /rapidast-vapi-configmap-http-header.yaml" )
58- self .create_from_yaml (f"{ self .tempdir } /rapidast-vapi-pod-http-header.yaml" )
59- assert is_pod_with_field_selector_successfully_completed (
60- field_selector = "metadata.name=rapidast-vapi-http-header" , timeout = 360
61- )
62-
63- logs = get_log_from_pod (self .tempdir , "rapidast-vapi-http-header" , container = "rapidast" , log_format = "text" )
64- data = get_log_from_pod (
65- self .tempdir ,
66- "rapidast-vapi-http-header" ,
67- filename_suffix = "results" ,
68- container = "results" ,
69- log_format = "json" ,
70- )
71-
72- assert (
73- "ZAP configured with Authentication using HTTP Header" in logs
74- ), "ZAP logs should indicate HTTP Header authentication was configured"
59+ assert expected_log in logs , f"ZAP logs should indicate { auth_type } authentication was configured"
7560
76- # NOTE: "MySecretHeader" is a dummy test header value for e2e testing - not a real secret
77- custom_header_found = verify_specific_auth_header_value (data , "Authorization" , "MySecretHeader" )
61+ # Verify authentication header is present in scan results
62+ # NOTE: All authentication values are dummy test credentials - not real secrets
63+ expected_header_value = header_value_func ()
64+ auth_header_found = verify_specific_auth_header_value (data , header_name , expected_header_value )
7865 assert (
79- custom_header_found
80- ), "Authorization header with exact custom value 'MySecretHeader ' should be found in scan results"
66+ auth_header_found
67+ ), f" { header_name } header with value '{ expected_header_value } ' should be found in scan results"
8168
8269
8370def verify_specific_auth_header_value (report_data : Dict , header_name : str , expected_header_value : str ) -> bool :
0 commit comments