fix(notifications): encode SMTP credentials in Shoutrrr URLs (#831)
Closes #829
This commit is contained in:
parent
3adc722cca
commit
f078e006c1
2 changed files with 18 additions and 3 deletions
|
|
@ -39,6 +39,21 @@ describe("notification shoutrrr URL builders", () => {
|
||||||
).toBe(
|
).toBe(
|
||||||
"smtp://user%20name:p%40ss%20word@smtp.example.com:465/?from=alerts%2Bteam%40example.com&fromname=Ops+Team&to=ops%40example.com&starttls=no",
|
"smtp://user%20name:p%40ss%20word@smtp.example.com:465/?from=alerts%2Bteam%40example.com&fromname=Ops+Team&to=ops%40example.com&starttls=no",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
buildEmailShoutrrrUrl({
|
||||||
|
type: "email",
|
||||||
|
smtpHost: "smtp.example.com",
|
||||||
|
smtpPort: 465,
|
||||||
|
username: "user%name+tag",
|
||||||
|
password: "pa%ss+word",
|
||||||
|
from: "alerts@example.com",
|
||||||
|
to: ["ops@example.com"],
|
||||||
|
useTLS: false,
|
||||||
|
}),
|
||||||
|
).toBe(
|
||||||
|
"smtp://user%25name%2Btag:pa%25ss%2Bword@smtp.example.com:465/?from=alerts%40example.com&to=ops%40example.com&starttls=no",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("builds discord URLs and rejects invalid webhook formats", () => {
|
test("builds discord URLs and rejects invalid webhook formats", () => {
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ export const buildEmailShoutrrrUrl = (config: Extract<NotificationConfig, { type
|
||||||
shoutrrrUrl.port = String(config.smtpPort);
|
shoutrrrUrl.port = String(config.smtpPort);
|
||||||
shoutrrrUrl.pathname = "/";
|
shoutrrrUrl.pathname = "/";
|
||||||
|
|
||||||
|
let auth = "";
|
||||||
if (config.username && config.password) {
|
if (config.username && config.password) {
|
||||||
shoutrrrUrl.username = config.username;
|
auth = `${encodeURIComponent(config.username)}:${encodeURIComponent(config.password)}@`;
|
||||||
shoutrrrUrl.password = config.password;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shoutrrrUrl.searchParams.set("from", config.from);
|
shoutrrrUrl.searchParams.set("from", config.from);
|
||||||
|
|
@ -19,5 +19,5 @@ export const buildEmailShoutrrrUrl = (config: Extract<NotificationConfig, { type
|
||||||
shoutrrrUrl.searchParams.set("to", config.to.join(","));
|
shoutrrrUrl.searchParams.set("to", config.to.join(","));
|
||||||
shoutrrrUrl.searchParams.set("starttls", config.useTLS ? "yes" : "no");
|
shoutrrrUrl.searchParams.set("starttls", config.useTLS ? "yes" : "no");
|
||||||
|
|
||||||
return shoutrrrUrl.toString();
|
return shoutrrrUrl.toString().replace("smtp://", `smtp://${auth}`);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue