-
Notifications
You must be signed in to change notification settings - Fork 113
NO-ISSUE: Improving IT to check for duplicated headers #1209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ricardozanini
merged 1 commit into
quarkiverse:main
from
ricardozanini:check-double-header
Jun 19, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
client/integration-tests/security/src/main/openapi/slack-openapi.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| { | ||
| "openapi": "3.0.1", | ||
| "info": { | ||
| "title": "Slack Actions for Slack API", | ||
| "description": "Slack Actions Slack API", | ||
| "version": "0.0.1" | ||
| }, | ||
| "paths": { | ||
| "/api/chat.postMessage": { | ||
| "post": { | ||
| "tags": [ | ||
| "Message" | ||
| ], | ||
| "summary": "Send slack message", | ||
| "description": "Send slack message to selected public channel", | ||
| "operationId": "sendSlackMessage", | ||
| "requestBody": { | ||
| "description": "Input parameters for the action sendSlackMessage", | ||
| "required": true, | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/SendMessageRequest" | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "responses": { | ||
| "default": { | ||
| "description": "Send Message Response", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "$ref": "#/components/schemas/SendMessageResponse" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "deprecated": false, | ||
| "security": [ | ||
| { | ||
| "bearerAuth": [] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "components": { | ||
| "securitySchemes": { | ||
| "basicAuth": { | ||
| "type": "http", | ||
| "scheme": "basic" | ||
| }, | ||
| "bearerAuth": { | ||
| "type": "http", | ||
| "scheme": "bearer" | ||
| } | ||
| }, | ||
| "schemas": { | ||
| "ErrorCollection": { | ||
| "type": "object" | ||
| }, | ||
| "SendMessageRequest": { | ||
| "type": "object", | ||
| "properties": { | ||
| "text": { | ||
| "type": "string" | ||
| }, | ||
| "channel": { | ||
| "type": "string" | ||
| } | ||
| } | ||
| }, | ||
| "SendMessageResponse": { | ||
| "type": "object", | ||
| "properties": { | ||
| "ok": { | ||
| "type": "boolean", | ||
| "description": "Indicates if the message was posted.", | ||
| "readOnly": true | ||
| }, | ||
| "channel": { | ||
| "type": "string", | ||
| "description": "The ID of the channel the message was posted.", | ||
| "readOnly": true | ||
| }, | ||
| "response_metadata": { | ||
| "type": "object", | ||
| "description": "The metadata of response details", | ||
| "readOnly": true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...c/test/java/io/quarkiverse/openapi/generator/it/security/CheckHeadersBearerTokenTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package io.quarkiverse.openapi.generator.it.security; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import jakarta.inject.Inject; | ||
|
|
||
| import org.acme.openapi.slack.api.MessageApi; | ||
| import org.acme.openapi.slack.model.SendMessageRequest; | ||
| import org.acme.openapi.slack.model.SendMessageResponse; | ||
| import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.github.tomakehurst.wiremock.WireMockServer; | ||
| import com.github.tomakehurst.wiremock.client.WireMock; | ||
| import com.github.tomakehurst.wiremock.verification.LoggedRequest; | ||
|
|
||
| import io.quarkus.test.common.QuarkusTestResource; | ||
| import io.quarkus.test.junit.QuarkusTest; | ||
|
|
||
| @QuarkusTestResource(WiremockSlackServer.class) | ||
| @QuarkusTest | ||
| public class CheckHeadersBearerTokenTest { | ||
|
|
||
| // injected by quarkus test resource | ||
| WireMockServer slackServer; | ||
|
|
||
| // generated by OpenAPI | ||
| @RestClient | ||
| @Inject | ||
| MessageApi messageApi; | ||
|
|
||
| @Test | ||
| void testNoDuplicateHeaders() { | ||
| SendMessageRequest sendMessageRequest = new SendMessageRequest(); | ||
| sendMessageRequest.setChannel("#test"); | ||
| sendMessageRequest.setText("Hello World"); | ||
| SendMessageResponse response = messageApi.sendSlackMessage(sendMessageRequest); | ||
| Assertions.assertNotNull(response, "Expected a non-null response"); | ||
|
|
||
| List<LoggedRequest> requests = slackServer.findAll( | ||
| WireMock.postRequestedFor(WireMock.urlEqualTo("/api/chat.postMessage"))); | ||
| Assertions.assertEquals(1, requests.size(), "Expected exactly one HTTP request"); | ||
|
|
||
| LoggedRequest req = requests.get(0); | ||
|
|
||
| String contentLength = req.getHeader("Content-Length"); | ||
| Assertions.assertNotNull(contentLength, "Content-Length header should be present"); | ||
| Assertions.assertTrue( | ||
| Integer.parseInt(contentLength) > 0, | ||
| "Content-Length should be a positive integer"); | ||
|
|
||
| for (String headerName : req.getAllHeaderKeys()) { | ||
| List<String> values = req.getHeaders().getHeader(headerName).values(); | ||
| Assertions.assertEquals( | ||
| 1, | ||
| values.size(), | ||
| () -> String.format( | ||
| "Header '%s' is duplicated; values: %s", | ||
| headerName, values)); | ||
| } | ||
| } | ||
|
|
||
| } | ||
44 changes: 44 additions & 0 deletions
44
...urity/src/test/java/io/quarkiverse/openapi/generator/it/security/WiremockSlackServer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package io.quarkiverse.openapi.generator.it.security; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.post; | ||
| import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import com.github.tomakehurst.wiremock.WireMockServer; | ||
| import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
|
|
||
| import io.quarkus.test.common.QuarkusTestResourceLifecycleManager; | ||
|
|
||
| public class WiremockSlackServer implements QuarkusTestResourceLifecycleManager { | ||
| public static final String URL_KEY = "quarkus.rest-client.slack_openapi_json.url"; | ||
| private WireMockServer wireMockServer; | ||
|
|
||
| @Override | ||
| public Map<String, String> start() { | ||
| wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig().dynamicPort()); | ||
| wireMockServer.start(); | ||
|
|
||
| wireMockServer.stubFor(post(urlPathEqualTo("/api/chat.postMessage")) | ||
| .willReturn(aResponse() | ||
| .withStatus(200) | ||
| .withHeader("Content-Type", "application/json") | ||
| .withBody( | ||
| "{\"ok\": \"true\", \"channel\": \"#test\", \"response_metadata\": {}}"))); | ||
|
|
||
| return Map.of(URL_KEY, wireMockServer.baseUrl()); | ||
| } | ||
|
|
||
| @Override | ||
| public void inject(TestInjector testInjector) { | ||
|
||
| testInjector.injectIntoFields(wireMockServer, f -> f.getName().equals("slackServer")); | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| if (null != wireMockServer) { | ||
| wireMockServer.stop(); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.