|
| 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 |
0 commit comments