Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ quarkus.oidc-client.service5_oauth2.grant.type=client
quarkus.oidc-client.service5_oauth2.credentials.client-secret.method=basic
quarkus.oidc-client.service5_oauth2.credentials.client-secret.value=secret

quarkus.keycloak.devservices.enabled=false
quarkus.keycloak.devservices.enabled=false

# Slack OpenAPI
quarkus.openapi-generator.codegen.spec.slack_openapi_json.base-package=org.acme.openapi.slack
quarkus.openapi-generator.slack_openapi_json.auth.bearerAuth.bearer-token=12345-TOKEN

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));
}
}

}
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();
}
}
}