diff --git a/.gitignore b/.gitignore index f80f27d2..d39149ef 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ dist/ /config.yml example/ldap/private.ldif + +package-lock.json diff --git a/Dockerfile b/Dockerfile index 63b6d3eb..7700fd8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,8 @@ WORKDIR /usr/src COPY package.json /usr/src/package.json RUN npm install --production -COPY dist/src/server /usr/src +COPY dist/server /usr/src/server +COPY dist/shared /usr/src/shared ENV PORT=80 EXPOSE 80 @@ -13,4 +14,4 @@ EXPOSE 80 VOLUME /etc/authelia VOLUME /var/lib/authelia -CMD ["node", "index.js", "/etc/authelia/config.yml"] +CMD ["node", "server/src/index.js", "/etc/authelia/config.yml"] diff --git a/Gruntfile.js b/Gruntfile.js index 1dd85367..3837d2ee 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -2,75 +2,90 @@ module.exports = function (grunt) { const buildDir = "dist"; grunt.initConfig({ + env: { + "env-test-server-unit": { + TS_NODE_PROJECT: "server" + }, + "env-test-client-unit": { + TS_NODE_PROJECT: "client" + } + }, run: { - options: {}, - "build": { + "compile-server": { cmd: "./node_modules/.bin/tsc", - args: ['-p', 'tsconfig.json'] + args: ['-p', 'server/tsconfig.json'] }, - "tslint": { + "compile-client": { + cmd: "./node_modules/.bin/tsc", + args: ['-p', 'client/tsconfig.json'] + }, + "lint-server": { cmd: "./node_modules/.bin/tslint", - args: ['-c', 'tslint.json', '-p', 'tsconfig.json'] + args: ['-c', 'server/tslint.json', '-p', 'server/tsconfig.json'] }, - "unit-tests": { + "lint-client": { + cmd: "./node_modules/.bin/tslint", + args: ['-c', 'client/tslint.json', '-p', 'client/tsconfig.json'] + }, + "test-server-unit": { cmd: "./node_modules/.bin/mocha", - args: ['--compilers', 'ts:ts-node/register', '--recursive', 'test/unit'] + args: ['--colors', '--compilers', 'ts:ts-node/register', '--recursive', 'server/test'] }, - "integration-tests": { + "test-client-unit": { + cmd: "./node_modules/.bin/mocha", + args: ['--colors', '--compilers', 'ts:ts-node/register', '--recursive', 'client/test'] + }, + "test-int": { cmd: "./node_modules/.bin/cucumber-js", - args: ["--compiler", "ts:ts-node/register", "./test/features"] + args: ["--colors", "--compiler", "ts:ts-node/register", "./test/features"] }, "docker-build": { cmd: "docker", args: ['build', '-t', 'clems4ever/authelia', '.'] }, - "docker-restart": { - cmd: "./scripts/dc-dev.sh", - args: ['restart', 'authelia'] - }, "minify": { cmd: "./node_modules/.bin/uglifyjs", - args: [`${buildDir}/src/server/public_html/js/authelia.js`, '-o', `${buildDir}/src/server/public_html/js/authelia.min.js`] + args: [`${buildDir}/server/src/public_html/js/authelia.js`, '-o', `${buildDir}/server/src/public_html/js/authelia.min.js`] }, "apidoc": { cmd: "./node_modules/.bin/apidoc", args: ["-i", "src/server", "-o", "doc"] }, - "make-dev-views": { + "include-minified-script": { cmd: "sed", - args: ["-i", "s/authelia\.min/authelia/", `${buildDir}/src/server/views/layout/layout.pug`] + args: ["-i", "s/authelia\.min/authelia/", `${buildDir}/server/src/views/layout/layout.pug`] } }, copy: { resources: { expand: true, - cwd: 'src/server/resources/', + cwd: 'server/src/resources/', src: '**', - dest: `${buildDir}/src/server/resources/` + dest: `${buildDir}/server/src/resources/` }, views: { expand: true, - cwd: 'src/server/views/', + cwd: 'server/src/views/', src: '**', - dest: `${buildDir}/src/server/views/` + dest: `${buildDir}/server/src/views/` }, images: { expand: true, - cwd: 'src/client/img', + cwd: 'client/src/img', src: '**', - dest: `${buildDir}/src/server/public_html/img/` + dest: `${buildDir}/server/src/public_html/img/` }, thirdparties: { expand: true, - cwd: 'src/client/thirdparties', + cwd: 'client/src/thirdparties', src: '**', - dest: `${buildDir}/src/server/public_html/js/` + dest: `${buildDir}/server/src/public_html/js/` }, }, browserify: { dist: { - src: ['dist/src/client/index.js'], - dest: `${buildDir}/src/server/public_html/js/authelia.js`, + src: ['dist/client/src/index.js'], + dest: `${buildDir}/server/src/public_html/js/authelia.js`, options: { browserifyOptions: { standalone: 'authelia' @@ -80,7 +95,7 @@ module.exports = function (grunt) { }, watch: { views: { - files: ['src/server/views/**/*.pug'], + files: ['server/src/views/**/*.pug'], tasks: ['copy:views'], options: { interrupt: false, @@ -88,7 +103,7 @@ module.exports = function (grunt) { } }, resources: { - files: ['src/server/resources/*.ejs'], + files: ['server/src/resources/*.ejs'], tasks: ['copy:resources'], options: { interrupt: false, @@ -96,7 +111,7 @@ module.exports = function (grunt) { } }, images: { - files: ['src/client/img/**'], + files: ['client/src/img/**'], tasks: ['copy:images'], options: { interrupt: false, @@ -104,7 +119,7 @@ module.exports = function (grunt) { } }, css: { - files: ['src/client/**/*.css'], + files: ['client/src/**/*.css'], tasks: ['concat:css', 'cssmin'], options: { interrupt: true, @@ -112,7 +127,7 @@ module.exports = function (grunt) { } }, client: { - files: ['src/client/**/*.ts'], + files: ['client/src/**/*.ts'], tasks: ['build-dev'], options: { interrupt: true, @@ -120,7 +135,7 @@ module.exports = function (grunt) { } }, server: { - files: ['src/server/**/*.ts'], + files: ['server/src/**/*.ts'], tasks: ['build-dev', 'run:docker-restart', 'run:make-dev-views' ], options: { interrupt: true, @@ -130,14 +145,14 @@ module.exports = function (grunt) { }, concat: { css: { - src: ['src/client/css/*.css'], - dest: `${buildDir}/src/server/public_html/css/authelia.css` + src: ['client/src/css/*.css'], + dest: `${buildDir}/server/src/public_html/css/authelia.css` }, }, cssmin: { target: { files: { - [`${buildDir}/src/server/public_html/css/authelia.min.css`]: [`${buildDir}/src/server/public_html/css/authelia.css`] + [`${buildDir}/server/src/public_html/css/authelia.min.css`]: [`${buildDir}/server/src/public_html/css/authelia.css`] } } } @@ -149,20 +164,26 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-run'); + grunt.loadNpmTasks('grunt-env'); - grunt.registerTask('default', ['build-dist']); - grunt.registerTask('build-resources', ['copy:resources', 'copy:views', 'copy:images', 'copy:thirdparties', 'concat:css']); + grunt.registerTask('compile-server', ['run:lint-server', 'run:compile-server']) + grunt.registerTask('compile-client', ['run:lint-client', 'run:compile-client']) - grunt.registerTask('build-common', ['run:tslint', 'run:build', 'browserify:dist', 'build-resources']); - grunt.registerTask('build-dev', ['build-common', 'run:make-dev-views']); - grunt.registerTask('build-dist', ['build-common', 'run:minify', 'cssmin']); + grunt.registerTask('test-server', ['env:env-test-server-unit', 'run:test-server-unit']) + grunt.registerTask('test-client', ['env:env-test-client-unit', 'run:test-client-unit']) + grunt.registerTask('test-unit', ['test-server', 'test-client']); + grunt.registerTask('test-int', ['run:test-int']); + + grunt.registerTask('copy-resources', ['copy:resources', 'copy:views', 'copy:images', 'copy:thirdparties', 'concat:css']); + + grunt.registerTask('build-client', ['compile-client', 'browserify']); + grunt.registerTask('build-server', ['compile-server', 'copy-resources']); + + grunt.registerTask('build', ['build-client', 'build-server']); + grunt.registerTask('build-dist', ['build', 'run:minify', 'cssmin', 'run:include-minified-script']); grunt.registerTask('docker-build', ['run:docker-build']); - grunt.registerTask('docker-restart', ['run:docker-restart']); - grunt.registerTask('unit-tests', ['run:unit-tests']); - grunt.registerTask('integration-tests', ['run:integration-tests']); - - grunt.registerTask('test', ['unit-tests']); + grunt.registerTask('default', ['build-dist']); }; diff --git a/src/client/css/00-bootstrap.min.css b/client/src/css/00-bootstrap.min.css similarity index 100% rename from src/client/css/00-bootstrap.min.css rename to client/src/css/00-bootstrap.min.css diff --git a/src/client/css/01-main.css b/client/src/css/01-main.css similarity index 100% rename from src/client/css/01-main.css rename to client/src/css/01-main.css diff --git a/src/client/css/02-login.css b/client/src/css/02-login.css similarity index 100% rename from src/client/css/02-login.css rename to client/src/css/02-login.css diff --git a/src/client/css/03-errors.css b/client/src/css/03-errors.css similarity index 100% rename from src/client/css/03-errors.css rename to client/src/css/03-errors.css diff --git a/src/client/css/03-password-reset-form.css b/client/src/css/03-password-reset-form.css similarity index 100% rename from src/client/css/03-password-reset-form.css rename to client/src/css/03-password-reset-form.css diff --git a/src/client/css/03-password-reset-request.css b/client/src/css/03-password-reset-request.css similarity index 100% rename from src/client/css/03-password-reset-request.css rename to client/src/css/03-password-reset-request.css diff --git a/src/client/css/03-totp-register.css b/client/src/css/03-totp-register.css similarity index 100% rename from src/client/css/03-totp-register.css rename to client/src/css/03-totp-register.css diff --git a/src/client/css/03-u2f-register.css b/client/src/css/03-u2f-register.css similarity index 100% rename from src/client/css/03-u2f-register.css rename to client/src/css/03-u2f-register.css diff --git a/src/client/img/icon.png b/client/src/img/icon.png similarity index 100% rename from src/client/img/icon.png rename to client/src/img/icon.png diff --git a/src/client/img/mail.png b/client/src/img/mail.png similarity index 100% rename from src/client/img/mail.png rename to client/src/img/mail.png diff --git a/src/client/img/padlock.png b/client/src/img/padlock.png similarity index 100% rename from src/client/img/padlock.png rename to client/src/img/padlock.png diff --git a/src/client/img/password.png b/client/src/img/password.png similarity index 100% rename from src/client/img/password.png rename to client/src/img/password.png diff --git a/src/client/img/pendrive.png b/client/src/img/pendrive.png similarity index 100% rename from src/client/img/pendrive.png rename to client/src/img/pendrive.png diff --git a/src/client/img/success.png b/client/src/img/success.png similarity index 100% rename from src/client/img/success.png rename to client/src/img/success.png diff --git a/src/client/img/user.png b/client/src/img/user.png similarity index 100% rename from src/client/img/user.png rename to client/src/img/user.png diff --git a/src/client/img/warning.png b/client/src/img/warning.png similarity index 100% rename from src/client/img/warning.png rename to client/src/img/warning.png diff --git a/src/client/index.ts b/client/src/index.ts similarity index 93% rename from src/client/index.ts rename to client/src/index.ts index 956edfc0..8c60127f 100644 --- a/src/client/index.ts +++ b/client/src/index.ts @@ -9,7 +9,7 @@ import ResetPasswordRequest from "./lib/reset-password/reset-password-request"; import ResetPasswordForm from "./lib/reset-password/reset-password-form"; import jslogger = require("js-logger"); import jQuery = require("jquery"); -import u2fApi = require("u2f-api"); +import U2fApi = require("u2f-api"); jslogger.useDefaults(); jslogger.setLevel(jslogger.INFO); @@ -19,7 +19,7 @@ export = { FirstFactor(window, jQuery, FirstFactorValidator, jslogger); }, secondfactor: function () { - SecondFactor(window, jQuery, u2fApi); + SecondFactor(window, jQuery, U2fApi); }, register_totp: function() { TOTPRegister(window, jQuery); diff --git a/src/client/lib/INotifier.ts b/client/src/lib/INotifier.ts similarity index 100% rename from src/client/lib/INotifier.ts rename to client/src/lib/INotifier.ts diff --git a/src/client/lib/Notifier.ts b/client/src/lib/Notifier.ts similarity index 100% rename from src/client/lib/Notifier.ts rename to client/src/lib/Notifier.ts diff --git a/src/client/lib/QueryParametersRetriever.ts b/client/src/lib/QueryParametersRetriever.ts similarity index 100% rename from src/client/lib/QueryParametersRetriever.ts rename to client/src/lib/QueryParametersRetriever.ts diff --git a/src/client/lib/firstfactor/FirstFactorValidator.ts b/client/src/lib/firstfactor/FirstFactorValidator.ts similarity index 87% rename from src/client/lib/firstfactor/FirstFactorValidator.ts rename to client/src/lib/firstfactor/FirstFactorValidator.ts index 32dc421c..b7bda3b4 100644 --- a/src/client/lib/firstfactor/FirstFactorValidator.ts +++ b/client/src/lib/firstfactor/FirstFactorValidator.ts @@ -1,7 +1,7 @@ import BluebirdPromise = require("bluebird"); -import Endpoints = require("../../../server/endpoints"); -import Constants = require("../../../server/constants"); +import Endpoints = require("../../../../shared/api"); +import Constants = require("../../../../shared/constants"); export function validate(username: string, password: string, redirectUrl: string, onlyBasicAuth: boolean, $: JQueryStatic): BluebirdPromise { diff --git a/src/client/lib/firstfactor/UISelectors.ts b/client/src/lib/firstfactor/UISelectors.ts similarity index 100% rename from src/client/lib/firstfactor/UISelectors.ts rename to client/src/lib/firstfactor/UISelectors.ts diff --git a/src/client/lib/firstfactor/index.ts b/client/src/lib/firstfactor/index.ts similarity index 92% rename from src/client/lib/firstfactor/index.ts rename to client/src/lib/firstfactor/index.ts index a4fd4829..fc897ff1 100644 --- a/src/client/lib/firstfactor/index.ts +++ b/client/src/lib/firstfactor/index.ts @@ -3,8 +3,8 @@ import JSLogger = require("js-logger"); import UISelectors = require("./UISelectors"); import { Notifier } from "../Notifier"; import { QueryParametersRetriever } from "../QueryParametersRetriever"; -import Constants = require("../../../server/constants"); -import Endpoints = require("../../../server/endpoints"); +import Constants = require("../../../../shared/constants"); +import Endpoints = require("../../../../shared/api"); export default function (window: Window, $: JQueryStatic, firstFactorValidator: typeof FirstFactorValidator, jslogger: typeof JSLogger) { diff --git a/src/client/lib/reset-password/constants.ts b/client/src/lib/reset-password/constants.ts similarity index 100% rename from src/client/lib/reset-password/constants.ts rename to client/src/lib/reset-password/constants.ts diff --git a/src/client/lib/reset-password/reset-password-form.ts b/client/src/lib/reset-password/reset-password-form.ts similarity index 96% rename from src/client/lib/reset-password/reset-password-form.ts rename to client/src/lib/reset-password/reset-password-form.ts index 26ec4ec1..12f60d77 100644 --- a/src/client/lib/reset-password/reset-password-form.ts +++ b/client/src/lib/reset-password/reset-password-form.ts @@ -1,6 +1,6 @@ import BluebirdPromise = require("bluebird"); -import Endpoints = require("../../../server/endpoints"); +import Endpoints = require("../../../../shared/api"); import Constants = require("./constants"); import { Notifier } from "../Notifier"; diff --git a/src/client/lib/reset-password/reset-password-request.ts b/client/src/lib/reset-password/reset-password-request.ts similarity index 96% rename from src/client/lib/reset-password/reset-password-request.ts rename to client/src/lib/reset-password/reset-password-request.ts index 8ff450f4..0685e176 100644 --- a/src/client/lib/reset-password/reset-password-request.ts +++ b/client/src/lib/reset-password/reset-password-request.ts @@ -1,7 +1,7 @@ import BluebirdPromise = require("bluebird"); -import Endpoints = require("../../../server/endpoints"); +import Endpoints = require("../../../../shared/api"); import Constants = require("./constants"); import jslogger = require("js-logger"); import { Notifier } from "../Notifier"; diff --git a/src/client/lib/secondfactor/TOTPValidator.ts b/client/src/lib/secondfactor/TOTPValidator.ts similarity index 91% rename from src/client/lib/secondfactor/TOTPValidator.ts rename to client/src/lib/secondfactor/TOTPValidator.ts index 4b1d0ffb..824b591a 100644 --- a/src/client/lib/secondfactor/TOTPValidator.ts +++ b/client/src/lib/secondfactor/TOTPValidator.ts @@ -1,6 +1,6 @@ import BluebirdPromise = require("bluebird"); -import Endpoints = require("../../../server/endpoints"); +import Endpoints = require("../../../../shared/api"); export function validate(token: string, $: JQueryStatic): BluebirdPromise { return new BluebirdPromise(function (resolve, reject) { diff --git a/src/client/lib/secondfactor/U2FValidator.ts b/client/src/lib/secondfactor/U2FValidator.ts similarity index 93% rename from src/client/lib/secondfactor/U2FValidator.ts rename to client/src/lib/secondfactor/U2FValidator.ts index b1fdb595..66c7751a 100644 --- a/src/client/lib/secondfactor/U2FValidator.ts +++ b/client/src/lib/secondfactor/U2FValidator.ts @@ -2,8 +2,8 @@ import U2fApi = require("u2f-api"); import U2f = require("u2f"); import BluebirdPromise = require("bluebird"); -import { SignMessage } from "../../../server/lib/routes/secondfactor/u2f/sign_request/SignMessage"; -import Endpoints = require("../../../server/endpoints"); +import { SignMessage } from "../../../../shared/SignMessage"; +import Endpoints = require("../../../../shared/api"); import { INotifier } from "../INotifier"; function finishU2fAuthentication(responseData: U2fApi.SignResponse, $: JQueryStatic): BluebirdPromise { diff --git a/src/client/lib/secondfactor/constants.ts b/client/src/lib/secondfactor/constants.ts similarity index 100% rename from src/client/lib/secondfactor/constants.ts rename to client/src/lib/secondfactor/constants.ts diff --git a/src/client/lib/secondfactor/index.ts b/client/src/lib/secondfactor/index.ts similarity index 94% rename from src/client/lib/secondfactor/index.ts rename to client/src/lib/secondfactor/index.ts index 4fe9ae94..52875254 100644 --- a/src/client/lib/secondfactor/index.ts +++ b/client/src/lib/secondfactor/index.ts @@ -4,11 +4,11 @@ import jslogger = require("js-logger"); import TOTPValidator = require("./TOTPValidator"); import U2FValidator = require("./U2FValidator"); -import Endpoints = require("../../../server/endpoints"); import Constants = require("./constants"); import { Notifier } from "../Notifier"; import { QueryParametersRetriever } from "../QueryParametersRetriever"; -import ServerConstants = require("../../../server/constants"); +import Endpoints = require("../../../../shared/api"); +import ServerConstants = require("../../../../shared/constants"); export default function (window: Window, $: JQueryStatic, u2fApi: typeof U2fApi) { diff --git a/src/client/lib/totp-register/totp-register.ts b/client/src/lib/totp-register/totp-register.ts similarity index 100% rename from src/client/lib/totp-register/totp-register.ts rename to client/src/lib/totp-register/totp-register.ts diff --git a/src/client/lib/totp-register/ui-selector.ts b/client/src/lib/totp-register/ui-selector.ts similarity index 100% rename from src/client/lib/totp-register/ui-selector.ts rename to client/src/lib/totp-register/ui-selector.ts diff --git a/src/client/lib/u2f-register/u2f-register.ts b/client/src/lib/u2f-register/u2f-register.ts similarity index 97% rename from src/client/lib/u2f-register/u2f-register.ts rename to client/src/lib/u2f-register/u2f-register.ts index e34706bc..f895bbf6 100644 --- a/src/client/lib/u2f-register/u2f-register.ts +++ b/client/src/lib/u2f-register/u2f-register.ts @@ -2,9 +2,9 @@ import BluebirdPromise = require("bluebird"); import U2f = require("u2f"); import u2fApi = require("u2f-api"); -import Endpoints = require("../../../server/endpoints"); import jslogger = require("js-logger"); import { Notifier } from "../Notifier"; +import Endpoints = require("../../../../shared/api"); export default function (window: Window, $: JQueryStatic) { const notifier = new Notifier(".notification", $); diff --git a/src/client/thirdparties/qrcode.min.js b/client/src/thirdparties/qrcode.min.js similarity index 100% rename from src/client/thirdparties/qrcode.min.js rename to client/src/thirdparties/qrcode.min.js diff --git a/test/unit/client/Notifier.test.ts b/client/test/Notifier.test.ts similarity index 97% rename from test/unit/client/Notifier.test.ts rename to client/test/Notifier.test.ts index 33e4331d..70bfea14 100644 --- a/test/unit/client/Notifier.test.ts +++ b/client/test/Notifier.test.ts @@ -3,7 +3,7 @@ import Assert = require("assert"); import Sinon = require("sinon"); import JQueryMock = require("./mocks/jquery"); -import { Notifier } from "../../../src/client/lib/Notifier"; +import { Notifier } from "../src/lib/Notifier"; describe("test notifier", function() { const SELECTOR = "dummy-selector"; diff --git a/test/unit/client/firstfactor/FirstFactorValidator.test.ts b/client/test/firstfactor/FirstFactorValidator.test.ts similarity index 94% rename from test/unit/client/firstfactor/FirstFactorValidator.test.ts rename to client/test/firstfactor/FirstFactorValidator.test.ts index cf3a954c..49e4f232 100644 --- a/test/unit/client/firstfactor/FirstFactorValidator.test.ts +++ b/client/test/firstfactor/FirstFactorValidator.test.ts @@ -1,5 +1,5 @@ -import FirstFactorValidator = require("../../../../src/client/lib/firstfactor/FirstFactorValidator"); +import FirstFactorValidator = require("../../src/lib/firstfactor/FirstFactorValidator"); import JQueryMock = require("../mocks/jquery"); import BluebirdPromise = require("bluebird"); import Assert = require("assert"); diff --git a/test/unit/client/mocks/NotifierStub.ts b/client/test/mocks/NotifierStub.ts similarity index 89% rename from test/unit/client/mocks/NotifierStub.ts rename to client/test/mocks/NotifierStub.ts index 66cf3769..9c268d66 100644 --- a/test/unit/client/mocks/NotifierStub.ts +++ b/client/test/mocks/NotifierStub.ts @@ -1,6 +1,6 @@ import Sinon = require("sinon"); -import { INotifier } from "../../../../src/client/lib/INotifier"; +import { INotifier } from "../../src/lib/INotifier"; export class NotifierStub implements INotifier { successStub: Sinon.SinonStub; diff --git a/test/unit/client/mocks/jquery.ts b/client/test/mocks/jquery.ts similarity index 100% rename from test/unit/client/mocks/jquery.ts rename to client/test/mocks/jquery.ts diff --git a/test/unit/client/mocks/u2f-api.ts b/client/test/mocks/u2f-api.ts similarity index 100% rename from test/unit/client/mocks/u2f-api.ts rename to client/test/mocks/u2f-api.ts diff --git a/test/unit/client/secondfactor/TOTPValidator.test.ts b/client/test/secondfactor/TOTPValidator.test.ts similarity index 93% rename from test/unit/client/secondfactor/TOTPValidator.test.ts rename to client/test/secondfactor/TOTPValidator.test.ts index c2fa57d6..e03b0b9a 100644 --- a/test/unit/client/secondfactor/TOTPValidator.test.ts +++ b/client/test/secondfactor/TOTPValidator.test.ts @@ -1,5 +1,5 @@ -import TOTPValidator = require("../../../../src/client/lib/secondfactor/TOTPValidator"); +import TOTPValidator = require("../../src/lib/secondfactor/TOTPValidator"); import JQueryMock = require("../mocks/jquery"); import BluebirdPromise = require("bluebird"); import Assert = require("assert"); diff --git a/test/unit/client/secondfactor/U2FValidator.test.ts b/client/test/secondfactor/U2FValidator.test.ts similarity index 94% rename from test/unit/client/secondfactor/U2FValidator.test.ts rename to client/test/secondfactor/U2FValidator.test.ts index c464715a..c57906a4 100644 --- a/test/unit/client/secondfactor/U2FValidator.test.ts +++ b/client/test/secondfactor/U2FValidator.test.ts @@ -1,9 +1,9 @@ -import U2FValidator = require("../../../../src/client/lib/secondfactor/U2FValidator"); -import { INotifier } from "../../../../src/client/lib/INotifier"; +import U2FValidator = require("../../src/lib/secondfactor/U2FValidator"); +import { INotifier } from "../../src/lib/INotifier"; import JQueryMock = require("../mocks/jquery"); import U2FApiMock = require("../mocks/u2f-api"); -import { SignMessage } from "../../../../src/server/lib/routes/secondfactor/u2f/sign_request/SignMessage"; +import { SignMessage } from "../../../shared/SignMessage"; import BluebirdPromise = require("bluebird"); import Assert = require("assert"); import { NotifierStub } from "../mocks/NotifierStub"; diff --git a/test/unit/client/totp-register/totp-register.test.ts b/client/test/totp-register/totp-register.test.ts similarity index 80% rename from test/unit/client/totp-register/totp-register.test.ts rename to client/test/totp-register/totp-register.test.ts index 5e97a84e..86fc455a 100644 --- a/test/unit/client/totp-register/totp-register.test.ts +++ b/client/test/totp-register/totp-register.test.ts @@ -2,8 +2,8 @@ import sinon = require("sinon"); import assert = require("assert"); -import UISelector = require("../../../../src/client/lib/totp-register/ui-selector"); -import TOTPRegister = require("../../../../src/client/lib/totp-register/totp-register"); +import UISelector = require("../../src/lib/totp-register/ui-selector"); +import TOTPRegister = require("../../src/lib/totp-register/totp-register"); describe("test totp-register", function() { let jqueryMock: any; diff --git a/tsconfig.json b/client/tsconfig.json similarity index 68% rename from tsconfig.json rename to client/tsconfig.json index f59e34c0..0bb4d62f 100644 --- a/tsconfig.json +++ b/client/tsconfig.json @@ -6,17 +6,19 @@ "noImplicitAny": true, "sourceMap": true, "removeComments": true, - "outDir": "dist", + "outDir": "../dist", "baseUrl": ".", "paths": { "*": [ - "./src/types/*", - "./node_modules/@types/*" + "./types/*", + "../shared/types/*" ] } }, - "includes": [ - "src/**/*", + "include": [ + "src/**/*" + ], + "exclude": [ "test/**/*" ] } diff --git a/tslint.json b/client/tslint.json similarity index 100% rename from tslint.json rename to client/tslint.json diff --git a/src/types/u2f-api.d.ts b/client/types/u2f-api.d.ts similarity index 100% rename from src/types/u2f-api.d.ts rename to client/types/u2f-api.d.ts diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 196ecac5..083b5763 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -3,7 +3,8 @@ services: authelia: volumes: - ./test:/usr/src/test - - ./dist/src/server:/usr/src + - ./dist/server:/usr/src/server + - ./dist/shared:/usr/src/shared - ./node_modules:/usr/src/node_modules - ./config.template.yml:/etc/authelia/config.yml:ro networks: diff --git a/package.json b/package.json index 7f31f9f1..e9523063 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "3.4.0", "description": "2FA Single Sign-On server for nginx using LDAP, TOTP and U2F", "bin": { - "authelia": "./dist/src/server/index.js" + "authelia": "./dist/server/src/index.js" }, "scripts": { "test": "./node_modules/.bin/grunt unit-tests", @@ -83,6 +83,7 @@ "grunt-contrib-copy": "^1.0.0", "grunt-contrib-cssmin": "^2.2.0", "grunt-contrib-watch": "^1.0.0", + "grunt-env": "^0.4.4", "grunt-run": "^0.6.0", "istanbul": "^0.4.5", "jquery": "^3.2.1", diff --git a/scripts/integration-tests.sh b/scripts/integration-tests.sh index 59c9bf15..1cabe9bc 100755 --- a/scripts/integration-tests.sh +++ b/scripts/integration-tests.sh @@ -3,6 +3,10 @@ DC_SCRIPT=./scripts/example-commit/dc-example.sh EXPECTED_SERVICES_COUNT=6 +build_services() { + $DC_SCRIPT build authelia +} + start_services() { $DC_SCRIPT up -d mongo redis openldap authelia nginx smtp sleep 3 @@ -32,7 +36,7 @@ run_integration_tests() { expect_services_count $EXPECTED_SERVICES_COUNT sleep 5 - ./node_modules/.bin/grunt run:integration-tests + ./node_modules/.bin/grunt run:test-int shut_services } @@ -59,6 +63,9 @@ set -e echo "Make sure services are not already running" shut_services +# Build the container +build_services + # Prepare & test example from end user perspective run_integration_tests diff --git a/scripts/travis.sh b/scripts/travis.sh index 7fcb42f3..97e2c545 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -6,7 +6,7 @@ docker --version docker-compose --version # Run unit tests -grunt test +grunt test-unit # Build the app from Typescript and package grunt build-dist diff --git a/src/server/index.ts b/server/src/index.ts similarity index 100% rename from src/server/index.ts rename to server/src/index.ts diff --git a/src/server/lib/AuthenticationRegulator.ts b/server/src/lib/AuthenticationRegulator.ts similarity index 100% rename from src/server/lib/AuthenticationRegulator.ts rename to server/src/lib/AuthenticationRegulator.ts diff --git a/src/server/lib/AuthenticationSession.ts b/server/src/lib/AuthenticationSession.ts similarity index 100% rename from src/server/lib/AuthenticationSession.ts rename to server/src/lib/AuthenticationSession.ts diff --git a/src/server/lib/AuthenticationValidator.ts b/server/src/lib/AuthenticationValidator.ts similarity index 100% rename from src/server/lib/AuthenticationValidator.ts rename to server/src/lib/AuthenticationValidator.ts diff --git a/src/server/lib/ErrorReplies.ts b/server/src/lib/ErrorReplies.ts similarity index 100% rename from src/server/lib/ErrorReplies.ts rename to server/src/lib/ErrorReplies.ts diff --git a/src/server/lib/Exceptions.ts b/server/src/lib/Exceptions.ts similarity index 100% rename from src/server/lib/Exceptions.ts rename to server/src/lib/Exceptions.ts diff --git a/src/server/lib/FirstFactorValidator.ts b/server/src/lib/FirstFactorValidator.ts similarity index 100% rename from src/server/lib/FirstFactorValidator.ts rename to server/src/lib/FirstFactorValidator.ts diff --git a/src/server/lib/IdentityCheckMiddleware.ts b/server/src/lib/IdentityCheckMiddleware.ts similarity index 100% rename from src/server/lib/IdentityCheckMiddleware.ts rename to server/src/lib/IdentityCheckMiddleware.ts diff --git a/src/server/lib/IdentityCheckPreValidationTemplate.ts b/server/src/lib/IdentityCheckPreValidationTemplate.ts similarity index 100% rename from src/server/lib/IdentityCheckPreValidationTemplate.ts rename to server/src/lib/IdentityCheckPreValidationTemplate.ts diff --git a/src/server/lib/RestApi.ts b/server/src/lib/RestApi.ts similarity index 98% rename from src/server/lib/RestApi.ts rename to server/src/lib/RestApi.ts index efea6906..67b7af3c 100644 --- a/src/server/lib/RestApi.ts +++ b/server/src/lib/RestApi.ts @@ -31,7 +31,7 @@ import Error403Get = require("./routes/error/403/get"); import Error404Get = require("./routes/error/404/get"); import { ServerVariablesHandler } from "./ServerVariablesHandler"; -import Endpoints = require("../endpoints"); +import Endpoints = require("../../../shared/api"); function withLog(fn: (req: Express.Request, res: Express.Response) => void) { return function(req: Express.Request, res: Express.Response) { diff --git a/src/server/lib/Server.ts b/server/src/lib/Server.ts similarity index 100% rename from src/server/lib/Server.ts rename to server/src/lib/Server.ts diff --git a/src/server/lib/ServerVariablesHandler.ts b/server/src/lib/ServerVariablesHandler.ts similarity index 100% rename from src/server/lib/ServerVariablesHandler.ts rename to server/src/lib/ServerVariablesHandler.ts diff --git a/src/server/lib/TOTPGenerator.ts b/server/src/lib/TOTPGenerator.ts similarity index 100% rename from src/server/lib/TOTPGenerator.ts rename to server/src/lib/TOTPGenerator.ts diff --git a/src/server/lib/TOTPValidator.ts b/server/src/lib/TOTPValidator.ts similarity index 100% rename from src/server/lib/TOTPValidator.ts rename to server/src/lib/TOTPValidator.ts diff --git a/src/server/lib/access_control/AccessController.ts b/server/src/lib/access_control/AccessController.ts similarity index 100% rename from src/server/lib/access_control/AccessController.ts rename to server/src/lib/access_control/AccessController.ts diff --git a/src/server/lib/access_control/DomainMatcher.ts b/server/src/lib/access_control/DomainMatcher.ts similarity index 100% rename from src/server/lib/access_control/DomainMatcher.ts rename to server/src/lib/access_control/DomainMatcher.ts diff --git a/src/server/lib/access_control/IAccessController.ts b/server/src/lib/access_control/IAccessController.ts similarity index 100% rename from src/server/lib/access_control/IAccessController.ts rename to server/src/lib/access_control/IAccessController.ts diff --git a/src/server/lib/configuration/Configuration.d.ts b/server/src/lib/configuration/Configuration.d.ts similarity index 100% rename from src/server/lib/configuration/Configuration.d.ts rename to server/src/lib/configuration/Configuration.d.ts diff --git a/src/server/lib/configuration/ConfigurationAdapter.ts b/server/src/lib/configuration/ConfigurationAdapter.ts similarity index 100% rename from src/server/lib/configuration/ConfigurationAdapter.ts rename to server/src/lib/configuration/ConfigurationAdapter.ts diff --git a/src/server/lib/configuration/SessionConfigurationBuilder.ts b/server/src/lib/configuration/SessionConfigurationBuilder.ts similarity index 100% rename from src/server/lib/configuration/SessionConfigurationBuilder.ts rename to server/src/lib/configuration/SessionConfigurationBuilder.ts diff --git a/src/server/lib/connectors/mongo/IMongoClient.d.ts b/server/src/lib/connectors/mongo/IMongoClient.d.ts similarity index 100% rename from src/server/lib/connectors/mongo/IMongoClient.d.ts rename to server/src/lib/connectors/mongo/IMongoClient.d.ts diff --git a/src/server/lib/connectors/mongo/IMongoConnector.d.ts b/server/src/lib/connectors/mongo/IMongoConnector.d.ts similarity index 100% rename from src/server/lib/connectors/mongo/IMongoConnector.d.ts rename to server/src/lib/connectors/mongo/IMongoConnector.d.ts diff --git a/src/server/lib/connectors/mongo/IMongoConnectorFactory.d.ts b/server/src/lib/connectors/mongo/IMongoConnectorFactory.d.ts similarity index 100% rename from src/server/lib/connectors/mongo/IMongoConnectorFactory.d.ts rename to server/src/lib/connectors/mongo/IMongoConnectorFactory.d.ts diff --git a/src/server/lib/connectors/mongo/MongoClient.ts b/server/src/lib/connectors/mongo/MongoClient.ts similarity index 100% rename from src/server/lib/connectors/mongo/MongoClient.ts rename to server/src/lib/connectors/mongo/MongoClient.ts diff --git a/src/server/lib/connectors/mongo/MongoConnector.ts b/server/src/lib/connectors/mongo/MongoConnector.ts similarity index 100% rename from src/server/lib/connectors/mongo/MongoConnector.ts rename to server/src/lib/connectors/mongo/MongoConnector.ts diff --git a/src/server/lib/connectors/mongo/MongoConnectorFactory.ts b/server/src/lib/connectors/mongo/MongoConnectorFactory.ts similarity index 100% rename from src/server/lib/connectors/mongo/MongoConnectorFactory.ts rename to server/src/lib/connectors/mongo/MongoConnectorFactory.ts diff --git a/src/server/lib/ldap/Authenticator.ts b/server/src/lib/ldap/Authenticator.ts similarity index 100% rename from src/server/lib/ldap/Authenticator.ts rename to server/src/lib/ldap/Authenticator.ts diff --git a/src/server/lib/ldap/Client.ts b/server/src/lib/ldap/Client.ts similarity index 93% rename from src/server/lib/ldap/Client.ts rename to server/src/lib/ldap/Client.ts index ea3da1b6..834f8b1e 100644 --- a/src/server/lib/ldap/Client.ts +++ b/server/src/lib/ldap/Client.ts @@ -14,6 +14,16 @@ interface SearchEntry { object: any; } +declare module "ldapjs" { + export interface ClientAsync { + on(event: string, callback: (data?: any) => void): void; + bindAsync(username: string, password: string): BluebirdPromise; + unbindAsync(): BluebirdPromise; + searchAsync(base: string, query: Ldapjs.SearchOptions): BluebirdPromise; + modifyAsync(userdn: string, change: Ldapjs.Change): BluebirdPromise; + } +} + export class Client implements IClient { private userDN: string; private password: string; diff --git a/src/server/lib/ldap/ClientFactory.ts b/server/src/lib/ldap/ClientFactory.ts similarity index 100% rename from src/server/lib/ldap/ClientFactory.ts rename to server/src/lib/ldap/ClientFactory.ts diff --git a/src/server/lib/ldap/EmailsRetriever.ts b/server/src/lib/ldap/EmailsRetriever.ts similarity index 100% rename from src/server/lib/ldap/EmailsRetriever.ts rename to server/src/lib/ldap/EmailsRetriever.ts diff --git a/src/server/lib/ldap/IAuthenticator.ts b/server/src/lib/ldap/IAuthenticator.ts similarity index 100% rename from src/server/lib/ldap/IAuthenticator.ts rename to server/src/lib/ldap/IAuthenticator.ts diff --git a/src/server/lib/ldap/IClient.ts b/server/src/lib/ldap/IClient.ts similarity index 100% rename from src/server/lib/ldap/IClient.ts rename to server/src/lib/ldap/IClient.ts diff --git a/src/server/lib/ldap/IClientFactory.ts b/server/src/lib/ldap/IClientFactory.ts similarity index 100% rename from src/server/lib/ldap/IClientFactory.ts rename to server/src/lib/ldap/IClientFactory.ts diff --git a/src/server/lib/ldap/IEmailsRetriever.ts b/server/src/lib/ldap/IEmailsRetriever.ts similarity index 100% rename from src/server/lib/ldap/IEmailsRetriever.ts rename to server/src/lib/ldap/IEmailsRetriever.ts diff --git a/src/server/lib/ldap/IPasswordUpdater.ts b/server/src/lib/ldap/IPasswordUpdater.ts similarity index 100% rename from src/server/lib/ldap/IPasswordUpdater.ts rename to server/src/lib/ldap/IPasswordUpdater.ts diff --git a/src/server/lib/ldap/PasswordUpdater.ts b/server/src/lib/ldap/PasswordUpdater.ts similarity index 100% rename from src/server/lib/ldap/PasswordUpdater.ts rename to server/src/lib/ldap/PasswordUpdater.ts diff --git a/src/server/lib/notifiers/AbstractEmailNotifier.ts b/server/src/lib/notifiers/AbstractEmailNotifier.ts similarity index 100% rename from src/server/lib/notifiers/AbstractEmailNotifier.ts rename to server/src/lib/notifiers/AbstractEmailNotifier.ts diff --git a/src/server/lib/notifiers/GMailNotifier.ts b/server/src/lib/notifiers/GMailNotifier.ts similarity index 100% rename from src/server/lib/notifiers/GMailNotifier.ts rename to server/src/lib/notifiers/GMailNotifier.ts diff --git a/src/server/lib/notifiers/INotifier.d.ts b/server/src/lib/notifiers/INotifier.d.ts similarity index 100% rename from src/server/lib/notifiers/INotifier.d.ts rename to server/src/lib/notifiers/INotifier.d.ts diff --git a/src/server/lib/notifiers/NotifierFactory.ts b/server/src/lib/notifiers/NotifierFactory.ts similarity index 100% rename from src/server/lib/notifiers/NotifierFactory.ts rename to server/src/lib/notifiers/NotifierFactory.ts diff --git a/src/server/lib/notifiers/SmtpNotifier.ts b/server/src/lib/notifiers/SmtpNotifier.ts similarity index 100% rename from src/server/lib/notifiers/SmtpNotifier.ts rename to server/src/lib/notifiers/SmtpNotifier.ts diff --git a/src/server/lib/routes/FirstFactorBlocker.ts b/server/src/lib/routes/FirstFactorBlocker.ts similarity index 100% rename from src/server/lib/routes/FirstFactorBlocker.ts rename to server/src/lib/routes/FirstFactorBlocker.ts diff --git a/src/server/lib/routes/error/401/get.ts b/server/src/lib/routes/error/401/get.ts similarity index 100% rename from src/server/lib/routes/error/401/get.ts rename to server/src/lib/routes/error/401/get.ts diff --git a/src/server/lib/routes/error/403/get.ts b/server/src/lib/routes/error/403/get.ts similarity index 100% rename from src/server/lib/routes/error/403/get.ts rename to server/src/lib/routes/error/403/get.ts diff --git a/src/server/lib/routes/error/404/get.ts b/server/src/lib/routes/error/404/get.ts similarity index 100% rename from src/server/lib/routes/error/404/get.ts rename to server/src/lib/routes/error/404/get.ts diff --git a/src/server/lib/routes/firstfactor/get.ts b/server/src/lib/routes/firstfactor/get.ts similarity index 92% rename from src/server/lib/routes/firstfactor/get.ts rename to server/src/lib/routes/firstfactor/get.ts index 01d8ac73..e2ba0d08 100644 --- a/src/server/lib/routes/firstfactor/get.ts +++ b/server/src/lib/routes/firstfactor/get.ts @@ -2,7 +2,7 @@ import express = require("express"); import objectPath = require("object-path"); import winston = require("winston"); -import Endpoints = require("../../../endpoints"); +import Endpoints = require("../../../../../shared/api"); import AuthenticationValidator = require("../../AuthenticationValidator"); import { ServerVariablesHandler } from "../../ServerVariablesHandler"; import BluebirdPromise = require("bluebird"); diff --git a/src/server/lib/routes/firstfactor/post.ts b/server/src/lib/routes/firstfactor/post.ts similarity index 97% rename from src/server/lib/routes/firstfactor/post.ts rename to server/src/lib/routes/firstfactor/post.ts index 869e9d4f..0bda3855 100644 --- a/src/server/lib/routes/firstfactor/post.ts +++ b/server/src/lib/routes/firstfactor/post.ts @@ -6,11 +6,11 @@ import express = require("express"); import { AccessController } from "../../access_control/AccessController"; import { AuthenticationRegulator } from "../../AuthenticationRegulator"; import { GroupsAndEmails } from "../../ldap/IClient"; -import Endpoint = require("../../../endpoints"); +import Endpoint = require("../../../../../shared/api"); import ErrorReplies = require("../../ErrorReplies"); import { ServerVariablesHandler } from "../../ServerVariablesHandler"; import AuthenticationSession = require("../../AuthenticationSession"); -import Constants = require("../../../constants"); +import Constants = require("../../../../../shared/constants"); export default function (req: express.Request, res: express.Response): BluebirdPromise { const username: string = req.body.username; diff --git a/src/server/lib/routes/logout/get.ts b/server/src/lib/routes/logout/get.ts similarity index 100% rename from src/server/lib/routes/logout/get.ts rename to server/src/lib/routes/logout/get.ts diff --git a/src/server/lib/routes/password-reset/constants.ts b/server/src/lib/routes/password-reset/constants.ts similarity index 100% rename from src/server/lib/routes/password-reset/constants.ts rename to server/src/lib/routes/password-reset/constants.ts diff --git a/src/server/lib/routes/password-reset/form/post.ts b/server/src/lib/routes/password-reset/form/post.ts similarity index 100% rename from src/server/lib/routes/password-reset/form/post.ts rename to server/src/lib/routes/password-reset/form/post.ts diff --git a/src/server/lib/routes/password-reset/identity/PasswordResetHandler.ts b/server/src/lib/routes/password-reset/identity/PasswordResetHandler.ts similarity index 100% rename from src/server/lib/routes/password-reset/identity/PasswordResetHandler.ts rename to server/src/lib/routes/password-reset/identity/PasswordResetHandler.ts diff --git a/src/server/lib/routes/password-reset/request/get.ts b/server/src/lib/routes/password-reset/request/get.ts similarity index 100% rename from src/server/lib/routes/password-reset/request/get.ts rename to server/src/lib/routes/password-reset/request/get.ts diff --git a/src/server/lib/routes/secondfactor/get.ts b/server/src/lib/routes/secondfactor/get.ts similarity index 93% rename from src/server/lib/routes/secondfactor/get.ts rename to server/src/lib/routes/secondfactor/get.ts index f7520fae..ba033036 100644 --- a/src/server/lib/routes/secondfactor/get.ts +++ b/server/src/lib/routes/secondfactor/get.ts @@ -1,6 +1,6 @@ import Express = require("express"); -import Endpoints = require("../../../endpoints"); +import Endpoints = require("../../../../../shared/api"); import FirstFactorBlocker = require("../FirstFactorBlocker"); import BluebirdPromise = require("bluebird"); import { ServerVariablesHandler } from "../../ServerVariablesHandler"; diff --git a/src/server/lib/routes/secondfactor/redirect.ts b/server/src/lib/routes/secondfactor/redirect.ts similarity index 92% rename from src/server/lib/routes/secondfactor/redirect.ts rename to server/src/lib/routes/secondfactor/redirect.ts index 0ab94845..75ff801d 100644 --- a/src/server/lib/routes/secondfactor/redirect.ts +++ b/server/src/lib/routes/secondfactor/redirect.ts @@ -2,7 +2,7 @@ import express = require("express"); import objectPath = require("object-path"); import winston = require("winston"); -import Endpoints = require("../../../endpoints"); +import Endpoints = require("../../../../../shared/api"); import { ServerVariablesHandler } from "../../ServerVariablesHandler"; import AuthenticationSession = require("../../AuthenticationSession"); import BluebirdPromise = require("bluebird"); diff --git a/src/server/lib/routes/secondfactor/totp/constants.ts b/server/src/lib/routes/secondfactor/totp/constants.ts similarity index 100% rename from src/server/lib/routes/secondfactor/totp/constants.ts rename to server/src/lib/routes/secondfactor/totp/constants.ts diff --git a/src/server/lib/routes/secondfactor/totp/identity/RegistrationHandler.ts b/server/src/lib/routes/secondfactor/totp/identity/RegistrationHandler.ts similarity index 98% rename from src/server/lib/routes/secondfactor/totp/identity/RegistrationHandler.ts rename to server/src/lib/routes/secondfactor/totp/identity/RegistrationHandler.ts index b4adee97..968a3858 100644 --- a/src/server/lib/routes/secondfactor/totp/identity/RegistrationHandler.ts +++ b/server/src/lib/routes/secondfactor/totp/identity/RegistrationHandler.ts @@ -7,7 +7,7 @@ import { Identity } from "../../../../../../types/Identity"; import { IdentityValidable } from "../../../../IdentityCheckMiddleware"; import { PRE_VALIDATION_TEMPLATE } from "../../../../IdentityCheckPreValidationTemplate"; import Constants = require("../constants"); -import Endpoints = require("../../../../../endpoints"); +import Endpoints = require("../../../../../../../shared/api"); import ErrorReplies = require("../../../../ErrorReplies"); import { ServerVariablesHandler } from "../../../../ServerVariablesHandler"; import AuthenticationSession = require("../../../../AuthenticationSession"); diff --git a/src/server/lib/routes/secondfactor/totp/sign/post.ts b/server/src/lib/routes/secondfactor/totp/sign/post.ts similarity index 96% rename from src/server/lib/routes/secondfactor/totp/sign/post.ts rename to server/src/lib/routes/secondfactor/totp/sign/post.ts index 62059249..6e4275f6 100644 --- a/src/server/lib/routes/secondfactor/totp/sign/post.ts +++ b/server/src/lib/routes/secondfactor/totp/sign/post.ts @@ -5,7 +5,7 @@ import express = require("express"); import { TOTPSecretDocument } from "../../../../storage/TOTPSecretDocument"; import BluebirdPromise = require("bluebird"); import FirstFactorBlocker from "../../../FirstFactorBlocker"; -import Endpoints = require("../../../../../endpoints"); +import Endpoints = require("../../../../../../../shared/api"); import redirect from "../../redirect"; import ErrorReplies = require("../../../../ErrorReplies"); import { ServerVariablesHandler } from "./../../../../ServerVariablesHandler"; diff --git a/src/server/lib/routes/secondfactor/u2f/U2FCommon.ts b/server/src/lib/routes/secondfactor/u2f/U2FCommon.ts similarity index 100% rename from src/server/lib/routes/secondfactor/u2f/U2FCommon.ts rename to server/src/lib/routes/secondfactor/u2f/U2FCommon.ts diff --git a/src/server/lib/routes/secondfactor/u2f/identity/RegistrationHandler.ts b/server/src/lib/routes/secondfactor/u2f/identity/RegistrationHandler.ts similarity index 100% rename from src/server/lib/routes/secondfactor/u2f/identity/RegistrationHandler.ts rename to server/src/lib/routes/secondfactor/u2f/identity/RegistrationHandler.ts diff --git a/src/server/lib/routes/secondfactor/u2f/register/post.ts b/server/src/lib/routes/secondfactor/u2f/register/post.ts similarity index 100% rename from src/server/lib/routes/secondfactor/u2f/register/post.ts rename to server/src/lib/routes/secondfactor/u2f/register/post.ts diff --git a/src/server/lib/routes/secondfactor/u2f/register_request/get.ts b/server/src/lib/routes/secondfactor/u2f/register_request/get.ts similarity index 100% rename from src/server/lib/routes/secondfactor/u2f/register_request/get.ts rename to server/src/lib/routes/secondfactor/u2f/register_request/get.ts diff --git a/src/server/lib/routes/secondfactor/u2f/sign/post.ts b/server/src/lib/routes/secondfactor/u2f/sign/post.ts similarity index 100% rename from src/server/lib/routes/secondfactor/u2f/sign/post.ts rename to server/src/lib/routes/secondfactor/u2f/sign/post.ts diff --git a/src/server/lib/routes/secondfactor/u2f/sign_request/get.ts b/server/src/lib/routes/secondfactor/u2f/sign_request/get.ts similarity index 97% rename from src/server/lib/routes/secondfactor/u2f/sign_request/get.ts rename to server/src/lib/routes/secondfactor/u2f/sign_request/get.ts index 0755a01a..841927d8 100644 --- a/src/server/lib/routes/secondfactor/u2f/sign_request/get.ts +++ b/server/src/lib/routes/secondfactor/u2f/sign_request/get.ts @@ -8,7 +8,7 @@ import { UserDataStore } from "../../../../storage/UserDataStore"; import { U2FRegistrationDocument } from "../../../../storage/U2FRegistrationDocument"; import { Winston } from "../../../../../../types/Dependencies"; import exceptions = require("../../../../Exceptions"); -import { SignMessage } from "./SignMessage"; +import { SignMessage } from "../../../../../../../shared/SignMessage"; import FirstFactorBlocker from "../../../FirstFactorBlocker"; import ErrorReplies = require("../../../../ErrorReplies"); import { ServerVariablesHandler } from "../../../../ServerVariablesHandler"; diff --git a/src/server/lib/routes/verify/get.ts b/server/src/lib/routes/verify/get.ts similarity index 97% rename from src/server/lib/routes/verify/get.ts rename to server/src/lib/routes/verify/get.ts index 390b198a..7bd59d49 100644 --- a/src/server/lib/routes/verify/get.ts +++ b/server/src/lib/routes/verify/get.ts @@ -8,7 +8,7 @@ import AuthenticationValidator = require("../../AuthenticationValidator"); import ErrorReplies = require("../../ErrorReplies"); import { ServerVariablesHandler } from "../../ServerVariablesHandler"; import AuthenticationSession = require("../../AuthenticationSession"); -import Constants = require("../../../constants"); +import Constants = require("../../../../../shared/constants"); function verify_filter(req: express.Request, res: express.Response): BluebirdPromise { const logger = ServerVariablesHandler.getLogger(req.app); diff --git a/src/server/lib/storage/AuthenticationTraceDocument.d.ts b/server/src/lib/storage/AuthenticationTraceDocument.d.ts similarity index 100% rename from src/server/lib/storage/AuthenticationTraceDocument.d.ts rename to server/src/lib/storage/AuthenticationTraceDocument.d.ts diff --git a/src/server/lib/storage/CollectionFactoryFactory.ts b/server/src/lib/storage/CollectionFactoryFactory.ts similarity index 100% rename from src/server/lib/storage/CollectionFactoryFactory.ts rename to server/src/lib/storage/CollectionFactoryFactory.ts diff --git a/src/server/lib/storage/ICollection.d.ts b/server/src/lib/storage/ICollection.d.ts similarity index 100% rename from src/server/lib/storage/ICollection.d.ts rename to server/src/lib/storage/ICollection.d.ts diff --git a/src/server/lib/storage/ICollectionFactory.d.ts b/server/src/lib/storage/ICollectionFactory.d.ts similarity index 100% rename from src/server/lib/storage/ICollectionFactory.d.ts rename to server/src/lib/storage/ICollectionFactory.d.ts diff --git a/src/server/lib/storage/IUserDataStore.d.ts b/server/src/lib/storage/IUserDataStore.d.ts similarity index 100% rename from src/server/lib/storage/IUserDataStore.d.ts rename to server/src/lib/storage/IUserDataStore.d.ts diff --git a/src/server/lib/storage/IdentityValidationDocument.d.ts b/server/src/lib/storage/IdentityValidationDocument.d.ts similarity index 100% rename from src/server/lib/storage/IdentityValidationDocument.d.ts rename to server/src/lib/storage/IdentityValidationDocument.d.ts diff --git a/src/server/lib/storage/TOTPSecretDocument.d.ts b/server/src/lib/storage/TOTPSecretDocument.d.ts similarity index 100% rename from src/server/lib/storage/TOTPSecretDocument.d.ts rename to server/src/lib/storage/TOTPSecretDocument.d.ts diff --git a/src/server/lib/storage/U2FRegistrationDocument.d.ts b/server/src/lib/storage/U2FRegistrationDocument.d.ts similarity index 100% rename from src/server/lib/storage/U2FRegistrationDocument.d.ts rename to server/src/lib/storage/U2FRegistrationDocument.d.ts diff --git a/src/server/lib/storage/UserDataStore.ts b/server/src/lib/storage/UserDataStore.ts similarity index 100% rename from src/server/lib/storage/UserDataStore.ts rename to server/src/lib/storage/UserDataStore.ts diff --git a/src/server/lib/storage/mongo/MongoCollection.ts b/server/src/lib/storage/mongo/MongoCollection.ts similarity index 100% rename from src/server/lib/storage/mongo/MongoCollection.ts rename to server/src/lib/storage/mongo/MongoCollection.ts diff --git a/src/server/lib/storage/mongo/MongoCollectionFactory.ts b/server/src/lib/storage/mongo/MongoCollectionFactory.ts similarity index 100% rename from src/server/lib/storage/mongo/MongoCollectionFactory.ts rename to server/src/lib/storage/mongo/MongoCollectionFactory.ts diff --git a/src/server/lib/storage/nedb/NedbCollection.ts b/server/src/lib/storage/nedb/NedbCollection.ts similarity index 66% rename from src/server/lib/storage/nedb/NedbCollection.ts rename to server/src/lib/storage/nedb/NedbCollection.ts index c42ea07a..88a93ad0 100644 --- a/src/server/lib/storage/nedb/NedbCollection.ts +++ b/server/src/lib/storage/nedb/NedbCollection.ts @@ -1,14 +1,23 @@ import BluebirdPromise = require("bluebird"); import { ICollection } from "../ICollection"; import Nedb = require("nedb"); -import { NedbAsync } from "nedb"; +declare module "nedb" { + export class NedbAsync extends Nedb { + constructor(pathOrOptions?: string | Nedb.DataStoreOptions); + updateAsync(query: any, updateQuery: any, options?: Nedb.UpdateOptions): BluebirdPromise; + findOneAsync(query: any): BluebirdPromise; + insertAsync(newDoc: T): BluebirdPromise; + removeAsync(query: any): BluebirdPromise; + countAsync(query: any): BluebirdPromise; + } +} export class NedbCollection implements ICollection { - private collection: NedbAsync; + private collection: Nedb.NedbAsync; constructor(options: Nedb.DataStoreOptions) { - this.collection = BluebirdPromise.promisifyAll(new Nedb(options)) as NedbAsync; + this.collection = BluebirdPromise.promisifyAll(new Nedb(options)) as Nedb.NedbAsync; } find(query: any, sortKeys?: any, count?: number): BluebirdPromise { diff --git a/src/server/lib/storage/nedb/NedbCollectionFactory.ts b/server/src/lib/storage/nedb/NedbCollectionFactory.ts similarity index 100% rename from src/server/lib/storage/nedb/NedbCollectionFactory.ts rename to server/src/lib/storage/nedb/NedbCollectionFactory.ts diff --git a/src/server/resources/email-template.ejs b/server/src/resources/email-template.ejs similarity index 100% rename from src/server/resources/email-template.ejs rename to server/src/resources/email-template.ejs diff --git a/src/server/views/already-logged-in.pug b/server/src/views/already-logged-in.pug similarity index 100% rename from src/server/views/already-logged-in.pug rename to server/src/views/already-logged-in.pug diff --git a/src/server/views/errors/401.pug b/server/src/views/errors/401.pug similarity index 100% rename from src/server/views/errors/401.pug rename to server/src/views/errors/401.pug diff --git a/src/server/views/errors/403.pug b/server/src/views/errors/403.pug similarity index 100% rename from src/server/views/errors/403.pug rename to server/src/views/errors/403.pug diff --git a/src/server/views/errors/404.pug b/server/src/views/errors/404.pug similarity index 100% rename from src/server/views/errors/404.pug rename to server/src/views/errors/404.pug diff --git a/src/server/views/firstfactor.pug b/server/src/views/firstfactor.pug similarity index 100% rename from src/server/views/firstfactor.pug rename to server/src/views/firstfactor.pug diff --git a/src/server/views/layout/layout.pug b/server/src/views/layout/layout.pug similarity index 100% rename from src/server/views/layout/layout.pug rename to server/src/views/layout/layout.pug diff --git a/src/server/views/need-identity-validation.pug b/server/src/views/need-identity-validation.pug similarity index 100% rename from src/server/views/need-identity-validation.pug rename to server/src/views/need-identity-validation.pug diff --git a/src/server/views/password-reset-form.pug b/server/src/views/password-reset-form.pug similarity index 100% rename from src/server/views/password-reset-form.pug rename to server/src/views/password-reset-form.pug diff --git a/src/server/views/password-reset-request.pug b/server/src/views/password-reset-request.pug similarity index 100% rename from src/server/views/password-reset-request.pug rename to server/src/views/password-reset-request.pug diff --git a/src/server/views/secondfactor.pug b/server/src/views/secondfactor.pug similarity index 100% rename from src/server/views/secondfactor.pug rename to server/src/views/secondfactor.pug diff --git a/src/server/views/totp-register.pug b/server/src/views/totp-register.pug similarity index 100% rename from src/server/views/totp-register.pug rename to server/src/views/totp-register.pug diff --git a/src/server/views/u2f-register.pug b/server/src/views/u2f-register.pug similarity index 100% rename from src/server/views/u2f-register.pug rename to server/src/views/u2f-register.pug diff --git a/test/unit/server/AuthenticationRegulator.test.ts b/server/test/AuthenticationRegulator.test.ts similarity index 97% rename from test/unit/server/AuthenticationRegulator.test.ts rename to server/test/AuthenticationRegulator.test.ts index 7f2c3aff..f3e40aa2 100644 --- a/test/unit/server/AuthenticationRegulator.test.ts +++ b/server/test/AuthenticationRegulator.test.ts @@ -3,9 +3,9 @@ import Sinon = require("sinon"); import BluebirdPromise = require("bluebird"); import Assert = require("assert"); -import { AuthenticationRegulator } from "../../../src/server/lib/AuthenticationRegulator"; +import { AuthenticationRegulator } from "../src/lib/AuthenticationRegulator"; import MockDate = require("mockdate"); -import exceptions = require("../../../src/server/lib/Exceptions"); +import exceptions = require("../src/lib/Exceptions"); import { UserDataStoreStub } from "./mocks/storage/UserDataStoreStub"; describe("test authentication regulator", function () { diff --git a/test/unit/server/IdentityCheckMiddleware.test.ts b/server/test/IdentityCheckMiddleware.test.ts similarity index 95% rename from test/unit/server/IdentityCheckMiddleware.test.ts rename to server/test/IdentityCheckMiddleware.test.ts index d187c998..37388c3e 100644 --- a/test/unit/server/IdentityCheckMiddleware.test.ts +++ b/server/test/IdentityCheckMiddleware.test.ts @@ -1,10 +1,10 @@ import sinon = require("sinon"); -import IdentityValidator = require("../../../src/server/lib/IdentityCheckMiddleware"); -import AuthenticationSession = require("../../../src/server/lib/AuthenticationSession"); -import { UserDataStore } from "../../../src/server/lib/storage/UserDataStore"; +import IdentityValidator = require("../src/lib/IdentityCheckMiddleware"); +import AuthenticationSession = require("../src/lib/AuthenticationSession"); +import { UserDataStore } from "../src/lib/storage/UserDataStore"; -import exceptions = require("../../../src/server/lib/Exceptions"); +import exceptions = require("../src/lib/Exceptions"); import assert = require("assert"); import Promise = require("bluebird"); import express = require("express"); diff --git a/test/unit/server/ServerConfiguration.test.ts b/server/test/ServerConfiguration.test.ts similarity index 89% rename from test/unit/server/ServerConfiguration.test.ts rename to server/test/ServerConfiguration.test.ts index cbc9d7ea..338d16bf 100644 --- a/test/unit/server/ServerConfiguration.test.ts +++ b/server/test/ServerConfiguration.test.ts @@ -9,9 +9,9 @@ import u2f = require("u2f"); import nodemailer = require("nodemailer"); import session = require("express-session"); -import { AppConfiguration, UserConfiguration } from "../../../src/server/lib/configuration/Configuration"; -import { GlobalDependencies, Nodemailer } from "../../../src/types/Dependencies"; -import Server from "../../../src/server/lib/Server"; +import { AppConfiguration, UserConfiguration } from "../src/lib/configuration/Configuration"; +import { GlobalDependencies, Nodemailer } from "../types/Dependencies"; +import Server from "../src/lib/Server"; describe("test server configuration", function () { diff --git a/test/unit/server/SessionConfigurationBuilder.test.ts b/server/test/SessionConfigurationBuilder.test.ts similarity index 94% rename from test/unit/server/SessionConfigurationBuilder.test.ts rename to server/test/SessionConfigurationBuilder.test.ts index 69882b23..0884d8ee 100644 --- a/test/unit/server/SessionConfigurationBuilder.test.ts +++ b/server/test/SessionConfigurationBuilder.test.ts @@ -1,6 +1,6 @@ -import { SessionConfigurationBuilder } from "../../../src/server/lib/configuration/SessionConfigurationBuilder"; -import { AppConfiguration } from "../../../src/server/lib/configuration/Configuration"; -import { GlobalDependencies } from "../../../src/types/Dependencies"; +import { SessionConfigurationBuilder } from "../src/lib/configuration/SessionConfigurationBuilder"; +import { AppConfiguration } from "../src/lib/configuration/Configuration"; +import { GlobalDependencies } from "../types/Dependencies"; import ExpressSession = require("express-session"); import ConnectRedis = require("connect-redis"); diff --git a/test/unit/server/TOTPValidator.test.ts b/server/test/TOTPValidator.test.ts similarity index 91% rename from test/unit/server/TOTPValidator.test.ts rename to server/test/TOTPValidator.test.ts index 0ef3faf5..6fd3981f 100644 --- a/test/unit/server/TOTPValidator.test.ts +++ b/server/test/TOTPValidator.test.ts @@ -1,5 +1,5 @@ -import { TOTPValidator } from "../../../src/server/lib/TOTPValidator"; +import { TOTPValidator } from "../src/lib/TOTPValidator"; import sinon = require("sinon"); import Promise = require("bluebird"); import SpeakeasyMock = require("./mocks/speakeasy"); diff --git a/test/unit/server/access_control/AccessController.test.ts b/server/test/access_control/AccessController.test.ts similarity index 98% rename from test/unit/server/access_control/AccessController.test.ts rename to server/test/access_control/AccessController.test.ts index 97c91fcd..aca3ee3e 100644 --- a/test/unit/server/access_control/AccessController.test.ts +++ b/server/test/access_control/AccessController.test.ts @@ -1,8 +1,8 @@ import Assert = require("assert"); import winston = require("winston"); -import { AccessController } from "../../../../src/server/lib/access_control/AccessController"; -import { ACLConfiguration, ACLRule } from "../../../../src/server/lib/configuration/Configuration"; +import { AccessController } from "../../src/lib/access_control/AccessController"; +import { ACLConfiguration, ACLRule } from "../../src/lib/configuration/Configuration"; describe("test access control manager", function () { let accessController: AccessController; diff --git a/test/unit/server/configuration/ConfigurationAdapter.test.ts b/server/test/configuration/ConfigurationAdapter.test.ts similarity index 94% rename from test/unit/server/configuration/ConfigurationAdapter.test.ts rename to server/test/configuration/ConfigurationAdapter.test.ts index d7886e8c..100a5e18 100644 --- a/test/unit/server/configuration/ConfigurationAdapter.test.ts +++ b/server/test/configuration/ConfigurationAdapter.test.ts @@ -2,8 +2,8 @@ import * as Assert from "assert"; import { UserConfiguration, LdapConfiguration, ACLConfiguration -} from "../../../../src/server/lib/configuration/Configuration"; -import { ConfigurationAdapter } from "../../../../src/server/lib/configuration/ConfigurationAdapter"; +} from "../../src/lib/configuration/Configuration"; +import { ConfigurationAdapter } from "../../src/lib/configuration/ConfigurationAdapter"; describe("test config adapter", function () { function build_yaml_config(): UserConfiguration { diff --git a/test/unit/server/configuration/LdapConfigurationAdaptation.test.ts b/server/test/configuration/LdapConfigurationAdaptation.test.ts similarity index 92% rename from test/unit/server/configuration/LdapConfigurationAdaptation.test.ts rename to server/test/configuration/LdapConfigurationAdaptation.test.ts index 0bf8df29..42c84d85 100644 --- a/test/unit/server/configuration/LdapConfigurationAdaptation.test.ts +++ b/server/test/configuration/LdapConfigurationAdaptation.test.ts @@ -1,6 +1,6 @@ import * as Assert from "assert"; -import { UserConfiguration, LdapConfiguration } from "../../../../src/server/lib/configuration/Configuration"; -import { ConfigurationAdapter } from "../../../../src/server/lib/configuration/ConfigurationAdapter"; +import { UserConfiguration, LdapConfiguration } from "../../src/lib/configuration/Configuration"; +import { ConfigurationAdapter } from "../../src/lib/configuration/ConfigurationAdapter"; describe("test ldap configuration adaptation", function () { function build_yaml_config(): UserConfiguration { diff --git a/test/unit/server/connectors/mongo/MongoClient.test.ts b/server/test/connectors/mongo/MongoClient.test.ts similarity index 92% rename from test/unit/server/connectors/mongo/MongoClient.test.ts rename to server/test/connectors/mongo/MongoClient.test.ts index c3f9a254..37ad0c4d 100644 --- a/test/unit/server/connectors/mongo/MongoClient.test.ts +++ b/server/test/connectors/mongo/MongoClient.test.ts @@ -1,7 +1,7 @@ import Assert = require("assert"); import Sinon = require("sinon"); import MongoDB = require("mongodb"); -import { MongoClient } from "../../../../../src/server/lib/connectors/mongo/MongoClient"; +import { MongoClient } from "../../../src/lib/connectors/mongo/MongoClient"; describe("MongoClient", function () { let mongoClientConnectStub: Sinon.SinonStub; diff --git a/test/unit/server/connectors/mongo/MongoConnector.test.ts b/server/test/connectors/mongo/MongoConnector.test.ts similarity index 88% rename from test/unit/server/connectors/mongo/MongoConnector.test.ts rename to server/test/connectors/mongo/MongoConnector.test.ts index 1bc24d4b..072bcd83 100644 --- a/test/unit/server/connectors/mongo/MongoConnector.test.ts +++ b/server/test/connectors/mongo/MongoConnector.test.ts @@ -2,8 +2,8 @@ import Assert = require("assert"); import Sinon = require("sinon"); import MongoDB = require("mongodb"); import BluebirdPromise = require("bluebird"); -import { IMongoClient } from "../../../../../src/server/lib/connectors/mongo/IMongoClient"; -import { MongoConnector } from "../../../../../src/server/lib/connectors/mongo/MongoConnector"; +import { IMongoClient } from "../../../src/lib/connectors/mongo/IMongoClient"; +import { MongoConnector } from "../../../src/lib/connectors/mongo/MongoConnector"; describe("MongoConnector", function () { let mongoClientConnectStub: Sinon.SinonStub; diff --git a/test/unit/server/connectors/mongo/MongoConnectorFactory.test.ts b/server/test/connectors/mongo/MongoConnectorFactory.test.ts similarity index 74% rename from test/unit/server/connectors/mongo/MongoConnectorFactory.test.ts rename to server/test/connectors/mongo/MongoConnectorFactory.test.ts index 2428507c..9d5d9cab 100644 --- a/test/unit/server/connectors/mongo/MongoConnectorFactory.test.ts +++ b/server/test/connectors/mongo/MongoConnectorFactory.test.ts @@ -1,5 +1,5 @@ import Assert = require("assert"); -import { MongoConnectorFactory } from "../../../../../src/server/lib/connectors/mongo/MongoConnectorFactory"; +import { MongoConnectorFactory } from "../../../src/lib/connectors/mongo/MongoConnectorFactory"; describe("MongoConnectorFactory", function () { describe("create", function () { diff --git a/test/unit/server/ldap/Authenticator.test.ts b/server/test/ldap/Authenticator.test.ts similarity index 96% rename from test/unit/server/ldap/Authenticator.test.ts rename to server/test/ldap/Authenticator.test.ts index 08373d4c..82373389 100644 --- a/test/unit/server/ldap/Authenticator.test.ts +++ b/server/test/ldap/Authenticator.test.ts @@ -1,6 +1,6 @@ -import { Authenticator } from "../../../../src/server/lib/ldap/Authenticator"; -import { LdapConfiguration } from "../../../../src/server/lib/configuration/Configuration"; +import { Authenticator } from "../../src/lib/ldap/Authenticator"; +import { LdapConfiguration } from "../../src/lib/configuration/Configuration"; import Sinon = require("sinon"); import BluebirdPromise = require("bluebird"); diff --git a/test/unit/server/ldap/EmailsRetriever.test.ts b/server/test/ldap/EmailsRetriever.test.ts similarity index 93% rename from test/unit/server/ldap/EmailsRetriever.test.ts rename to server/test/ldap/EmailsRetriever.test.ts index 2cfb7ad1..2826c462 100644 --- a/test/unit/server/ldap/EmailsRetriever.test.ts +++ b/server/test/ldap/EmailsRetriever.test.ts @@ -1,6 +1,6 @@ -import { EmailsRetriever } from "../../../../src/server/lib/ldap/EmailsRetriever"; -import { LdapConfiguration } from "../../../../src/server/lib/configuration/Configuration"; +import { EmailsRetriever } from "../../src/lib/ldap/EmailsRetriever"; +import { LdapConfiguration } from "../../src/lib/configuration/Configuration"; import Sinon = require("sinon"); import BluebirdPromise = require("bluebird"); diff --git a/test/unit/server/ldap/PasswordUpdater.test.ts b/server/test/ldap/PasswordUpdater.test.ts similarity index 93% rename from test/unit/server/ldap/PasswordUpdater.test.ts rename to server/test/ldap/PasswordUpdater.test.ts index 514bf601..634b22f1 100644 --- a/test/unit/server/ldap/PasswordUpdater.test.ts +++ b/server/test/ldap/PasswordUpdater.test.ts @@ -1,6 +1,6 @@ -import { PasswordUpdater } from "../../../../src/server/lib/ldap/PasswordUpdater"; -import { LdapConfiguration } from "../../../../src/server/lib/configuration/Configuration"; +import { PasswordUpdater } from "../../src/lib/ldap/PasswordUpdater"; +import { LdapConfiguration } from "../../src/lib/configuration/Configuration"; import Sinon = require("sinon"); import BluebirdPromise = require("bluebird"); diff --git a/test/unit/server/mocks/AccessControllerStub.ts b/server/test/mocks/AccessControllerStub.ts similarity index 79% rename from test/unit/server/mocks/AccessControllerStub.ts rename to server/test/mocks/AccessControllerStub.ts index 6d402e73..e295cdab 100644 --- a/test/unit/server/mocks/AccessControllerStub.ts +++ b/server/test/mocks/AccessControllerStub.ts @@ -1,6 +1,6 @@ import Sinon = require("sinon"); -import { IAccessController } from "../../../../src/server/lib/access_control/IAccessController"; +import { IAccessController } from "../../src/lib/access_control/IAccessController"; export class AccessControllerStub implements IAccessController { isAccessAllowedMock: Sinon.SinonStub; diff --git a/test/unit/server/mocks/AuthenticationRegulator.ts b/server/test/mocks/AuthenticationRegulator.ts similarity index 100% rename from test/unit/server/mocks/AuthenticationRegulator.ts rename to server/test/mocks/AuthenticationRegulator.ts diff --git a/test/unit/server/mocks/IdentityValidator.ts b/server/test/mocks/IdentityValidator.ts similarity index 87% rename from test/unit/server/mocks/IdentityValidator.ts rename to server/test/mocks/IdentityValidator.ts index 24898fc9..3fbe44dc 100644 --- a/test/unit/server/mocks/IdentityValidator.ts +++ b/server/test/mocks/IdentityValidator.ts @@ -1,9 +1,9 @@ import sinon = require("sinon"); -import { IdentityValidable } from "../../../../src/server/lib/IdentityCheckMiddleware"; +import { IdentityValidable } from "../../src/lib/IdentityCheckMiddleware"; import express = require("express"); import BluebirdPromise = require("bluebird"); -import { Identity } from "../../../../src/types/Identity"; +import { Identity } from "../../types/Identity"; export interface IdentityValidableMock { diff --git a/test/unit/server/mocks/Notifier.ts b/server/test/mocks/Notifier.ts similarity index 100% rename from test/unit/server/mocks/Notifier.ts rename to server/test/mocks/Notifier.ts diff --git a/test/unit/server/mocks/ServerVariablesMock.ts b/server/test/mocks/ServerVariablesMock.ts similarity index 92% rename from test/unit/server/mocks/ServerVariablesMock.ts rename to server/test/mocks/ServerVariablesMock.ts index ea3cdc8f..08caf776 100644 --- a/test/unit/server/mocks/ServerVariablesMock.ts +++ b/server/test/mocks/ServerVariablesMock.ts @@ -2,7 +2,7 @@ import Sinon = require("sinon"); import express = require("express"); import winston = require("winston"); import { UserDataStoreStub } from "./storage/UserDataStoreStub"; -import { VARIABLES_KEY } from "../../../../src/server/lib/ServerVariablesHandler"; +import { VARIABLES_KEY } from "../../src/lib/ServerVariablesHandler"; export interface ServerVariablesMock { logger: any; diff --git a/test/unit/server/mocks/TOTPValidator.ts b/server/test/mocks/TOTPValidator.ts similarity index 100% rename from test/unit/server/mocks/TOTPValidator.ts rename to server/test/mocks/TOTPValidator.ts diff --git a/test/unit/server/mocks/connectors/mongo/MongoClientStub.ts b/server/test/mocks/connectors/mongo/MongoClientStub.ts similarity index 77% rename from test/unit/server/mocks/connectors/mongo/MongoClientStub.ts rename to server/test/mocks/connectors/mongo/MongoClientStub.ts index 2ee4d063..81999b00 100644 --- a/test/unit/server/mocks/connectors/mongo/MongoClientStub.ts +++ b/server/test/mocks/connectors/mongo/MongoClientStub.ts @@ -1,6 +1,6 @@ import Sinon = require("sinon"); import MongoDB = require("mongodb"); -import { IMongoClient } from "../../../../../../src/server/lib/connectors/mongo/IMongoClient"; +import { IMongoClient } from "../../../../src/lib/connectors/mongo/IMongoClient"; export class MongoClientStub implements IMongoClient { public collectionStub: Sinon.SinonStub; diff --git a/test/unit/server/mocks/express.ts b/server/test/mocks/express.ts similarity index 100% rename from test/unit/server/mocks/express.ts rename to server/test/mocks/express.ts diff --git a/test/unit/server/mocks/ldap/ClientFactoryStub.ts b/server/test/mocks/ldap/ClientFactoryStub.ts similarity index 65% rename from test/unit/server/mocks/ldap/ClientFactoryStub.ts rename to server/test/mocks/ldap/ClientFactoryStub.ts index 26d3909e..2b3afe8e 100644 --- a/test/unit/server/mocks/ldap/ClientFactoryStub.ts +++ b/server/test/mocks/ldap/ClientFactoryStub.ts @@ -1,6 +1,6 @@ -import { IClient } from "../../../../../src/server/lib/ldap/IClient"; -import { IClientFactory } from "../../../../../src/server/lib/ldap/IClientFactory"; +import { IClient } from "../../../src/lib/ldap/IClient"; +import { IClientFactory } from "../../../src/lib/ldap/IClientFactory"; import Sinon = require("sinon"); export class ClientFactoryStub implements IClientFactory { diff --git a/test/unit/server/mocks/ldap/ClientStub.ts b/server/test/mocks/ldap/ClientStub.ts similarity index 93% rename from test/unit/server/mocks/ldap/ClientStub.ts rename to server/test/mocks/ldap/ClientStub.ts index faf3b74a..bcfdc2ae 100644 --- a/test/unit/server/mocks/ldap/ClientStub.ts +++ b/server/test/mocks/ldap/ClientStub.ts @@ -1,6 +1,6 @@ import BluebirdPromise = require("bluebird"); -import { IClient, GroupsAndEmails } from "../../../../../src/server/lib/ldap/IClient"; +import { IClient, GroupsAndEmails } from "../../../src/lib/ldap/IClient"; import Sinon = require("sinon"); export class ClientStub implements IClient { diff --git a/test/unit/server/mocks/ldapjs.ts b/server/test/mocks/ldapjs.ts similarity index 100% rename from test/unit/server/mocks/ldapjs.ts rename to server/test/mocks/ldapjs.ts diff --git a/test/unit/server/mocks/nodemailer.ts b/server/test/mocks/nodemailer.ts similarity index 100% rename from test/unit/server/mocks/nodemailer.ts rename to server/test/mocks/nodemailer.ts diff --git a/test/unit/server/mocks/speakeasy.ts b/server/test/mocks/speakeasy.ts similarity index 100% rename from test/unit/server/mocks/speakeasy.ts rename to server/test/mocks/speakeasy.ts diff --git a/test/unit/server/mocks/storage/CollectionFactoryStub.ts b/server/test/mocks/storage/CollectionFactoryStub.ts similarity index 66% rename from test/unit/server/mocks/storage/CollectionFactoryStub.ts rename to server/test/mocks/storage/CollectionFactoryStub.ts index 74936b28..947be55f 100644 --- a/test/unit/server/mocks/storage/CollectionFactoryStub.ts +++ b/server/test/mocks/storage/CollectionFactoryStub.ts @@ -1,7 +1,7 @@ import BluebirdPromise = require("bluebird"); import Sinon = require("sinon"); -import { ICollection } from "../../../../../src/server/lib/storage/ICollection"; -import { ICollectionFactory } from "../../../../../src/server/lib/storage/ICollectionFactory"; +import { ICollection } from "../../../src/lib/storage/ICollection"; +import { ICollectionFactory } from "../../../src/lib/storage/ICollectionFactory"; export class CollectionFactoryStub implements ICollectionFactory { buildStub: Sinon.SinonStub; diff --git a/test/unit/server/mocks/storage/CollectionStub.ts b/server/test/mocks/storage/CollectionStub.ts similarity index 93% rename from test/unit/server/mocks/storage/CollectionStub.ts rename to server/test/mocks/storage/CollectionStub.ts index 6b83267f..05dc76ba 100644 --- a/test/unit/server/mocks/storage/CollectionStub.ts +++ b/server/test/mocks/storage/CollectionStub.ts @@ -1,6 +1,6 @@ import BluebirdPromise = require("bluebird"); import Sinon = require("sinon"); -import { ICollection } from "../../../../../src/server/lib/storage/ICollection"; +import { ICollection } from "../../../src/lib/storage/ICollection"; export class CollectionStub implements ICollection { findStub: Sinon.SinonStub; diff --git a/test/unit/server/mocks/storage/UserDataStoreStub.ts b/server/test/mocks/storage/UserDataStoreStub.ts similarity index 79% rename from test/unit/server/mocks/storage/UserDataStoreStub.ts rename to server/test/mocks/storage/UserDataStoreStub.ts index cb709c4f..41fa0bb9 100644 --- a/test/unit/server/mocks/storage/UserDataStoreStub.ts +++ b/server/test/mocks/storage/UserDataStoreStub.ts @@ -1,14 +1,14 @@ import Sinon = require("sinon"); import BluebirdPromise = require("bluebird"); -import { TOTPSecretDocument } from "../../../../../src/server/lib/storage/TOTPSecretDocument"; -import { U2FRegistrationDocument } from "../../../../../src/server/lib/storage/U2FRegistrationDocument"; -import { U2FRegistration } from "../../../../../src/types/U2FRegistration"; -import { TOTPSecret } from "../../../../../src/types/TOTPSecret"; -import { AuthenticationTraceDocument } from "../../../../../src/server/lib/storage/AuthenticationTraceDocument"; -import { IdentityValidationDocument } from "../../../../../src/server/lib/storage/IdentityValidationDocument"; +import { TOTPSecretDocument } from "../../../src/lib/storage/TOTPSecretDocument"; +import { U2FRegistrationDocument } from "../../../src/lib/storage/U2FRegistrationDocument"; +import { U2FRegistration } from "../../../types/U2FRegistration"; +import { TOTPSecret } from "../../../types/TOTPSecret"; +import { AuthenticationTraceDocument } from "../../../src/lib/storage/AuthenticationTraceDocument"; +import { IdentityValidationDocument } from "../../../src/lib/storage/IdentityValidationDocument"; -import { IUserDataStore } from "../../../../../src/server/lib/storage/IUserDataStore"; +import { IUserDataStore } from "../../../src/lib/storage/IUserDataStore"; export class UserDataStoreStub implements IUserDataStore { saveU2FRegistrationStub: Sinon.SinonStub; diff --git a/test/unit/server/mocks/u2f.ts b/server/test/mocks/u2f.ts similarity index 100% rename from test/unit/server/mocks/u2f.ts rename to server/test/mocks/u2f.ts diff --git a/test/unit/server/notifiers/GMailNotifier.test.ts b/server/test/notifiers/GMailNotifier.test.ts similarity index 93% rename from test/unit/server/notifiers/GMailNotifier.test.ts rename to server/test/notifiers/GMailNotifier.test.ts index 08b6a112..d7c5828e 100644 --- a/test/unit/server/notifiers/GMailNotifier.test.ts +++ b/server/test/notifiers/GMailNotifier.test.ts @@ -3,7 +3,7 @@ import * as assert from "assert"; import BluebirdPromise = require("bluebird"); import NodemailerMock = require("../mocks/nodemailer"); -import GMailNotifier = require("../../../../src/server/lib/notifiers/GMailNotifier"); +import GMailNotifier = require("../../src/lib/notifiers/GMailNotifier"); describe("test gmail notifier", function () { diff --git a/test/unit/server/notifiers/NotifierFactory.test.ts b/server/test/notifiers/NotifierFactory.test.ts similarity index 82% rename from test/unit/server/notifiers/NotifierFactory.test.ts rename to server/test/notifiers/NotifierFactory.test.ts index a28034b0..19143277 100644 --- a/test/unit/server/notifiers/NotifierFactory.test.ts +++ b/server/test/notifiers/NotifierFactory.test.ts @@ -3,9 +3,9 @@ import * as sinon from "sinon"; import * as BluebirdPromise from "bluebird"; import * as assert from "assert"; -import { NotifierFactory } from "../../../../src/server/lib/notifiers/NotifierFactory"; -import { GMailNotifier } from "../../../../src/server/lib/notifiers/GMailNotifier"; -import { SmtpNotifier } from "../../../../src/server/lib/notifiers/SmtpNotifier"; +import { NotifierFactory } from "../../src/lib/notifiers/NotifierFactory"; +import { GMailNotifier } from "../../src/lib/notifiers/GMailNotifier"; +import { SmtpNotifier } from "../../src/lib/notifiers/SmtpNotifier"; import NodemailerMock = require("../mocks/nodemailer"); diff --git a/test/unit/server/requests.ts b/server/test/requests.ts similarity index 89% rename from test/unit/server/requests.ts rename to server/test/requests.ts index 557cf909..268556f5 100644 --- a/test/unit/server/requests.ts +++ b/server/test/requests.ts @@ -4,10 +4,24 @@ import request = require("request"); import assert = require("assert"); import express = require("express"); import nodemailer = require("nodemailer"); -import Endpoints = require("../../../src/server/endpoints"); +import Endpoints = require("../../shared/api"); import NodemailerMock = require("./mocks/nodemailer"); +declare module "request" { + export interface RequestAPI { + getAsync(uri: string, options?: RequiredUriUrl): BluebirdPromise; + getAsync(uri: string): BluebirdPromise; + getAsync(options: RequiredUriUrl & CoreOptions): BluebirdPromise; + + postAsync(uri: string, options?: CoreOptions): BluebirdPromise; + postAsync(uri: string): BluebirdPromise; + postAsync(options: RequiredUriUrl & CoreOptions): BluebirdPromise; + } +} + const requestAsync: typeof request = BluebirdPromise.promisifyAll(request) as typeof request; export = function (port: number) { diff --git a/test/unit/server/routes/errors/401/get.test.ts b/server/test/routes/errors/401/get.test.ts similarity index 85% rename from test/unit/server/routes/errors/401/get.test.ts rename to server/test/routes/errors/401/get.test.ts index 2728cb1f..72162285 100644 --- a/test/unit/server/routes/errors/401/get.test.ts +++ b/server/test/routes/errors/401/get.test.ts @@ -1,7 +1,7 @@ import Sinon = require("sinon"); import Express = require("express"); import Assert = require("assert"); -import Get401 from "../../../../../../src/server/lib/routes/error/401/get"; +import Get401 from "../../../../src/lib/routes/error/401/get"; describe("Server error 401", function () { it("should render the page", function () { diff --git a/test/unit/server/routes/errors/403/get.test.ts b/server/test/routes/errors/403/get.test.ts similarity index 85% rename from test/unit/server/routes/errors/403/get.test.ts rename to server/test/routes/errors/403/get.test.ts index b3b78721..09f141e3 100644 --- a/test/unit/server/routes/errors/403/get.test.ts +++ b/server/test/routes/errors/403/get.test.ts @@ -1,7 +1,7 @@ import Sinon = require("sinon"); import Express = require("express"); import Assert = require("assert"); -import Get403 from "../../../../../../src/server/lib/routes/error/403/get"; +import Get403 from "../../../../src/lib/routes/error/403/get"; describe("Server error 403", function () { it("should render the page", function () { diff --git a/test/unit/server/routes/errors/404/get.test.ts b/server/test/routes/errors/404/get.test.ts similarity index 85% rename from test/unit/server/routes/errors/404/get.test.ts rename to server/test/routes/errors/404/get.test.ts index fe20a4d1..fe283860 100644 --- a/test/unit/server/routes/errors/404/get.test.ts +++ b/server/test/routes/errors/404/get.test.ts @@ -1,7 +1,7 @@ import Sinon = require("sinon"); import Express = require("express"); import Assert = require("assert"); -import Get404 from "../../../../../../src/server/lib/routes/error/404/get"; +import Get404 from "../../../../src/lib/routes/error/404/get"; describe("Server error 404", function () { it("should render the page", function () { diff --git a/test/unit/server/routes/firstfactor/post.test.ts b/server/test/routes/firstfactor/post.test.ts similarity index 92% rename from test/unit/server/routes/firstfactor/post.test.ts rename to server/test/routes/firstfactor/post.test.ts index b5329b04..c7c1c866 100644 --- a/test/unit/server/routes/firstfactor/post.test.ts +++ b/server/test/routes/firstfactor/post.test.ts @@ -4,16 +4,16 @@ import BluebirdPromise = require("bluebird"); import assert = require("assert"); import winston = require("winston"); -import FirstFactorPost = require("../../../../../src/server/lib/routes/firstfactor/post"); -import exceptions = require("../../../../../src/server/lib/Exceptions"); -import AuthenticationSession = require("../../../../../src/server/lib/AuthenticationSession"); -import Endpoints = require("../../../../../src/server/endpoints"); +import FirstFactorPost = require("../../../src/lib/routes/firstfactor/post"); +import exceptions = require("../../../src/lib/Exceptions"); +import AuthenticationSession = require("../../../src/lib/AuthenticationSession"); +import Endpoints = require("../../../../shared/api"); import AuthenticationRegulatorMock = require("../../mocks/AuthenticationRegulator"); import { AccessControllerStub } from "../../mocks/AccessControllerStub"; import ExpressMock = require("../../mocks/express"); import ServerVariablesMock = require("../../mocks/ServerVariablesMock"); -import { ServerVariables } from "../../../../../src/server/lib/ServerVariablesHandler"; +import { ServerVariables } from "../../../src/lib/ServerVariablesHandler"; describe("test the first factor validation route", function () { let req: ExpressMock.RequestMock; diff --git a/test/unit/server/routes/password-reset/identity/PasswordResetHandler.test.ts b/server/test/routes/password-reset/identity/PasswordResetHandler.test.ts similarity index 90% rename from test/unit/server/routes/password-reset/identity/PasswordResetHandler.test.ts rename to server/test/routes/password-reset/identity/PasswordResetHandler.test.ts index 512a0eff..74e76116 100644 --- a/test/unit/server/routes/password-reset/identity/PasswordResetHandler.test.ts +++ b/server/test/routes/password-reset/identity/PasswordResetHandler.test.ts @@ -1,8 +1,8 @@ -import PasswordResetHandler from "../../../../../../src/server/lib/routes/password-reset/identity/PasswordResetHandler"; -import PasswordUpdater = require("../../../../../../src/server/lib/ldap/PasswordUpdater"); -import { ServerVariablesHandler } from "../../../../../../src/server/lib/ServerVariablesHandler"; -import { UserDataStore } from "../../../../../../src/server/lib/storage/UserDataStore"; +import PasswordResetHandler from "../../../../src/lib/routes/password-reset/identity/PasswordResetHandler"; +import PasswordUpdater = require("../../../../src/lib/ldap/PasswordUpdater"); +import { ServerVariablesHandler } from "../../../../src/lib/ServerVariablesHandler"; +import { UserDataStore } from "../../../../src/lib/storage/UserDataStore"; import Sinon = require("sinon"); import winston = require("winston"); import assert = require("assert"); diff --git a/test/unit/server/routes/password-reset/post.test.ts b/server/test/routes/password-reset/post.test.ts similarity index 89% rename from test/unit/server/routes/password-reset/post.test.ts rename to server/test/routes/password-reset/post.test.ts index 71a2cf50..920f97d2 100644 --- a/test/unit/server/routes/password-reset/post.test.ts +++ b/server/test/routes/password-reset/post.test.ts @@ -1,9 +1,9 @@ -import PasswordResetFormPost = require("../../../../../src/server/lib/routes/password-reset/form/post"); -import { PasswordUpdater } from "../../../../../src/server/lib/ldap/PasswordUpdater"; -import AuthenticationSession = require("../../../../../src/server/lib/AuthenticationSession"); -import { ServerVariablesHandler } from "../../../../../src/server/lib/ServerVariablesHandler"; -import { UserDataStore } from "../../../../../src/server/lib/storage/UserDataStore"; +import PasswordResetFormPost = require("../../../src/lib/routes/password-reset/form/post"); +import { PasswordUpdater } from "../../../src/lib/ldap/PasswordUpdater"; +import AuthenticationSession = require("../../../src/lib/AuthenticationSession"); +import { ServerVariablesHandler } from "../../../src/lib/ServerVariablesHandler"; +import { UserDataStore } from "../../../src/lib/storage/UserDataStore"; import Sinon = require("sinon"); import winston = require("winston"); import assert = require("assert"); diff --git a/test/unit/server/routes/secondfactor/totp/register/RegistrationHandler.test.ts b/server/test/routes/secondfactor/totp/register/RegistrationHandler.test.ts similarity index 88% rename from test/unit/server/routes/secondfactor/totp/register/RegistrationHandler.test.ts rename to server/test/routes/secondfactor/totp/register/RegistrationHandler.test.ts index cf13f90b..a913b1a4 100644 --- a/test/unit/server/routes/secondfactor/totp/register/RegistrationHandler.test.ts +++ b/server/test/routes/secondfactor/totp/register/RegistrationHandler.test.ts @@ -1,9 +1,9 @@ import Sinon = require("sinon"); import winston = require("winston"); -import RegistrationHandler from "../../../../../../../src/server/lib/routes/secondfactor/totp/identity/RegistrationHandler"; -import { Identity } from "../../../../../../../src/types/Identity"; -import AuthenticationSession = require("../../../../../../../src/server/lib/AuthenticationSession"); -import { UserDataStore } from "../../../../../../../src/server/lib/storage/UserDataStore"; +import RegistrationHandler from "../../../../../src/lib/routes/secondfactor/totp/identity/RegistrationHandler"; +import { Identity } from "../../../../../types/Identity"; +import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession"); +import { UserDataStore } from "../../../../../src/lib/storage/UserDataStore"; import assert = require("assert"); import BluebirdPromise = require("bluebird"); diff --git a/test/unit/server/routes/secondfactor/totp/sign/post.test.ts b/server/test/routes/secondfactor/totp/sign/post.test.ts similarity index 91% rename from test/unit/server/routes/secondfactor/totp/sign/post.test.ts rename to server/test/routes/secondfactor/totp/sign/post.test.ts index b7ce7a13..a562d1ba 100644 --- a/test/unit/server/routes/secondfactor/totp/sign/post.test.ts +++ b/server/test/routes/secondfactor/totp/sign/post.test.ts @@ -4,9 +4,9 @@ import sinon = require("sinon"); import assert = require("assert"); import winston = require("winston"); -import exceptions = require("../../../../../../../src/server/lib/Exceptions"); -import AuthenticationSession = require("../../../../../../../src/server/lib/AuthenticationSession"); -import SignPost = require("../../../../../../../src/server/lib/routes/secondfactor/totp/sign/post"); +import exceptions = require("../../../../../src/lib/Exceptions"); +import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession"); +import SignPost = require("../../../../../src/lib/routes/secondfactor/totp/sign/post"); import ExpressMock = require("../../../../mocks/express"); import TOTPValidatorMock = require("../../../../mocks/TOTPValidator"); diff --git a/test/unit/server/routes/secondfactor/u2f/identity/RegistrationHandler.test.ts b/server/test/routes/secondfactor/u2f/identity/RegistrationHandler.test.ts similarity index 91% rename from test/unit/server/routes/secondfactor/u2f/identity/RegistrationHandler.test.ts rename to server/test/routes/secondfactor/u2f/identity/RegistrationHandler.test.ts index 859b614e..11d28eb0 100644 --- a/test/unit/server/routes/secondfactor/u2f/identity/RegistrationHandler.test.ts +++ b/server/test/routes/secondfactor/u2f/identity/RegistrationHandler.test.ts @@ -3,9 +3,9 @@ import winston = require("winston"); import assert = require("assert"); import BluebirdPromise = require("bluebird"); -import { Identity } from "../../../../../../../src/types/Identity"; -import RegistrationHandler from "../../../../../../../src/server/lib/routes/secondfactor/u2f/identity/RegistrationHandler"; -import AuthenticationSession = require("../../../../../../../src/server/lib/AuthenticationSession"); +import { Identity } from "../../../../../types/Identity"; +import RegistrationHandler from "../../../../../src/lib/routes/secondfactor/u2f/identity/RegistrationHandler"; +import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession"); import ExpressMock = require("../../../../mocks/express"); import { UserDataStoreStub } from "../../../../mocks/storage/UserDataStoreStub"; diff --git a/test/unit/server/routes/secondfactor/u2f/register/post.test.ts b/server/test/routes/secondfactor/u2f/register/post.test.ts similarity index 94% rename from test/unit/server/routes/secondfactor/u2f/register/post.test.ts rename to server/test/routes/secondfactor/u2f/register/post.test.ts index 664fcea9..9a8ced38 100644 --- a/test/unit/server/routes/secondfactor/u2f/register/post.test.ts +++ b/server/test/routes/secondfactor/u2f/register/post.test.ts @@ -2,9 +2,9 @@ import sinon = require("sinon"); import BluebirdPromise = require("bluebird"); import assert = require("assert"); -import U2FRegisterPost = require("../../../../../../../src/server/lib/routes/secondfactor/u2f/register/post"); -import AuthenticationSession = require("../../../../../../../src/server/lib/AuthenticationSession"); -import { ServerVariablesHandler } from "../../../../../../../src/server/lib/ServerVariablesHandler"; +import U2FRegisterPost = require("../../../../../src/lib/routes/secondfactor/u2f/register/post"); +import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession"); +import { ServerVariablesHandler } from "../../../../../src/lib/ServerVariablesHandler"; import winston = require("winston"); import ExpressMock = require("../../../../mocks/express"); diff --git a/test/unit/server/routes/secondfactor/u2f/register_request/get.test.ts b/server/test/routes/secondfactor/u2f/register_request/get.test.ts similarity index 90% rename from test/unit/server/routes/secondfactor/u2f/register_request/get.test.ts rename to server/test/routes/secondfactor/u2f/register_request/get.test.ts index e647f944..0a6fae7a 100644 --- a/test/unit/server/routes/secondfactor/u2f/register_request/get.test.ts +++ b/server/test/routes/secondfactor/u2f/register_request/get.test.ts @@ -2,9 +2,9 @@ import sinon = require("sinon"); import BluebirdPromise = require("bluebird"); import assert = require("assert"); -import U2FRegisterRequestGet = require("../../../../../../../src/server/lib/routes/secondfactor/u2f/register_request/get"); -import AuthenticationSession = require("../../../../../../../src/server/lib/AuthenticationSession"); -import { ServerVariablesHandler } from "../../../../../../../src/server/lib/ServerVariablesHandler"; +import U2FRegisterRequestGet = require("../../../../../src/lib/routes/secondfactor/u2f/register_request/get"); +import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession"); +import { ServerVariablesHandler } from "../../../../../src/lib/ServerVariablesHandler"; import winston = require("winston"); import ExpressMock = require("../../../../mocks/express"); diff --git a/test/unit/server/routes/secondfactor/u2f/sign/post.test.ts b/server/test/routes/secondfactor/u2f/sign/post.test.ts similarity index 90% rename from test/unit/server/routes/secondfactor/u2f/sign/post.test.ts rename to server/test/routes/secondfactor/u2f/sign/post.test.ts index c033a287..54784f0c 100644 --- a/test/unit/server/routes/secondfactor/u2f/sign/post.test.ts +++ b/server/test/routes/secondfactor/u2f/sign/post.test.ts @@ -2,9 +2,9 @@ import sinon = require("sinon"); import BluebirdPromise = require("bluebird"); import Assert = require("assert"); -import U2FSignPost = require("../../../../../../../src/server/lib/routes/secondfactor/u2f/sign/post"); -import AuthenticationSession = require("../../../../../../../src/server/lib/AuthenticationSession"); -import { ServerVariablesHandler } from "../../../../../../../src/server/lib/ServerVariablesHandler"; +import U2FSignPost = require("../../../../../src/lib/routes/secondfactor/u2f/sign/post"); +import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession"); +import { ServerVariablesHandler } from "../../../../../src/lib/ServerVariablesHandler"; import winston = require("winston"); import ExpressMock = require("../../../../mocks/express"); diff --git a/test/unit/server/routes/secondfactor/u2f/sign_request/get.test.ts b/server/test/routes/secondfactor/u2f/sign_request/get.test.ts similarity index 84% rename from test/unit/server/routes/secondfactor/u2f/sign_request/get.test.ts rename to server/test/routes/secondfactor/u2f/sign_request/get.test.ts index 82fd79cb..9e3027b4 100644 --- a/test/unit/server/routes/secondfactor/u2f/sign_request/get.test.ts +++ b/server/test/routes/secondfactor/u2f/sign_request/get.test.ts @@ -2,9 +2,9 @@ import sinon = require("sinon"); import BluebirdPromise = require("bluebird"); import assert = require("assert"); -import U2FSignRequestGet = require("../../../../../../../src/server/lib/routes/secondfactor/u2f/sign_request/get"); -import AuthenticationSession = require("../../../../../../../src/server/lib/AuthenticationSession"); -import { ServerVariablesHandler } from "../../../../../../../src/server/lib/ServerVariablesHandler"; +import U2FSignRequestGet = require("../../../../../src/lib/routes/secondfactor/u2f/sign_request/get"); +import AuthenticationSession = require("../../../../../src/lib/AuthenticationSession"); +import { ServerVariablesHandler } from "../../../../../src/lib/ServerVariablesHandler"; import winston = require("winston"); import ExpressMock = require("../../../../mocks/express"); @@ -13,7 +13,7 @@ import ServerVariablesMock = require("../../../../mocks/ServerVariablesMock"); import U2FMock = require("../../../../mocks/u2f"); import U2f = require("u2f"); -import { SignMessage } from "../../../../../../../src/server/lib/routes/secondfactor/u2f/sign_request/SignMessage"; +import { SignMessage } from "../../../../../../shared/SignMessage"; describe("test u2f routes: sign_request", function () { let req: ExpressMock.RequestMock; diff --git a/test/unit/server/routes/verify/get.test.ts b/server/test/routes/verify/get.test.ts similarity index 97% rename from test/unit/server/routes/verify/get.test.ts rename to server/test/routes/verify/get.test.ts index deee7d54..1f257c22 100644 --- a/test/unit/server/routes/verify/get.test.ts +++ b/server/test/routes/verify/get.test.ts @@ -1,7 +1,7 @@ import Assert = require("assert"); -import VerifyGet = require("../../../../../src/server/lib/routes/verify/get"); -import AuthenticationSession = require("../../../../../src/server/lib/AuthenticationSession"); +import VerifyGet = require("../../../src/lib/routes/verify/get"); +import AuthenticationSession = require("../../../src/lib/AuthenticationSession"); import Sinon = require("sinon"); import winston = require("winston"); diff --git a/test/unit/server/server/PrivatePages.ts b/server/test/server/PrivatePages.ts similarity index 94% rename from test/unit/server/server/PrivatePages.ts rename to server/test/server/PrivatePages.ts index 520b9f59..44a8411c 100644 --- a/test/unit/server/server/PrivatePages.ts +++ b/server/test/server/PrivatePages.ts @@ -1,14 +1,14 @@ -import Server from "../../../../src/server/lib/Server"; +import Server from "../../src/lib/Server"; import BluebirdPromise = require("bluebird"); import speakeasy = require("speakeasy"); import request = require("request"); import nedb = require("nedb"); -import { GlobalDependencies } from "../../../../src/types/Dependencies"; -import { UserConfiguration } from "../../../../src/server/lib/configuration/Configuration"; -import { TOTPSecret } from "../../../../src/types/TOTPSecret"; +import { GlobalDependencies } from "../../types/Dependencies"; +import { UserConfiguration } from "../../src/lib/configuration/Configuration"; +import { TOTPSecret } from "../../types/TOTPSecret"; import U2FMock = require("./../mocks/u2f"); -import Endpoints = require("../../../../src/server/endpoints"); +import Endpoints = require("../../../shared/api"); import Requests = require("../requests"); import Assert = require("assert"); import Sinon = require("sinon"); diff --git a/test/unit/server/server/PublicPages.ts b/server/test/server/PublicPages.ts similarity index 92% rename from test/unit/server/server/PublicPages.ts rename to server/test/server/PublicPages.ts index 44ede36a..180642fe 100644 --- a/test/unit/server/server/PublicPages.ts +++ b/server/test/server/PublicPages.ts @@ -1,14 +1,14 @@ -import Server from "../../../../src/server/lib/Server"; +import Server from "../../src/lib/Server"; import BluebirdPromise = require("bluebird"); import speakeasy = require("speakeasy"); import Request = require("request"); import nedb = require("nedb"); -import { GlobalDependencies } from "../../../../src/types/Dependencies"; -import { UserConfiguration } from "../../../../src/server/lib/configuration/Configuration"; -import { TOTPSecret } from "../../../../src/types/TOTPSecret"; +import { GlobalDependencies } from "../../types/Dependencies"; +import { UserConfiguration } from "../../src/lib/configuration/Configuration"; +import { TOTPSecret } from "../../types/TOTPSecret"; import U2FMock = require("./../mocks/u2f"); -import Endpoints = require("../../../../src/server/endpoints"); +import Endpoints = require("../../../shared/api"); import Requests = require("../requests"); import Assert = require("assert"); import Sinon = require("sinon"); diff --git a/test/unit/server/storage/UserDataStore.test.ts b/server/test/storage/UserDataStore.test.ts similarity index 96% rename from test/unit/server/storage/UserDataStore.test.ts rename to server/test/storage/UserDataStore.test.ts index 44b1eaad..fcf2abbb 100644 --- a/test/unit/server/storage/UserDataStore.test.ts +++ b/server/test/storage/UserDataStore.test.ts @@ -4,10 +4,10 @@ import * as Sinon from "sinon"; import * as MockDate from "mockdate"; import BluebirdPromise = require("bluebird"); -import { UserDataStore } from "../../../../src/server/lib/storage/UserDataStore"; -import { TOTPSecret } from "../../../../src/types/TOTPSecret"; -import { U2FRegistration } from "../../../../src/types/U2FRegistration"; -import { AuthenticationTraceDocument } from "../../../../src/server/lib/storage/AuthenticationTraceDocument"; +import { UserDataStore } from "../../src/lib/storage/UserDataStore"; +import { TOTPSecret } from "../../types/TOTPSecret"; +import { U2FRegistration } from "../../types/U2FRegistration"; +import { AuthenticationTraceDocument } from "../../src/lib/storage/AuthenticationTraceDocument"; import { CollectionStub } from "../mocks/storage/CollectionStub"; import { CollectionFactoryStub } from "../mocks/storage/CollectionFactoryStub"; diff --git a/test/unit/server/storage/mongo/MongoCollection.test.ts b/server/test/storage/mongo/MongoCollection.test.ts similarity index 97% rename from test/unit/server/storage/mongo/MongoCollection.test.ts rename to server/test/storage/mongo/MongoCollection.test.ts index ab07a1df..5edd4670 100644 --- a/test/unit/server/storage/mongo/MongoCollection.test.ts +++ b/server/test/storage/mongo/MongoCollection.test.ts @@ -3,7 +3,7 @@ import Sinon = require("sinon"); import MongoDB = require("mongodb"); import BluebirdPromise = require("bluebird"); import { MongoClientStub } from "../../mocks/connectors/mongo/MongoClientStub"; -import { MongoCollection } from "../../../../../src/server/lib/storage/mongo/MongoCollection"; +import { MongoCollection } from "../../../src/lib/storage/mongo/MongoCollection"; describe("MongoCollection", function () { let mongoCollectionStub: MongoDB.Collection; diff --git a/test/unit/server/storage/mongo/MongoCollectionFactory.test.ts b/server/test/storage/mongo/MongoCollectionFactory.test.ts similarity index 83% rename from test/unit/server/storage/mongo/MongoCollectionFactory.test.ts rename to server/test/storage/mongo/MongoCollectionFactory.test.ts index c414c92e..eab3da9a 100644 --- a/test/unit/server/storage/mongo/MongoCollectionFactory.test.ts +++ b/server/test/storage/mongo/MongoCollectionFactory.test.ts @@ -1,7 +1,7 @@ import Assert = require("assert"); import Sinon = require("sinon"); import { MongoClientStub } from "../../mocks/connectors/mongo/MongoClientStub"; -import { MongoCollectionFactory } from "../../../../../src/server/lib/storage/mongo/MongoCollectionFactory"; +import { MongoCollectionFactory } from "../../../src/lib/storage/mongo/MongoCollectionFactory"; describe("MongoCollectionFactory", function () { let mongoClient: MongoClientStub; diff --git a/test/unit/server/storage/nedb/NedbCollection.test.ts b/server/test/storage/nedb/NedbCollection.test.ts similarity index 97% rename from test/unit/server/storage/nedb/NedbCollection.test.ts rename to server/test/storage/nedb/NedbCollection.test.ts index 9d6a9a6f..16c79b4e 100644 --- a/test/unit/server/storage/nedb/NedbCollection.test.ts +++ b/server/test/storage/nedb/NedbCollection.test.ts @@ -1,7 +1,7 @@ import Sinon = require("sinon"); import Assert = require("assert"); -import { NedbCollection } from "../../../../../src/server/lib/storage/nedb/NedbCollection"; +import { NedbCollection } from "../../../src/lib/storage/nedb/NedbCollection"; describe("NedbCollection", function () { describe("insert", function () { diff --git a/test/unit/server/storage/nedb/NedbCollectionFactory.test.ts b/server/test/storage/nedb/NedbCollectionFactory.test.ts similarity index 78% rename from test/unit/server/storage/nedb/NedbCollectionFactory.test.ts rename to server/test/storage/nedb/NedbCollectionFactory.test.ts index 4994a8f8..d6339091 100644 --- a/test/unit/server/storage/nedb/NedbCollectionFactory.test.ts +++ b/server/test/storage/nedb/NedbCollectionFactory.test.ts @@ -1,7 +1,7 @@ import Sinon = require("sinon"); import Assert = require("assert"); -import { NedbCollectionFactory } from "../../../../../src/server/lib/storage/nedb/NedbCollectionFactory"; +import { NedbCollectionFactory } from "../../../src/lib/storage/nedb/NedbCollectionFactory"; describe("NedbCollectionFactory", function() { it("should create a nedb collection", function() { diff --git a/server/tsconfig.json b/server/tsconfig.json new file mode 100644 index 00000000..0bb4d62f --- /dev/null +++ b/server/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "moduleResolution": "node", + "noImplicitAny": true, + "sourceMap": true, + "removeComments": true, + "outDir": "../dist", + "baseUrl": ".", + "paths": { + "*": [ + "./types/*", + "../shared/types/*" + ] + } + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "test/**/*" + ] +} diff --git a/server/tslint.json b/server/tslint.json new file mode 100644 index 00000000..c2c1b750 --- /dev/null +++ b/server/tslint.json @@ -0,0 +1,60 @@ +{ + "rules": { + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "indent": [ + true, + "spaces" + ], + "one-line": [ + true, + "check-open-brace", + "check-whitespace" + ], + "no-var-keyword": true, + "quotemark": [ + true, + "double", + "avoid-escape" + ], + "semicolon": [ + true, + "always", + "ignore-bound-class-methods" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-module", + "check-separator", + "check-type" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + }, + { + "call-signature": "onespace", + "index-signature": "onespace", + "parameter": "onespace", + "property-declaration": "onespace", + "variable-declaration": "onespace" + } + ], + "no-internal-module": true, + "no-trailing-whitespace": true, + "no-null-keyword": true, + "prefer-const": true, + "jsdoc-format": true + } +} diff --git a/src/types/Dependencies.ts b/server/types/Dependencies.ts similarity index 100% rename from src/types/Dependencies.ts rename to server/types/Dependencies.ts diff --git a/src/types/Identity.ts b/server/types/Identity.ts similarity index 100% rename from src/types/Identity.ts rename to server/types/Identity.ts diff --git a/src/types/TOTPSecret.ts b/server/types/TOTPSecret.ts similarity index 100% rename from src/types/TOTPSecret.ts rename to server/types/TOTPSecret.ts diff --git a/src/types/U2FRegistration.ts b/server/types/U2FRegistration.ts similarity index 100% rename from src/types/U2FRegistration.ts rename to server/types/U2FRegistration.ts diff --git a/src/types/dovehash.d.ts b/server/types/dovehash.d.ts similarity index 100% rename from src/types/dovehash.d.ts rename to server/types/dovehash.d.ts diff --git a/src/server/lib/routes/secondfactor/u2f/sign_request/SignMessage.ts b/shared/SignMessage.ts similarity index 99% rename from src/server/lib/routes/secondfactor/u2f/sign_request/SignMessage.ts rename to shared/SignMessage.ts index c2f495c2..8031ed63 100644 --- a/src/server/lib/routes/secondfactor/u2f/sign_request/SignMessage.ts +++ b/shared/SignMessage.ts @@ -1,4 +1,3 @@ - import U2f = require("u2f"); export interface SignMessage { diff --git a/src/server/endpoints.ts b/shared/api.ts similarity index 100% rename from src/server/endpoints.ts rename to shared/api.ts diff --git a/src/server/constants.ts b/shared/constants.ts similarity index 100% rename from src/server/constants.ts rename to shared/constants.ts diff --git a/src/types/u2f.d.ts b/shared/types/u2f.d.ts similarity index 100% rename from src/types/u2f.d.ts rename to shared/types/u2f.d.ts diff --git a/src/types/ldapjs-async.d.ts b/src/types/ldapjs-async.d.ts deleted file mode 100644 index 9fce7f51..00000000 --- a/src/types/ldapjs-async.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ldapjs = require("ldapjs"); -import * as BluebirdPromise from "bluebird"; -import { EventEmitter } from "events"; - -declare module "ldapjs" { - export interface ClientAsync { - on(event: string, callback: (data?: any) => void): void; - bindAsync(username: string, password: string): BluebirdPromise; - unbindAsync(): BluebirdPromise; - searchAsync(base: string, query: ldapjs.SearchOptions): BluebirdPromise; - modifyAsync(userdn: string, change: ldapjs.Change): BluebirdPromise; - } -} \ No newline at end of file diff --git a/src/types/nedb-async.d.ts b/src/types/nedb-async.d.ts deleted file mode 100644 index 3f5c96b8..00000000 --- a/src/types/nedb-async.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import Nedb = require("nedb"); -import BluebirdPromise = require("bluebird"); - -declare module "nedb" { - export class NedbAsync extends Nedb { - constructor(pathOrOptions?: string | Nedb.DataStoreOptions); - updateAsync(query: any, updateQuery: any, options?: Nedb.UpdateOptions): BluebirdPromise; - findOneAsync(query: any): BluebirdPromise; - insertAsync(newDoc: T): BluebirdPromise; - removeAsync(query: any): BluebirdPromise; - countAsync(query: any): BluebirdPromise - } -} \ No newline at end of file diff --git a/src/types/request-async.d.ts b/src/types/request-async.d.ts deleted file mode 100644 index 964a7b24..00000000 --- a/src/types/request-async.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import * as BluebirdPromise from "bluebird"; - -declare module "request" { - export interface RequestAPI { - getAsync(uri: string, options?: RequiredUriUrl): BluebirdPromise; - getAsync(uri: string): BluebirdPromise; - getAsync(options: RequiredUriUrl & CoreOptions): BluebirdPromise; - - postAsync(uri: string, options?: CoreOptions): BluebirdPromise; - postAsync(uri: string): BluebirdPromise; - postAsync(options: RequiredUriUrl & CoreOptions): BluebirdPromise; - } -} \ No newline at end of file diff --git a/test/features/access-control.feature b/test/features/access-control.feature index 4a3a8554..e540ac57 100644 --- a/test/features/access-control.feature +++ b/test/features/access-control.feature @@ -2,10 +2,11 @@ Feature: User has access restricted access to domains @need-registered-user-john Scenario: User john has admin access - When I visit "https://auth.test.local:8080" + When I visit "https://auth.test.local:8080?redirect=https%3A%2F%2Fhome.test.local%3A8080%2F" And I login with user "john" and password "password" And I use "REGISTERED" as TOTP token handle And I click on "TOTP" + And I'm redirected to "https://home.test.local:8080/" Then I have access to: | url | | https://public.test.local:8080/secret.html | @@ -23,10 +24,11 @@ Feature: User has access restricted access to domains @need-registered-user-bob Scenario: User bob has restricted access - When I visit "https://auth.test.local:8080" + When I visit "https://auth.test.local:8080?redirect=https%3A%2F%2Fhome.test.local%3A8080%2F" And I login with user "bob" and password "password" And I use "REGISTERED" as TOTP token handle And I click on "TOTP" + And I'm redirected to "https://home.test.local:8080/" Then I have access to: | url | | https://public.test.local:8080/secret.html | @@ -44,10 +46,11 @@ Feature: User has access restricted access to domains @need-registered-user-harry Scenario: User harry has restricted access - When I visit "https://auth.test.local:8080" + When I visit "https://auth.test.local:8080?redirect=https%3A%2F%2Fhome.test.local%3A8080%2F" And I login with user "harry" and password "password" And I use "REGISTERED" as TOTP token handle And I click on "TOTP" + And I'm redirected to "https://home.test.local:8080/" Then I have access to: | url | | https://public.test.local:8080/secret.html | diff --git a/test/features/step_definitions/authentication.ts b/test/features/step_definitions/authentication.ts index ac3f398c..140434e8 100644 --- a/test/features/step_definitions/authentication.ts +++ b/test/features/step_definitions/authentication.ts @@ -4,6 +4,7 @@ import Assert = require("assert"); import Fs = require("fs"); import Speakeasy = require("speakeasy"); import CustomWorld = require("../support/world"); +import BluebirdPromise = require("bluebird"); Cucumber.defineSupportCode(function ({ Given, When, Then }) { When(/^I visit "(https:\/\/[a-zA-Z0-9:%&._\/=?-]+)"$/, function (link: string) { @@ -83,7 +84,7 @@ and I use TOTP token handle {stringInDoubleQuotes}", const url = (dataTable.hashes() as any)[i].url; promises.push(hasAccessToSecret(url, this)); } - return Promise.all(promises); + return BluebirdPromise.all(promises); }); Then("I have no access to:", function (dataTable: Cucumber.TableDefinition) { @@ -92,6 +93,6 @@ and I use TOTP token handle {stringInDoubleQuotes}", const url = (dataTable.hashes() as any)[i].url; promises.push(hasNoAccessToSecret(url, this)); } - return Promise.all(promises); + return BluebirdPromise.all(promises); }); }); \ No newline at end of file diff --git a/test/features/step_definitions/hooks.ts b/test/features/step_definitions/hooks.ts index 184a66d2..b8dcddfc 100644 --- a/test/features/step_definitions/hooks.ts +++ b/test/features/step_definitions/hooks.ts @@ -2,11 +2,11 @@ import Cucumber = require("cucumber"); import fs = require("fs"); import BluebirdPromise = require("bluebird"); import ChildProcess = require("child_process"); -import { UserDataStore } from "../../../src/server/lib/storage/UserDataStore"; -import { CollectionFactoryFactory } from "../../../src/server/lib/storage/CollectionFactoryFactory"; -import { MongoConnector } from "../../../src/server/lib/connectors/mongo/MongoConnector"; -import { IMongoClient } from "../../../src/server/lib/connectors/mongo/IMongoClient"; -import { TOTPGenerator } from "../../../src/server/lib/TOTPGenerator"; +import { UserDataStore } from "../../../server/src/lib/storage/UserDataStore"; +import { CollectionFactoryFactory } from "../../../server/src/lib/storage/CollectionFactoryFactory"; +import { MongoConnector } from "../../../server/src/lib/connectors/mongo/MongoConnector"; +import { IMongoClient } from "../../../server/src/lib/connectors/mongo/IMongoClient"; +import { TOTPGenerator } from "../../../server/src/lib/TOTPGenerator"; import Speakeasy = require("speakeasy"); Cucumber.defineSupportCode(function ({ setDefaultTimeout }) {