Skip to content

Commit 39e7d43

Browse files
committed
Use Connection URL Instead of Connection Object
Signed-off-by: Yannik Fuhrmeister <yannik.fuhrmeister@iteratec.com>
1 parent 6dcbebf commit 39e7d43

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

‎hooks/notification-hook/Notifiers/EMailNotifier.test.ts‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { NotifierType } from "../NotifierType";
22
import { EMailNotifier } from "./EMailNotifier";
33
import { NotificationChannel } from "../model/NotificationChannel";
44
import { Scan } from "../model/Scan";
5-
import * as nodemailer from "nodemailer";
65

76
const sendMail = jest.fn();
87
const close = jest.fn();
@@ -19,16 +18,8 @@ jest.mock("nodemailer", () => {
1918
});
2019

2120
test("Should Send Mail", async () => {
22-
23-
const smtp =
24-
`
25-
host: smtp.ethereal.email
26-
port: 587
27-
secure: false
28-
auth:
29-
user: some_user
30-
pass: some_password
31-
from: mail@from.someone`
21+
const from = "secureCodeBox";
22+
const smtp = "smtp://user:pass@smtp.ethereal.email/"
3223
process.env[EMailNotifier.SMTP_CONFIG] = smtp;
3324
const channel: NotificationChannel = {
3425
name: "Channel Name",
@@ -78,7 +69,10 @@ test("Should Send Mail", async () => {
7869
},
7970
};
8071

81-
const notifier = new EMailNotifier(channel, scan, [], []);
72+
const args = new Array();
73+
args[EMailNotifier.EMAIL_FROM] = from;
74+
75+
const notifier = new EMailNotifier(channel, scan, [], args);
8276

8377
await notifier.sendMessage();
8478

‎hooks/notification-hook/Notifiers/EMailNotifier.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { NotifierType } from "../NotifierType";
22
import { AbstractNotifier } from "./AbstractNotifier";
33
import { createTransport } from "nodemailer"
4-
import * as jsyaml from "js-yaml";
54

65
export class EMailNotifier extends AbstractNotifier {
76
public static readonly SMTP_CONFIG = 'SMTP_CONFIG';
7+
public static readonly EMAIL_FROM = 'EMAIL_FROM';
88
protected type: NotifierType.EMAIL;
99

1010
public async sendMessage(): Promise<void> {
@@ -14,7 +14,7 @@ export class EMailNotifier extends AbstractNotifier {
1414
}
1515

1616
private getSMTPConfig(): any {
17-
return jsyaml.load(process.env[EMailNotifier.SMTP_CONFIG]);
17+
return process.env[EMailNotifier.SMTP_CONFIG];
1818
}
1919

2020
protected async sendMail(message: any, smtpConfig: any) {
@@ -32,7 +32,7 @@ export class EMailNotifier extends AbstractNotifier {
3232
private prepareMessage(): any {
3333
const message = JSON.parse(this.renderMessage());
3434
message.to = this.channel.endPoint;
35-
message.from = this.getSMTPConfig().from;
35+
message.from = this.args[EMailNotifier.EMAIL_FROM];
3636
return message;
3737
}
3838
}

0 commit comments

Comments
 (0)