1+ # --------------------------------------------------------------------
2+ # Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3+ #
4+ # WSO2 LLC. licenses this file to you under the Apache License,
5+ # Version 2.0 (the "License"); you may not use this file except
6+ # in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing,
12+ # software distributed under the License is distributed on an
13+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+ # KIND, either express or implied. See the License for the
15+ # specific language governing permissions and limitations
16+ # under the License.
17+ # --------------------------------------------------------------------
18+
19+ @analytics-header-filter
20+ Feature : Analytics Header Filter Policy
21+ As an API developer
22+ I want to control which headers are included in analytics data
23+ So that I can prevent sensitive or noisy headers from being collected
24+
25+ Background :
26+ Given the gateway services are running
27+
28+ Scenario : Both request and response headers filtering configured
29+ Given I authenticate using basic auth as "admin"
30+ When I deploy this API configuration:
31+ """
32+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
33+ kind: RestApi
34+ metadata:
35+ name: analytics-header-filter-both-api
36+ spec:
37+ displayName: Analytics Header Filter Both API
38+ version: v1.0
39+ context: /analytics-both/$version
40+ upstream:
41+ main:
42+ url: http://sample-backend:9080/api/v1
43+ operations:
44+ - method: GET
45+ path: /test
46+ policies:
47+ - name: analytics-header-filter
48+ version: v0.1.0
49+ params:
50+ requestHeadersToFilter:
51+ operation: deny
52+ headers:
53+ - "authorization"
54+ - "x-api-key"
55+ responseHeadersToFilter:
56+ operation: allow
57+ headers:
58+ - "content-type"
59+ - "x-custom-header"
60+ """
61+ Then the response should be successful
62+ And the response should be valid JSON
63+ And the JSON response field "status" should be "success"
64+ And I wait for the endpoint "http://localhost:8080/analytics-both/v1.0/test" to be ready
65+
66+ When I set header "Authorization" to "Bearer test-token"
67+ And I set header "X-API-Key" to "secret-key"
68+ And I set header "User-Agent" to "test-client"
69+ And I send a GET request to "http://localhost:8080/analytics-both/v1.0/test"
70+ Then the response should be successful
71+ And the response should be valid JSON
72+
73+ Scenario : Only request headers filtering configured
74+ Given I authenticate using basic auth as "admin"
75+ When I deploy this API configuration:
76+ """
77+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
78+ kind: RestApi
79+ metadata:
80+ name: analytics-header-filter-request-api
81+ spec:
82+ displayName: Analytics Header Filter Request API
83+ version: v1.0
84+ context: /analytics-request/$version
85+ upstream:
86+ main:
87+ url: http://sample-backend:9080/api/v1
88+ operations:
89+ - method: POST
90+ path: /data
91+ policies:
92+ - name: analytics-header-filter
93+ version: v0.1.0
94+ params:
95+ requestHeadersToFilter:
96+ operation: allow
97+ headers:
98+ - "content-type"
99+ - "user-agent"
100+ """
101+ Then the response should be successful
102+ And the response should be valid JSON
103+ And the JSON response field "status" should be "success"
104+ And I wait for the endpoint "http://localhost:8080/analytics-request/v1.0/data" to be ready
105+
106+ When I set header "Content-Type" to "application/json"
107+ And I set header "User-Agent" to "test-client"
108+ And I set header "Authorization" to "Bearer secret-token"
109+ And I send a POST request to "http://localhost:8080/analytics-request/v1.0/data" with body:
110+ """
111+ {"message": "test data"}
112+ """
113+ Then the response should be successful
114+ And the response should be valid JSON
115+
116+ Scenario : Only response headers filtering configured
117+ Given I authenticate using basic auth as "admin"
118+ When I deploy this API configuration:
119+ """
120+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
121+ kind: RestApi
122+ metadata:
123+ name: analytics-header-filter-response-api
124+ spec:
125+ displayName: Analytics Header Filter Response API
126+ version: v1.0
127+ context: /analytics-response/$version
128+ upstream:
129+ main:
130+ url: http://sample-backend:9080/api/v1
131+ operations:
132+ - method: GET
133+ path: /headers
134+ policies:
135+ - name: analytics-header-filter
136+ version: v0.1.0
137+ params:
138+ responseHeadersToFilter:
139+ operation: deny
140+ headers:
141+ - "server"
142+ - "x-powered-by"
143+ - "x-internal-debug"
144+ """
145+ Then the response should be successful
146+ And the response should be valid JSON
147+ And the JSON response field "status" should be "success"
148+ And I wait for the endpoint "http://localhost:8080/analytics-response/v1.0/headers" to be ready
149+
150+ When I send a GET request to "http://localhost:8080/analytics-response/v1.0/headers"
151+ Then the response should be successful
152+ And the response should be valid JSON
153+
154+ Scenario : Invalid policy configuration - missing operation field
155+ Given I authenticate using basic auth as "admin"
156+ When I deploy this API configuration:
157+ """
158+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
159+ kind: RestApi
160+ metadata:
161+ name: analytics-header-filter-invalid-api
162+ spec:
163+ displayName: Analytics Header Filter Invalid API
164+ version: v1.0
165+ context: /analytics-invalid/$version
166+ upstream:
167+ main:
168+ url: http://sample-backend:9080/api/v1
169+ operations:
170+ - method: GET
171+ path: /test
172+ policies:
173+ - name: analytics-header-filter
174+ version: v0.1.0
175+ params:
176+ requestHeadersToFilter:
177+ headers:
178+ - "authorization"
179+ """
180+ Then the response status code should be 400
181+ And the response should be valid JSON
182+ And the JSON response field "status" should be "error"
183+ And the response body should contain "operation"
184+
185+ Scenario : Invalid policy configuration - invalid operation value
186+ Given I authenticate using basic auth as "admin"
187+ When I deploy this API configuration:
188+ """
189+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
190+ kind: RestApi
191+ metadata:
192+ name: analytics-header-filter-invalid-op-api
193+ spec:
194+ displayName: Analytics Header Filter Invalid Op API
195+ version: v1.0
196+ context: /analytics-invalid-op/$version
197+ upstream:
198+ main:
199+ url: http://sample-backend:9080/api/v1
200+ operations:
201+ - method: GET
202+ path: /test
203+ policies:
204+ - name: analytics-header-filter
205+ version: v0.1.0
206+ params:
207+ requestHeadersToFilter:
208+ operation: invalid
209+ headers:
210+ - "authorization"
211+ """
212+ Then the response status code should be 400
213+ And the response should be valid JSON
214+ And the JSON response field "status" should be "error"
215+ And the response body should contain "operation"
216+
217+ Scenario : Invalid policy configuration - missing headers field
218+ Given I authenticate using basic auth as "admin"
219+ When I deploy this API configuration:
220+ """
221+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
222+ kind: RestApi
223+ metadata:
224+ name: analytics-header-filter-no-headers-api
225+ spec:
226+ displayName: Analytics Header Filter No Headers API
227+ version: v1.0
228+ context: /analytics-no-headers/$version
229+ upstream:
230+ main:
231+ url: http://sample-backend:9080/api/v1
232+ operations:
233+ - method: GET
234+ path: /test
235+ policies:
236+ - name: analytics-header-filter
237+ version: v0.1.0
238+ params:
239+ responseHeadersToFilter:
240+ operation: allow
241+ """
242+ Then the response status code should be 400
243+ And the response should be valid JSON
244+ And the JSON response field "status" should be "error"
245+ And the response body should contain "headers"
246+
247+ Scenario : Case-insensitive header matching with allow operation
248+ Given I authenticate using basic auth as "admin"
249+ When I deploy this API configuration:
250+ """
251+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
252+ kind: RestApi
253+ metadata:
254+ name: analytics-header-filter-case-api
255+ spec:
256+ displayName: Analytics Header Filter Case API
257+ version: v1.0
258+ context: /analytics-case/$version
259+ upstream:
260+ main:
261+ url: http://sample-backend:9080/api/v1
262+ operations:
263+ - method: GET
264+ path: /case-test
265+ policies:
266+ - name: analytics-header-filter
267+ version: v0.1.0
268+ params:
269+ requestHeadersToFilter:
270+ operation: allow
271+ headers:
272+ - "Content-Type"
273+ - "USER-AGENT"
274+ - "x-custom-header"
275+ """
276+ Then the response should be successful
277+ And the response should be valid JSON
278+ And the JSON response field "status" should be "success"
279+ And I wait for the endpoint "http://localhost:8080/analytics-case/v1.0/case-test" to be ready
280+
281+ When I set header "content-type" to "application/json"
282+ And I set header "user-agent" to "test-client"
283+ And I set header "X-Custom-Header" to "test-value"
284+ And I set header "Authorization" to "Bearer secret"
285+ And I send a GET request to "http://localhost:8080/analytics-case/v1.0/case-test"
286+ Then the response should be successful
287+ And the response should be valid JSON
288+
289+ Scenario : Empty headers array with deny operation
290+ Given I authenticate using basic auth as "admin"
291+ When I deploy this API configuration:
292+ """
293+ apiVersion: gateway.api-platform.wso2.com/v1alpha1
294+ kind: RestApi
295+ metadata:
296+ name: analytics-header-filter-empty-api
297+ spec:
298+ displayName: Analytics Header Filter Empty API
299+ version: v1.0
300+ context: /analytics-empty/$version
301+ upstream:
302+ main:
303+ url: http://sample-backend:9080/api/v1
304+ operations:
305+ - method: GET
306+ path: /empty-test
307+ policies:
308+ - name: analytics-header-filter
309+ version: v0.1.0
310+ params:
311+ requestHeadersToFilter:
312+ operation: deny
313+ headers: []
314+ responseHeadersToFilter:
315+ operation: allow
316+ headers: []
317+ """
318+ Then the response should be successful
319+ And the response should be valid JSON
320+ And the JSON response field "status" should be "success"
321+ And I wait for the endpoint "http://localhost:8080/analytics-empty/v1.0/empty-test" to be ready
322+
323+ When I set header "Content-Type" to "application/json"
324+ And I set header "Authorization" to "Bearer token"
325+ And I send a GET request to "http://localhost:8080/analytics-empty/v1.0/empty-test"
326+ Then the response should be successful
327+ And the response should be valid JSON
0 commit comments