From f564174998321837b1bdfe6b9cc723f8f318bf05 Mon Sep 17 00:00:00 2001 From: Clement Michaud Date: Sun, 24 Sep 2017 20:55:11 +0200 Subject: [PATCH] Remove FileSystem notifier completely --- example/ldap/docker-compose.yml | 1 - .../lib/notifiers/FileSystemNotifier.ts | 24 ----------- src/server/lib/notifiers/NotifierFactory.ts | 4 -- test/unit/server/mocks/nodemailer.ts | 4 +- .../notifiers/FileSystemNotifier.test.ts | 43 ------------------- .../server/notifiers/NotifierFactory.test.ts | 20 ++++++--- 6 files changed, 17 insertions(+), 79 deletions(-) delete mode 100644 src/server/lib/notifiers/FileSystemNotifier.ts delete mode 100644 test/unit/server/notifiers/FileSystemNotifier.test.ts diff --git a/example/ldap/docker-compose.yml b/example/ldap/docker-compose.yml index 4d3c6d4c4..e991df60b 100644 --- a/example/ldap/docker-compose.yml +++ b/example/ldap/docker-compose.yml @@ -12,7 +12,6 @@ services: - SLAPD_FORCE_RECONFIGURE=true volumes: - ./example/ldap/base.ldif:/etc/ldap.dist/prepopulate/base.ldif - - ./example/ldap/private.ldif:/etc/ldap.dist/prepopulate/private.ldif - ./example/ldap/access.rules:/etc/ldap.dist/prepopulate/access.rules networks: - example-network diff --git a/src/server/lib/notifiers/FileSystemNotifier.ts b/src/server/lib/notifiers/FileSystemNotifier.ts deleted file mode 100644 index 042877ac6..000000000 --- a/src/server/lib/notifiers/FileSystemNotifier.ts +++ /dev/null @@ -1,24 +0,0 @@ - -import * as BluebirdPromise from "bluebird"; -import * as util from "util"; -import * as Fs from "fs"; -import { INotifier } from "./INotifier"; -import { Identity } from "../../../types/Identity"; - -import { FileSystemNotifierConfiguration } from "../configuration/Configuration"; - -export class FileSystemNotifier implements INotifier { - private filename: string; - - constructor(options: FileSystemNotifierConfiguration) { - this.filename = options.filename; - } - - notify(identity: Identity, subject: string, link: string): BluebirdPromise { - const content = util.format("Date: %s\nUser: %s\nSubject: %s\nLink: %s", new Date().toString(), identity.userid, - subject, link); - const writeFilePromised: any = BluebirdPromise.promisify(Fs.writeFile); - return writeFilePromised(this.filename, content); - } -} - diff --git a/src/server/lib/notifiers/NotifierFactory.ts b/src/server/lib/notifiers/NotifierFactory.ts index b1f202ae8..2567db6eb 100644 --- a/src/server/lib/notifiers/NotifierFactory.ts +++ b/src/server/lib/notifiers/NotifierFactory.ts @@ -5,16 +5,12 @@ import { INotifier } from "./INotifier"; import { GMailNotifier } from "./GMailNotifier"; import { SmtpNotifier } from "./SmtpNotifier"; -import { FileSystemNotifier } from "./FileSystemNotifier"; export class NotifierFactory { static build(options: NotifierConfiguration, nodemailer: Nodemailer): INotifier { if ("gmail" in options) { return new GMailNotifier(options.gmail, nodemailer); } - else if ("filesystem" in options) { - return new FileSystemNotifier(options.filesystem); - } else if ("smtp" in options) { return new SmtpNotifier(options.smtp, nodemailer); } diff --git a/test/unit/server/mocks/nodemailer.ts b/test/unit/server/mocks/nodemailer.ts index 61ec1c94b..2c7bc41ac 100644 --- a/test/unit/server/mocks/nodemailer.ts +++ b/test/unit/server/mocks/nodemailer.ts @@ -13,10 +13,12 @@ export function NodemailerMock(): NodemailerMock { export interface NodemailerTransporterMock { sendMail: sinon.SinonStub; + verify: sinon.SinonStub; } export function NodemailerTransporterMock() { return { - sendMail: sinon.stub() + sendMail: sinon.stub(), + verify: sinon.stub() }; } diff --git a/test/unit/server/notifiers/FileSystemNotifier.test.ts b/test/unit/server/notifiers/FileSystemNotifier.test.ts deleted file mode 100644 index eecab6573..000000000 --- a/test/unit/server/notifiers/FileSystemNotifier.test.ts +++ /dev/null @@ -1,43 +0,0 @@ - -import * as sinon from "sinon"; -import * as assert from "assert"; -import { FileSystemNotifier } from "../../../../src/server/lib/notifiers/FileSystemNotifier"; -import * as tmp from "tmp"; -import * as fs from "fs"; -import BluebirdPromise = require("bluebird"); - -const NOTIFICATIONS_DIRECTORY = "notifications"; - -describe("test FS notifier", function() { - let tmpDir: tmp.SynchrounousResult; - before(function() { - tmpDir = tmp.dirSync({ unsafeCleanup: true }); - }); - - after(function() { - tmpDir.removeCallback(); - }); - - it("should write the notification in a file", function() { - const options = { - filename: tmpDir.name + "/" + NOTIFICATIONS_DIRECTORY - }; - - const sender = new FileSystemNotifier(options); - const subject = "subject"; - - const identity = { - userid: "user", - email: "user@example.com" - }; - - const url = "http://test.com"; - - return sender.notify(identity, subject, url) - .then(function() { - const content = fs.readFileSync(options.filename, "UTF-8"); - assert(content.length > 0); - return BluebirdPromise.resolve(); - }); - }); -}); diff --git a/test/unit/server/notifiers/NotifierFactory.test.ts b/test/unit/server/notifiers/NotifierFactory.test.ts index 8b4d8674c..a28034b06 100644 --- a/test/unit/server/notifiers/NotifierFactory.test.ts +++ b/test/unit/server/notifiers/NotifierFactory.test.ts @@ -5,7 +5,7 @@ import * as assert from "assert"; import { NotifierFactory } from "../../../../src/server/lib/notifiers/NotifierFactory"; import { GMailNotifier } from "../../../../src/server/lib/notifiers/GMailNotifier"; -import { FileSystemNotifier } from "../../../../src/server/lib/notifiers/FileSystemNotifier"; +import { SmtpNotifier } from "../../../../src/server/lib/notifiers/SmtpNotifier"; import NodemailerMock = require("../mocks/nodemailer"); @@ -20,17 +20,25 @@ describe("test notifier factory", function() { } }; nodemailerMock = NodemailerMock.NodemailerMock(); - nodemailerMock.createTransport.returns(sinon.spy()); + const transporterMock = NodemailerMock.NodemailerTransporterMock(); + nodemailerMock.createTransport.returns(transporterMock); assert(NotifierFactory.build(options, nodemailerMock) instanceof GMailNotifier); }); - it("should build a FS Notifier", function() { + it("should build a SMTP Notifier", function() { const options = { - filesystem: { - filename: "abc" + smtp: { + username: "user", + password: "pass", + secure: true, + host: "localhost", + port: 25 } }; - assert(NotifierFactory.build(options, nodemailerMock) instanceof FileSystemNotifier); + nodemailerMock = NodemailerMock.NodemailerMock(); + const transporterMock = NodemailerMock.NodemailerTransporterMock(); + nodemailerMock.createTransport.returns(transporterMock); + assert(NotifierFactory.build(options, nodemailerMock) instanceof SmtpNotifier); }); });