mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-05-19 06:03:01 -04:00
fix(notifications): encode SMTP credentials in Shoutrrr URLs (#831)
Closes #829
This commit is contained in:
@@ -39,6 +39,21 @@ describe("notification shoutrrr URL builders", () => {
|
||||
).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",
|
||||
);
|
||||
|
||||
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", () => {
|
||||
|
||||
@@ -7,9 +7,9 @@ export const buildEmailShoutrrrUrl = (config: Extract<NotificationConfig, { type
|
||||
shoutrrrUrl.port = String(config.smtpPort);
|
||||
shoutrrrUrl.pathname = "/";
|
||||
|
||||
let auth = "";
|
||||
if (config.username && config.password) {
|
||||
shoutrrrUrl.username = config.username;
|
||||
shoutrrrUrl.password = config.password;
|
||||
auth = `${encodeURIComponent(config.username)}:${encodeURIComponent(config.password)}@`;
|
||||
}
|
||||
|
||||
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("starttls", config.useTLS ? "yes" : "no");
|
||||
|
||||
return shoutrrrUrl.toString();
|
||||
return shoutrrrUrl.toString().replace("smtp://", `smtp://${auth}`);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user