Skip to content

Commit 9416d19

Browse files
authored
Merge pull request #1823 from CrowleyRajapakse/new-main
Adding integration test for interceptor policy
2 parents f45945f + 47cc98b commit 9416d19

9 files changed

Lines changed: 365 additions & 0 deletions

File tree

gateway/it/docker-compose.test.postgres.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ services:
282282
networks:
283283
- it-gateway-runtime-network
284284

285+
# Mock Interceptor Service for interceptor-service policy testing
286+
mock-interceptor-service:
287+
container_name: it-mock-interceptor-service
288+
image: ghcr.io/wso2/api-platform/mock-interceptor-service:latest
289+
build:
290+
context: ../../tests/mock-servers/mock-interceptor-service
291+
dockerfile: Dockerfile
292+
ports:
293+
- "8087:8080"
294+
healthcheck:
295+
test: ["CMD", "wget", "--spider", "--quiet", "--tries=1", "http://127.0.0.1:8080/health"]
296+
interval: 5s
297+
timeout: 3s
298+
retries: 10
299+
start_period: 5s
300+
networks:
301+
- it-gateway-runtime-network
302+
285303
# Redis with RediSearch for semantic cache vector storage
286304
redis:
287305
container_name: it-redis

gateway/it/docker-compose.test.vhosts-multi.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ services:
224224
networks:
225225
- it-gateway-runtime-network
226226

227+
# Mock Interceptor Service for interceptor-service policy testing
228+
mock-interceptor-service:
229+
container_name: it-mock-interceptor-service
230+
image: ghcr.io/wso2/api-platform/mock-interceptor-service:latest
231+
build:
232+
context: ../../tests/mock-servers/mock-interceptor-service
233+
dockerfile: Dockerfile
234+
ports:
235+
- "8087:8080"
236+
healthcheck:
237+
test: ["CMD", "wget", "--spider", "--quiet", "--tries=1", "http://127.0.0.1:8080/health"]
238+
interval: 5s
239+
timeout: 3s
240+
retries: 10
241+
start_period: 5s
242+
networks:
243+
- it-gateway-runtime-network
244+
227245
# Redis with RediSearch for semantic cache vector storage
228246
redis:
229247
container_name: it-redis

gateway/it/docker-compose.test.vhosts-single.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,24 @@ services:
224224
networks:
225225
- it-gateway-runtime-network
226226

227+
# Mock Interceptor Service for interceptor-service policy testing
228+
mock-interceptor-service:
229+
container_name: it-mock-interceptor-service
230+
image: ghcr.io/wso2/api-platform/mock-interceptor-service:latest
231+
build:
232+
context: ../../tests/mock-servers/mock-interceptor-service
233+
dockerfile: Dockerfile
234+
ports:
235+
- "8087:8080"
236+
healthcheck:
237+
test: ["CMD", "wget", "--spider", "--quiet", "--tries=1", "http://127.0.0.1:8080/health"]
238+
interval: 5s
239+
timeout: 3s
240+
retries: 10
241+
start_period: 5s
242+
networks:
243+
- it-gateway-runtime-network
244+
227245
# Redis with RediSearch for semantic cache vector storage
228246
redis:
229247
container_name: it-redis

gateway/it/docker-compose.test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,24 @@ services:
250250
networks:
251251
- it-gateway-runtime-network
252252

