-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add LogProcessor to the available options
- Loading branch information
Showing
9 changed files
with
154 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ reports | |
.env | ||
*.eml | ||
test.log | ||
data-headers.txt.raw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Can replace fakeSMTP.jar | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json", | ||
"flows": { | ||
"localhost": { | ||
"filters": [ | ||
// Allow only localhost | ||
{ | ||
"type": "whitelist", | ||
"ips": ["127.0.0.1"] | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
// We just log to the console | ||
"type": "log" | ||
} | ||
] | ||
} | ||
}, | ||
"port": 10026, | ||
"options": { | ||
"disableReverseLookup": false, | ||
// Do not require auth | ||
"authOptional": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Can replace fakeSMTP.jar | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/loopingz/smtp-relay/main/config.schema.json", | ||
"flows": { | ||
"localhost": { | ||
"filters": [ | ||
// Allow only localhost | ||
{ | ||
"type": "whitelist", | ||
"ips": ["127.0.0.1"] | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
// We just log to the console | ||
"type": "nodemailer", | ||
"nodemailer": { | ||
"host": "localhost", | ||
"port": 10026, | ||
"secure": false, | ||
"auth": { | ||
"user": "user", | ||
"pass": "pass" | ||
}, | ||
"tls": { | ||
"rejectUnauthorized": false | ||
} | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"options": { | ||
"disableReverseLookup": false, | ||
// Do not require auth | ||
"authOptional": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import * as sinon from "sinon"; | |
import { SmtpSession } from "../server"; | ||
import { getFakeSession } from "../server.spec"; | ||
import { GCPProcessor } from "./gcp"; | ||
import { readFileSync } from "node:fs"; | ||
|
||
@suite | ||
class GCPProcessorTest { | ||
|
@@ -71,9 +72,16 @@ class GCPProcessorTest { | |
} | ||
}; | ||
}); | ||
session.user = "LZ"; | ||
await gcp.onMail(session); | ||
delete session.user; | ||
assert.strictEqual(bucket, "test"); | ||
assert.strictEqual(filename, "unit-test-fake-path"); | ||
assert.ok(filename.endsWith("data-headers.txt.raw")); | ||
const updatedData = readFileSync(filename).toString(); | ||
assert.ok(updatedData.includes("X-smtp-relay-MAIL_FROM:[email protected]\n")); | ||
assert.ok(updatedData.includes("X-smtp-relay-CLIENT_HOSTNAME:localhost\n")); | ||
assert.ok(updatedData.includes("X-smtp-relay-HELO:localhost\n")); | ||
assert.ok(updatedData.includes("X-smtp-relay-USER:LZ\n")); | ||
assert.strictEqual(destination, "1234.eml"); | ||
|
||
bucket = filename = destination = undefined; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,56 @@ class NodeMailerProcessorTest { | |
await nodemailer.onMail(session); | ||
assert.notStrictEqual(msg, undefined); | ||
} | ||
|
||
@test | ||
async bccResolution() { | ||
const session = getFakeSession(); | ||
let nodemailer = new NodeMailerProcessor( | ||
undefined, | ||
{ | ||
type: "nodemailer", | ||
nodemailer: { | ||
host: "smtp.example.com", | ||
port: 587, | ||
secure: false, // upgrade later with STARTTLS | ||
auth: { | ||
user: "username", | ||
pass: "password" | ||
} | ||
} | ||
}, | ||
new WorkerOutput() | ||
); | ||
session.envelope.rcptTo = [ | ||
{ address: "[email protected]", args: [] }, | ||
{ address: "[email protected]", args: [] }, | ||
{ address: "[email protected]", args: [] } | ||
]; | ||
session.email.cc = [ | ||
{ | ||
html: "", | ||
text: "", | ||
value: [{ name: "", address: "[email protected]" }] | ||
} | ||
]; | ||
session.email.to = [ | ||
{ | ||
html: "", | ||
text: "", | ||
value: [{ name: "", address: "[email protected]" }] | ||
} | ||
]; | ||
session.email.headerLines = [{ key: "plop", line: "test" }]; | ||
NodeMailerProcessor.transformEmail(session); | ||
assert.deepStrictEqual(session.email.bcc, { | ||
html: "[email protected]", | ||
text: "[email protected]", | ||
value: [ | ||
{ | ||
address: "[email protected]", | ||
name: "" | ||
} | ||
] | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { SmtpFilter } from "./filter"; | |
import { SmtpFlow } from "./flow"; | ||
import { SmtpProcessor } from "./processor"; | ||
import { SmtpServer, SmtpSession, mapAddressObjects } from "./server"; | ||
import { readdirSync, unlinkSync } from "node:fs"; | ||
|
||
export class SmtpTest { | ||
sock: Socket; | ||
|
@@ -168,6 +169,12 @@ class OpenFilter extends SmtpFilter { | |
|
||
@suite | ||
class SmtpServerTest { | ||
static after() { | ||
readdirSync(".") | ||
.filter(f => f.startsWith(".email_") && f.endsWith(".eml")) | ||
.forEach(f => unlinkSync(f)); | ||
} | ||
|
||
@test | ||
async middlewareChaining() { | ||
defaultModules(); | ||
|
@@ -185,7 +192,10 @@ class SmtpServerTest { | |
); | ||
server.close(); | ||
// cov | ||
assert.ok(Array.isArray(mapAddressObjects({value: [], text: "", html: ""}, () => {})), "Should always return an array"); | ||
assert.ok( | ||
Array.isArray(mapAddressObjects({ value: [], text: "", html: "" }, () => {})), | ||
"Should always return an array" | ||
); | ||
// @ts-ignore | ||
server.addFlow({ name: "Test" }); | ||
// @ts-ignore | ||
|
@@ -252,7 +262,10 @@ class SmtpServerTest { | |
] | ||
}; | ||
// @ts-ignore | ||
await server.onDataRead({ flows: { fake: "PENDING" }, envelope: { mailFrom: {address: "[email protected]", args: {}}, rcptTo: [{address: "ok.com", args: {}}] } }); | ||
await server.onDataRead({ | ||
flows: { fake: "PENDING" }, | ||
envelope: { mailFrom: { address: "[email protected]", args: {} }, rcptTo: [{ address: "ok.com", args: {} }] } | ||
}); | ||
} | ||
|
||
@test | ||
|
@@ -318,7 +331,7 @@ export function getFakeSession(): SmtpSession { | |
secure: false, | ||
transmissionType: "TEST", | ||
time: new Date(), | ||
emailPath: "unit-test-fake-path", | ||
emailPath: import.meta.dirname + "/../tests/data-headers.txt", | ||
envelope: { | ||
mailFrom: { | ||
address: "[email protected]", | ||
|