|
| 1 | +import { NotifierType } from "../NotifierType"; |
| 2 | +import { EMailNotifier } from "./EMailNotifier"; |
| 3 | +import { NotificationChannel } from "../model/NotificationChannel"; |
| 4 | +import { Scan } from "../model/Scan"; |
| 5 | + |
| 6 | +const sendMail = jest.fn(); |
| 7 | +const close = jest.fn(); |
| 8 | + |
| 9 | +jest.mock("nodemailer", () => { |
| 10 | + return { |
| 11 | + createTransport: () => { |
| 12 | + return { |
| 13 | + sendMail, |
| 14 | + close, |
| 15 | + } |
| 16 | + } |
| 17 | + }; |
| 18 | +}); |
| 19 | + |
| 20 | +test("Should Send Mail", async () => { |
| 21 | + const from = "secureCodeBox"; |
| 22 | + const smtp = "smtp://user:pass@smtp.ethereal.email/" |
| 23 | + process.env[EMailNotifier.SMTP_CONFIG] = smtp; |
| 24 | + const channel: NotificationChannel = { |
| 25 | + name: "Channel Name", |
| 26 | + type: NotifierType.EMAIL, |
| 27 | + template: "email", |
| 28 | + rules: [], |
| 29 | + endPoint: "mail@some.email" |
| 30 | + }; |
| 31 | + const scan: Scan = { |
| 32 | + metadata: { |
| 33 | + uid: "09988cdf-1fc7-4f85-95ee-1b1d65dbc7cc", |
| 34 | + name: "demo-scan-1601086432", |
| 35 | + namespace: "my-scans", |
| 36 | + creationTimestamp: new Date("2021-01-01T14:29:25Z"), |
| 37 | + labels: { |
| 38 | + company: "iteratec", |
| 39 | + "attack-surface": "external", |
| 40 | + }, |
| 41 | + }, |
| 42 | + spec: { |
| 43 | + scanType: "nmap", |
| 44 | + parameters: ["-Pn", "localhost"], |
| 45 | + }, |
| 46 | + status: { |
| 47 | + findingDownloadLink: |
| 48 | + "https://my-secureCodeBox-instance.com/scan-b9as-sdweref--sadf-asdfsdf-dasdgf-asdffdsfa7/findings.json", |
| 49 | + findings: { |
| 50 | + categories: { |
| 51 | + "A Client Error response code was returned by the server": 1, |
| 52 | + "Information Disclosure - Sensitive Information in URL": 1, |
| 53 | + "Strict-Transport-Security Header Not Set": 1, |
| 54 | + }, |
| 55 | + count: 3, |
| 56 | + severities: { |
| 57 | + high: 10, |
| 58 | + medium: 5, |
| 59 | + low: 2, |
| 60 | + informational: 1, |
| 61 | + }, |
| 62 | + }, |
| 63 | + finishedAt: new Date("2020-05-25T02:38:13Z"), |
| 64 | + rawResultDownloadLink: |
| 65 | + "https://my-secureCodeBox-instance.com/scan-blkfsdg-sdgfsfgd-sfg-sdfg-dfsg-gfs98-e8af2172caa7/zap-results.json?Expires=1601691232", |
| 66 | + rawResultFile: "zap-results.json", |
| 67 | + rawResultType: "zap-json", |
| 68 | + state: "Done", |
| 69 | + }, |
| 70 | + }; |
| 71 | + |
| 72 | + const args = new Array(); |
| 73 | + args[EMailNotifier.EMAIL_FROM] = from; |
| 74 | + |
| 75 | + const notifier = new EMailNotifier(channel, scan, [], args); |
| 76 | + |
| 77 | + await notifier.sendMessage(); |
| 78 | + |
| 79 | + expect(sendMail).toBeCalled(); |
| 80 | + expect(close).toBeCalled(); |
| 81 | + |
| 82 | +}) |
0 commit comments