253+
# Mock Interceptor Service for interceptor-service policy testing
254+
mock-interceptor-service:
255+
container_name: it-mock-interceptor-service
256+
image: ghcr.io/wso2/api-platform/mock-interceptor-service:latest
257+
build:
258+
context: ../../tests/mock-servers/mock-interceptor-service
259+
dockerfile: Dockerfile
260+
ports:
261+
- "8087:8080"
262+
healthcheck:
263+
test: ["CMD", "wget", "--spider", "--quiet", "--tries=1", "http://127.0.0.1:8080/health"]
264+
interval: 5s
265+
timeout: 3s
266+
retries: 10
267+
start_period: 5s
268+
networks:
269+
- it-gateway-runtime-network
270+
253271
# Redis with RediSearch for semantic cache vector storage
254272
redis:
255273
container_name: it-redis
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
Feature: Interceptor Service Policy Integration Tests
2+
Validate interceptor-service policy for request/response mutation and direct responses
3+
4+
Background:
5+
Given the gateway services are running
6+
And I authenticate using basic auth as "admin"
7+
8+
Scenario: Request interceptor mutates path, headers, and body before upstream call
9+
When I deploy this API configuration:
10+
"""
11+
apiVersion: gateway.api-platform.wso2.com/v1alpha1
12+
kind: RestApi
13+
metadata:
14+
name: interceptor-request-mutation-api
15+
spec:
16+
displayName: Interceptor Request Mutation API
17+
version: v1.0
18+
context: /interceptor-request/$version
19+
upstream:
20+
main:
21+
url: http://echo-backend:80
22+
operations:
23+
- method: POST
24+
path: /mutate
25+
policies:
26+
- name: interceptor-service
27+
version: v0
28+
params:
29+
endpoint: http://mock-interceptor-service:8080
30+
request:
31+
includeRequestHeaders: true
32+
includeRequestBody: true
33+
passthroughOnError: false
34+
"""
35+
Then the response should be successful
36+
And I wait for policy snapshot sync
37+
And I set header "Content-Type" to "application/json"
38+
When I send a POST request to "http://localhost:8080/interceptor-request/v1.0/mutate" with body:
39+
"""
40+
{"client":"payload"}
41+
"""
42+
Then the response status code should be 200
43+
And the JSON response field "url" should contain "/anything/intercepted"
44+
And the JSON response field "headers.X-Interceptor-Request" should be "true"
45+
And the JSON response field "data" should contain "mutated-by-interceptor"
46+
# Cleanup
47+
When I delete the API "interceptor-request-mutation-api"
48+
Then the response should be successful
49+
50+
Scenario: Request interceptor short-circuits with direct response
51+
When I deploy this API configuration:
52+
"""
53+
apiVersion: gateway.api-platform.wso2.com/v1alpha1
54+
kind: RestApi
55+
metadata:
56+
name: interceptor-direct-respond-api
57+
spec:
58+
displayName: Interceptor Direct Respond API
59+
version: v1.0
60+
context: /interceptor-direct/$version
61+
upstream:
62+
main:
63+
url: http://echo-backend:80
64+
operations:
65+
- method: GET
66+
path: /block
67+
policies:
68+
- name: interceptor-service
69+
version: v0
70+
params:
71+
endpoint: http://mock-interceptor-service:8080
72+
request:
73+
includeRequestHeaders: true
74+
includeRequestBody: false
75+
passthroughOnError: false
76+
"""
77+
Then the response should be successful
78+
And I wait for policy snapshot sync
79+
When I send a GET request to "http://localhost:8080/interceptor-direct/v1.0/block"
80+
Then the response status code should be 403
81+
And the response header "X-Interceptor-Decision" should be "blocked"
82+
And the response body should contain "blocked by interceptor"
83+
# Cleanup
84+
Given I authenticate using basic auth as "admin"
85+
When I delete the API "interceptor-direct-respond-api"
86+
Then the response should be successful
87+
88+
Scenario: Response interceptor rewrites status, headers, and body
89+
When I deploy this API configuration:
90+
"""
91+
apiVersion: gateway.api-platform.wso2.com/v1alpha1
92+
kind: RestApi
93+
metadata:
94+
name: interceptor-response-mutation-api
95+
spec:
96+
displayName: Interceptor Response Mutation API
97+
version: v1.0
98+
context: /interceptor-response/$version
99+
upstream:
100+
main:
101+
url: http://echo-backend:80
102+
operations:
103+
- method: GET
104+
path: /response-rewrite
105+
policies:
106+
- name: interceptor-service
107+
version: v0
108+
params:
109+
endpoint: http://mock-interceptor-service:8080
110+
request:
111+
includeRequestHeaders: true
112+
includeRequestBody: false
113+
passthroughOnError: false
114+
response:
115+
includeRequestHeaders: true
116+
includeRequestBody: false
117+
includeResponseHeaders: true
118+
includeResponseBody: true
119+
passthroughOnError: false
120+
"""
121+
Then the response should be successful
122+
And I wait for policy snapshot sync
123+
When I send a GET request to "http://localhost:8080/interceptor-response/v1.0/response-rewrite"
124+
Then the response status code should be 202
125+
And the response header "X-Interceptor-Response" should be "true"
126+
And the response header "X-Interceptor-Trace" should be "request-phase"
127+
And the response body should contain "response-overridden"
128+
# Cleanup
129+
Given I authenticate using basic auth as "admin"
130+
When I delete the API "interceptor-response-mutation-api"
131+
Then the response should be successful

gateway/it/suite_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func getFeaturePaths() []string {
125125
"features/api-error-responses.feature",
126126
"features/api-keys.feature",
127127
"features/api-with-policies.feature",
128+
"features/interceptor-service.feature",
128129
"features/llm-proxies.feature",
129130
"features/startup-db-bootstrap.feature",
130131
"features/search-deployments.feature",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:1.23-alpine AS builder
2+
3+
WORKDIR /app
4+
5+
COPY go.mod ./
6+
RUN go mod download
7+
8+
COPY main.go ./
9+
RUN CGO_ENABLED=0 GOOS=linux go build -o mock-interceptor-service main.go
10+
11+
FROM alpine:latest
12+
13+
RUN apk --no-cache add ca-certificates
14+
15+
WORKDIR /root/
16+
COPY --from=builder /app/mock-interceptor-service .
17+
18+
EXPOSE 8080
19+
20+
CMD ["./mock-interceptor-service"]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/wso2/api-platform/tests/mock-servers/mock-interceptor-service
2+
3+
go 1.23

0 commit comments

Comments
 (0)