Remove FileSystem notifier completely

pull/97/head
Clement Michaud 2017-09-24 20:55:11 +02:00
parent 4cd78f3f83
commit f564174998
6 changed files with 17 additions and 79 deletions

View File

@ -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

View File

@ -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<void> {
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);
}
}

View File

@ -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);
}

View File

@ -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()
};
}

View File

@ -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();
});
});
});

View File

@ -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);
});
});