feat: add authentication support to ntfy notifications
ntfy servers that require auth rejected every Checkmate alert because the
provider posted without an Authorization header, so alerts to protected
topics failed silently.
Adds ntfyAuthType ("none" | "token" | "basic"):
- token: Authorization: Bearer <accessToken>
- basic: Authorization: Basic base64(ntfyUsername:accessToken)
Both types store their secret in the existing accessToken field rather than
introducing a new secret, so credential handling stays in one place.
Incomplete credentials fail the send instead of falling back to an anonymous
post, and validation rejects partial auth config up front so a channel can't
be saved looking authenticated while posting anonymously.
Backend only; frontend follows once this lands.
Closes #3717
This commit is contained in:
1 parent
f97ca8565a
commit
1c9739d1da
8 files changed
+289
-8
No files matched your search
@@ -44,4 +44,69 @@ describe("notification validation", () => {
|
||||
expect(result.success).toBe(false);
|
||||
}
|
||||
);
|
||||
|
||||
describe("ntfy authentication", () => {
|
||||
const parseNtfy = (overrides: Record<string, unknown>) =>
|
||||
createNotificationBodyValidation.safeParse({
|
||||
notificationName: "ntfy alerts",
|
||||
type: "ntfy",
|
||||
address: "https://ntfy.example.com",
|
||||
topic: "checkmate-alerts",
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const pathsOf = (result: ReturnType<typeof parseNtfy>) => (result.success ? [] : result.error.issues.map((issue) => issue.path.join(".")));
|
||||
|
||||
it("accepts an unauthenticated channel", () => {
|
||||
expect(parseNtfy({}).success).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts an explicit auth type of none", () => {
|
||||
expect(parseNtfy({ ntfyAuthType: "none" }).success).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts token auth with an access token", () => {
|
||||
expect(parseNtfy({ ntfyAuthType: "token", accessToken: "tk_secret" }).success).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts basic auth with a username and password", () => {
|
||||
expect(parseNtfy({ ntfyAuthType: "basic", ntfyUsername: "alice", accessToken: "s3cret" }).success).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects an unknown auth type", () => {
|
||||
expect(parseNtfy({ ntfyAuthType: "oauth" }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects token auth without an access token", () => {
|
||||
expect(pathsOf(parseNtfy({ ntfyAuthType: "token" }))).toContain("accessToken");
|
||||
});
|
||||
|
||||
it("rejects token auth carrying a username", () => {
|
||||
expect(pathsOf(parseNtfy({ ntfyAuthType: "token", accessToken: "tk_secret", ntfyUsername: "alice" }))).toContain("ntfyUsername");
|
||||
});
|
||||
|
||||
it("rejects basic auth without a username", () => {
|
||||
expect(pathsOf(parseNtfy({ ntfyAuthType: "basic", accessToken: "s3cret" }))).toContain("ntfyUsername");
|
||||
});
|
||||
|
||||
it("rejects basic auth without a password", () => {
|
||||
expect(pathsOf(parseNtfy({ ntfyAuthType: "basic", ntfyUsername: "alice" }))).toContain("accessToken");
|
||||
});
|
||||
|
||||
it("reports both fields when basic auth is entirely empty", () => {
|
||||
expect(pathsOf(parseNtfy({ ntfyAuthType: "basic" }))).toEqual(expect.arrayContaining(["ntfyUsername", "accessToken"]));
|
||||
});
|
||||
|
||||
// Credentials with auth off would be stored but never sent, which reads as protected
|
||||
// while posting anonymously.
|
||||
it("rejects credentials supplied without an auth type", () => {
|
||||
expect(pathsOf(parseNtfy({ accessToken: "tk_secret" }))).toContain("accessToken");
|
||||
expect(pathsOf(parseNtfy({ ntfyUsername: "alice" }))).toContain("ntfyUsername");
|
||||
});
|
||||
|
||||
it("still requires a topic and a valid server URL", () => {
|
||||
expect(parseNtfy({ topic: "" }).success).toBe(false);
|
||||
expect(parseNtfy({ address: "not-a-url" }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user