From aaf8bb2f871cfee36309495580539b5ef0c000bb Mon Sep 17 00:00:00 2001 From: Renuka Fernando Date: Tue, 19 Mar 2024 13:15:28 +0530 Subject: [PATCH 1/3] Send API UUID to the backend as a header Signed-off-by: Renuka Fernando --- .../choreo/connect/enforcer/constants/APIConstants.java | 1 + .../wso2/choreo/connect/enforcer/grpc/ExtAuthService.java | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java index 1f1dc4a75f..6a6664eb40 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java @@ -86,6 +86,7 @@ public class APIConstants { public static final String CONTENT_TYPE_HEADER = "Content-type"; public static final String APPLICATION_JSON = "application/json"; public static final String API_TRACE_KEY = "X-TRACE-KEY"; + public static final String CHOREO_API_UUID_HEADER = "X-Choreo-API-UUID"; public static final String X_FORWARDED_FOR = "x-forwarded-for"; public static final String PATH_HEADER = ":path"; diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java index bf3d8af7bf..dec3e43e61 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java @@ -186,6 +186,13 @@ private CheckResponse buildResponse(CheckRequest request, ResponseObject respons .setHeader(HeaderValue.newBuilder().setKey(APIConstants.API_TRACE_KEY).setValue(traceKey).build()) .build(); okResponseBuilder.addHeaders(headerValueOption); + + // Add the API UUID to the request headers tobe sent to the backend + headerValueOption = HeaderValueOption.newBuilder() + .setHeader(HeaderValue.newBuilder().setKey(APIConstants.CHOREO_API_UUID_HEADER) + .setValue(responseObject.getApiUuid()).build()).build(); + okResponseBuilder.addHeaders(headerValueOption); + return CheckResponse.newBuilder().setStatus(Status.newBuilder().setCode(Code.OK_VALUE).build()) .setOkResponse(okResponseBuilder.build()) .setDynamicMetadata(structBuilder.build()) From 63d93b49b4f875c68411df8de7571cd0eb6a439b Mon Sep 17 00:00:00 2001 From: Renuka Fernando Date: Wed, 17 Apr 2024 18:24:51 +0530 Subject: [PATCH 2/3] Rename 'X-Choreo-API-UUID' as 'X-Choreo-API-ID' Signed-off-by: Renuka Fernando --- .../wso2/choreo/connect/enforcer/constants/APIConstants.java | 2 +- .../org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java index 6a6664eb40..a0f34df780 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/constants/APIConstants.java @@ -86,7 +86,7 @@ public class APIConstants { public static final String CONTENT_TYPE_HEADER = "Content-type"; public static final String APPLICATION_JSON = "application/json"; public static final String API_TRACE_KEY = "X-TRACE-KEY"; - public static final String CHOREO_API_UUID_HEADER = "X-Choreo-API-UUID"; + public static final String CHOREO_API_ID_HEADER = "X-Choreo-API-ID"; public static final String X_FORWARDED_FOR = "x-forwarded-for"; public static final String PATH_HEADER = ":path"; diff --git a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java index dec3e43e61..599b6b8000 100644 --- a/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java +++ b/enforcer-parent/enforcer/src/main/java/org/wso2/choreo/connect/enforcer/grpc/ExtAuthService.java @@ -189,7 +189,7 @@ private CheckResponse buildResponse(CheckRequest request, ResponseObject respons // Add the API UUID to the request headers tobe sent to the backend headerValueOption = HeaderValueOption.newBuilder() - .setHeader(HeaderValue.newBuilder().setKey(APIConstants.CHOREO_API_UUID_HEADER) + .setHeader(HeaderValue.newBuilder().setKey(APIConstants.CHOREO_API_ID_HEADER) .setValue(responseObject.getApiUuid()).build()).build(); okResponseBuilder.addHeaders(headerValueOption); From 4c58759196b78dd95c7314aaf5989db321209354 Mon Sep 17 00:00:00 2001 From: Renuka Fernando Date: Thu, 18 Apr 2024 07:43:21 +0530 Subject: [PATCH 3/3] Update int tests with new header Signed-off-by: Renuka Fernando --- .../testcases/standalone/router/EnvoyHttpFilterTestCase.java | 3 ++- .../tests/testcases/withapim/EnvoyHttpFilterTestCase.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/standalone/router/EnvoyHttpFilterTestCase.java b/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/standalone/router/EnvoyHttpFilterTestCase.java index b586d1f50e..ab4fae1906 100644 --- a/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/standalone/router/EnvoyHttpFilterTestCase.java +++ b/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/standalone/router/EnvoyHttpFilterTestCase.java @@ -51,7 +51,7 @@ public void checkHeadersSentToBackend() throws Exception { // Request headers received by the backend JSONObject headersSentToBackend = new JSONObject(response.getData()); - Assert.assertEquals(headersSentToBackend.length(), 8, "Unexpected number of headers received by the backend"); + Assert.assertEquals(headersSentToBackend.length(), 9, "Unexpected number of headers received by the backend"); JSONObject headersToBackend = Utils.changeHeadersToLowerCase(headersSentToBackend); @@ -63,6 +63,7 @@ public void checkHeadersSentToBackend() throws Exception { Assert.assertNotNull(headersToBackend.get("pragma")); Assert.assertNotNull(headersToBackend.get("user-agent")); Assert.assertNotNull(headersToBackend.get("cache-control")); + Assert.assertNotNull(headersToBackend.get("x-choreo-api-id")); Assert.assertFalse(headersToBackend.has("x-envoy-original-path"), "x-envoy-original-path not removed"); Assert.assertFalse(headersToBackend.has("x-wso2-cluster-header"), "x-wso2-cluster-header not removed"); diff --git a/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/withapim/EnvoyHttpFilterTestCase.java b/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/withapim/EnvoyHttpFilterTestCase.java index 711f50bc87..754ae0fcbb 100644 --- a/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/withapim/EnvoyHttpFilterTestCase.java +++ b/integration/test-integration/src/test/java/org/wso2/choreo/connect/tests/testcases/withapim/EnvoyHttpFilterTestCase.java @@ -61,7 +61,7 @@ public void checkHeadersSentToBackend() throws Exception { // Request headers received by the backend JSONObject headersSentToBackend = new JSONObject(response.getData()); - Assert.assertEquals(headersSentToBackend.length(), 9, "Unexpected number of headers received by the backend"); + Assert.assertEquals(headersSentToBackend.length(), 10, "Unexpected number of headers received by the backend"); JSONObject headersToBackend = Utils.changeHeadersToLowerCase(headersSentToBackend); @@ -74,6 +74,7 @@ public void checkHeadersSentToBackend() throws Exception { Assert.assertNotNull(headersToBackend.get("pragma")); Assert.assertNotNull(headersToBackend.get("user-agent")); Assert.assertNotNull(headersToBackend.get("cache-control")); + Assert.assertNotNull(headersToBackend.get("x-choreo-api-id")); Assert.assertFalse(headersToBackend.has("x-envoy-original-path"), "x-envoy-original-path not removed"); Assert.assertFalse(headersToBackend.has("x-wso2-cluster-header"), "x-wso2-cluster-header not removed");