Skip to content

Commit 3186659

Browse files
authored
Merge pull request #7 from Traction-Rec/fix/resilient-cleanup-test
fix: retry GitHub webhook delivery on 401 or missing secret
2 parents e8a76d8 + c2533d8 commit 3186659

5 files changed

Lines changed: 408 additions & 65 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "n8n-slack-unihook"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition = "2024"
55
description = "A Slack event router for n8n that enables multiple workflows to share a single Slack app webhook"
66
license = "MIT"
@@ -45,6 +45,8 @@ reqwest = { version = "0.13", features = ["json", "cookies"] }
4545
hmac = "0.12"
4646
sha2 = "0.10"
4747
hex = "0.4"
48+
# Mock HTTP server for unit tests
49+
wiremock = "0.6"
4850

4951
[[test]]
5052
name = "integration"

src/n8n/client.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl N8nClient {
147147
events = ?trigger.events,
148148
owner = %trigger.owner,
149149
repository = %trigger.repository,
150+
has_webhook_secret = trigger.webhook_secret.is_some(),
150151
"Found GitHub trigger"
151152
);
152153
triggers.push(trigger);
@@ -215,12 +216,15 @@ impl N8nClient {
215216
/// The `raw_body` parameter is the exact raw request body from the source
216217
/// (Slack, Jira, etc.). This is forwarded as-is (not re-serialized) to
217218
/// preserve the exact bytes for signature/authentication verification by n8n.
219+
///
220+
/// Returns the HTTP status code from n8n's response on success, or an error
221+
/// if the request couldn't be sent at all (connection failure, DNS, etc.).
218222
pub async fn forward_event(
219223
&self,
220224
webhook_url: &str,
221225
raw_body: &str,
222226
headers: &HeaderMap,
223-
) -> Result<(), N8nClientError> {
227+
) -> Result<u16, N8nClientError> {
224228
debug!(
225229
webhook_url = %webhook_url,
226230
forwarded_headers = headers.len(),
@@ -249,16 +253,18 @@ impl N8nClient {
249253
N8nClientError::RequestFailed(e.to_string())
250254
})?;
251255

252-
if !response.status().is_success() {
253-
let status = response.status();
256+
let status = response.status();
257+
let status_code = status.as_u16();
258+
259+
if !status.is_success() {
254260
warn!(
255261
status = %status,
256262
webhook_url = %webhook_url,
257263
"Webhook returned non-success status"
258264
);
259265
}
260266

261-
Ok(())
267+
Ok(status_code)
262268
}
263269
}
264270

0 commit comments

Comments
 (0)