44import fnmatch
55import pytest
66
7- from agentex . lib . types . agent_configs import CustomHeadersConfig
7+ # No longer need CustomHeadersConfig - using simple lists now
88
99
10- class TestCustomHeadersConfig :
11- """Test CustomHeadersConfig functionality."""
10+ class TestHeaderAllowlist :
11+ """Test header allowlist functionality."""
1212
13- def test_custom_headers_config_creation (self ) -> None :
14- """Test that CustomHeadersConfig can be created with defaults."""
15- config = CustomHeadersConfig ()
16-
17- assert config .strategy == "allowlist"
18- assert config .allowed_headers == []
19-
20- def test_custom_headers_config_with_headers (self ) -> None :
21- """Test CustomHeadersConfig with allowed headers."""
22- config = CustomHeadersConfig (
23- allowed_headers = ["x-user-email" , "x-tenant-id" ]
24- )
25-
26- assert config .strategy == "allowlist"
27- assert config .allowed_headers == ["x-user-email" , "x-tenant-id" ]
13+ def test_allowlist_creation (self ) -> None :
14+ """Test that allowlists can be created as simple lists."""
15+ allowlist = ["x-user-email" , "x-tenant-id" ]
16+ assert len (allowlist ) == 2
17+ assert "x-user-email" in allowlist
18+ assert "x-tenant-id" in allowlist
19+
20+ def test_empty_allowlist (self ) -> None :
21+ """Test empty allowlist behavior."""
22+ allowlist : list [str ] = []
23+ assert len (allowlist ) == 0
2824
2925
3026def filter_headers_standalone (
3127 headers : dict [str , str ] | None ,
32- config : CustomHeadersConfig | None
28+ allowlist : list [ str ] | None
3329) -> dict [str , str ]:
3430 """Standalone header filtering function matching the production implementation."""
3531 if not headers :
3632 return {}
3733
38- # Pass-through behavior: if no config , forward all headers
39- if config is None :
34+ # Pass-through behavior: if no allowlist , forward all headers
35+ if allowlist is None :
4036 return headers
4137
4238 # Apply filtering based on allowlist
43- if not config . allowed_headers :
39+ if not allowlist :
4440 return {}
4541
4642 filtered = {}
4743 for header_name , header_value in headers .items ():
4844 # Check against allowlist patterns (case-insensitive)
4945 header_allowed = False
50- for pattern in config . allowed_headers :
46+ for pattern in allowlist :
5147 if fnmatch .fnmatch (header_name .lower (), pattern .lower ()):
5248 header_allowed = True
5349 break
@@ -63,42 +59,42 @@ class TestHeaderFiltering:
6359
6460 def test_filter_headers_no_headers (self ) -> None :
6561 """Test header filtering with no input headers."""
66- config = CustomHeadersConfig ( allowed_headers = ["x-user-email" ])
67- result = filter_headers_standalone (None , config )
62+ allowlist = ["x-user-email" ]
63+ result = filter_headers_standalone (None , allowlist )
6864 assert result == {}
6965
70- result = filter_headers_standalone ({}, config )
66+ result = filter_headers_standalone ({}, allowlist )
7167 assert result == {}
7268
7369 def test_filter_headers_pass_through_by_default (self ) -> None :
74- """Test header filtering with no config (pass-through behavior)."""
70+ """Test header filtering with no allowlist (pass-through behavior)."""
7571 headers = {
7672 "x-user-email" :
"[email protected] " ,
7773 "x-admin-token" : "secret" ,
7874 "authorization" : "Bearer token" ,
7975 "x-custom-header" : "value"
8076 }
8177 result = filter_headers_standalone (headers , None )
82- # All headers should pass through when no config is provided
78+ # All headers should pass through when no allowlist is provided
8379 assert result == headers
8480
8581 def test_filter_headers_empty_allowlist (self ) -> None :
86- """Test header filtering with empty allowed headers ."""
87- config = CustomHeadersConfig ( allowed_headers = [])
82+ """Test header filtering with empty allowlist ."""
83+ allowlist : list [ str ] = []
8884 headers = {
"x-user-email" :
"[email protected] " ,
"x-admin-token" :
"secret" }
89- result = filter_headers_standalone (headers , config )
85+ result = filter_headers_standalone (headers , allowlist )
9086 assert result == {}
9187
9288 def test_filter_headers_allowed_headers (self ) -> None :
93- """Test header filtering with allowed headers ."""
94- config = CustomHeadersConfig ( allowed_headers = ["x-user-email" , "x-tenant-id" ])
89+ """Test header filtering with allowlist ."""
90+ allowlist = ["x-user-email" , "x-tenant-id" ]
9591 headers = {
9692 "x-user-email" :
"[email protected] " ,
9793 "x-tenant-id" : "tenant123" ,
9894 "x-admin-token" : "secret" , # Should be filtered out
9995 "content-type" : "application/json" # Should be filtered out
10096 }
101- result = filter_headers_standalone (headers , config )
97+ result = filter_headers_standalone (headers , allowlist )
10298
10399 expected = {
104100 "x-user-email" :
"[email protected] " ,
@@ -108,14 +104,14 @@ def test_filter_headers_allowed_headers(self) -> None:
108104
109105 def test_filter_headers_case_insensitive_patterns (self ) -> None :
110106 """Test header filtering with case-insensitive pattern matching."""
111- config = CustomHeadersConfig ( allowed_headers = ["X-User-Email" , "x-tenant-*" ])
107+ allowlist = ["X-User-Email" , "x-tenant-*" ]
112108 headers = {
113109 "x-user-email" :
"[email protected] " ,
# Should match X-User-Email 114110 "X-TENANT-ID" : "tenant123" , # Should match x-tenant-*
115111 "x-tenant-name" : "acme" , # Should match x-tenant-*
116112 "x-admin-token" : "secret" # Should be filtered out
117113 }
118- result = filter_headers_standalone (headers , config )
114+ result = filter_headers_standalone (headers , allowlist )
119115
120116 expected = {
121117 "x-user-email" :
"[email protected] " ,
@@ -126,7 +122,7 @@ def test_filter_headers_case_insensitive_patterns(self) -> None:
126122
127123 def test_filter_headers_wildcard_patterns (self ) -> None :
128124 """Test header filtering with wildcard patterns."""
129- config = CustomHeadersConfig ( allowed_headers = ["x-user-*" , "authorization" ])
125+ allowlist = ["x-user-*" , "authorization" ]
130126 headers = {
131127 "x-user-id" : "123" ,
132128 "x-user-email" :
"[email protected] " ,
@@ -135,7 +131,7 @@ def test_filter_headers_wildcard_patterns(self) -> None:
135131 "x-system-info" : "blocked" , # Should be filtered out
136132 "content-type" : "application/json" # Should be filtered out
137133 }
138- result = filter_headers_standalone (headers , config )
134+ result = filter_headers_standalone (headers , allowlist )
139135
140136 expected = {
141137 "x-user-id" : "123" ,
@@ -147,7 +143,7 @@ def test_filter_headers_wildcard_patterns(self) -> None:
147143
148144 def test_filter_headers_complex_patterns (self ) -> None :
149145 """Test header filtering with complex fnmatch patterns."""
150- config = CustomHeadersConfig ( allowed_headers = ["x-tenant-*" , "x-user-[abc]*" , "auth*" ])
146+ allowlist = ["x-tenant-*" , "x-user-[abc]*" , "auth*" ]
151147 headers = {
152148 "x-tenant-id" : "tenant1" , # Matches x-tenant-*
153149 "x-tenant-name" : "acme" , # Matches x-tenant-*
@@ -158,7 +154,7 @@ def test_filter_headers_complex_patterns(self) -> None:
158154 "authenticate" : "digest" , # Matches auth*
159155 "content-type" : "json" , # No match
160156 }
161- result = filter_headers_standalone (headers , config )
157+ result = filter_headers_standalone (headers , allowlist )
162158
163159 expected = {
164160 "x-tenant-id" : "tenant1" ,
@@ -172,7 +168,7 @@ def test_filter_headers_complex_patterns(self) -> None:
172168
173169 def test_filter_headers_all_types (self ) -> None :
174170 """Test that any header type can be allowed, not just x- prefixed ones."""
175- config = CustomHeadersConfig ( allowed_headers = ["authorization" , "accept-language" , "custom-*" ])
171+ allowlist = ["authorization" , "accept-language" , "custom-*" ]
176172 headers = {
177173 "authorization" : "Bearer token" ,
178174 "accept-language" : "en-US" ,
@@ -181,7 +177,7 @@ def test_filter_headers_all_types(self) -> None:
181177 "content-type" : "application/json" , # Should be blocked
182178 "x-blocked" : "value" # Should be blocked
183179 }
184- result = filter_headers_standalone (headers , config )
180+ result = filter_headers_standalone (headers , allowlist )
185181
186182 expected = {
187183 "authorization" : "Bearer token" ,
0 commit comments