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
5 changes: 5 additions & 0 deletions .changeset/proxy-fetch-undici-version-mismatch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slack/slack-github-action": patch
---

fix: send requests through the configured proxy using the undici version that matches the node runtime
3 changes: 3 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ updates:
versions:
- "25.x"
- "26.x"
- dependency-name: "undici" # https://undici.nodejs.org/#long-term-support
versions:
- "8.x"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"flat": "^6.0.1",
"js-yaml": "^5.5.0",
"markup-js": "^1.5.21",
"undici": "^8.12.4"
"undici": "^7.30.2"
},
"overrides": {
"undici-types": "$undici"
Expand Down
66 changes: 66 additions & 0 deletions test/proxies.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import assert from "node:assert";
import http from "node:http";
import { beforeEach, describe, it } from "node:test";
import { errors as undiciErrors } from "undici";
import Config from "../src/config.js";
import SlackError from "../src/errors.js";
import { fetch, proxies } from "../src/proxies.js";
Expand All @@ -20,6 +22,70 @@ describe("proxies", () => {
assert.strictEqual(typeof fetchFn, "function");
});

it("dispatches requests through the proxy with correct request handler", async () => {
mocks.inputs.set("method", "chat.postMessage");
mocks.inputs.set("proxy", "http://127.0.0.1:1");
mocks.inputs.set("token", "xoxb-example");
mocks.fetch.mock.restore();
const config = new Config(mocks.core);
const fetchFn = fetch(config);
await assert.rejects(
// ".invalid" is reserved by RFC 2606 to never resolve.
fetchFn("https://slack-github-action.invalid/api/chat.postMessage", {
method: "POST",
}),
(err) => {
assert.ok(!(err.cause instanceof undiciErrors.InvalidArgumentError));
return true;
},
);
});

/**
* @see {@link https://github.com/slackapi/slack-github-action/pull/675}
*/
it("sends form data through the proxy as a multipart body", async () => {
const received = {};
const server = http.createServer((req, res) => {
const chunks = [];
req.on("data", (chunk) => chunks.push(chunk));
req.on("end", () => {
received.host = req.headers.host;
received.type = req.headers["content-type"];
received.body = Buffer.concat(chunks).toString();
res.end("{}");
});
});
server.on("connect", (req, socket, head) => {
received.tunnel = req.url;
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
socket.unshift(head);
server.emit("connection", socket);
});
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
mocks.inputs.set("method", "files.uploadV2");
mocks.inputs.set("proxy", `http://127.0.0.1:${server.address().port}`);
mocks.inputs.set("token", "xoxb-example");
mocks.fetch.mock.restore();
mocks.fs.readFileSync.mock.restore();
const config = new Config(mocks.core);
const fetchFn = fetch(config);
const body = new FormData();
body.append("file", new Blob(["example"]), "example.txt");
try {
await fetchFn("http://slack-github-action.invalid/upload", {
method: "POST",
body,
});
} finally {
server.closeAllConnections();
server.close();
}
assert.strictEqual(received.host, "slack-github-action.invalid");
assert.match(received.type, /^multipart\/form-data; boundary=/);
assert.match(received.body, /filename="example.txt"[\s\S]*example/);
});

it("returns undefined when no proxy is configured", async () => {
mocks.inputs.set("method", "chat.postMessage");
mocks.inputs.set("token", "xoxb-example");
Expand Down
Loading