From 798586c9965ea871c98791787d4e0bee5ad5a345 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sat, 16 May 2020 18:48:56 +0200 Subject: [PATCH] Add basic test for auth middlewares :white_check_mark: To check for basic mistakes like broken imports, these tests try to create all middlewares (excluding SAML, because that requires a certificate file on disk) Signed-off-by: David Mehren --- test/auth.ts | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 test/auth.ts diff --git a/test/auth.ts b/test/auth.ts new file mode 100644 index 000000000..334206307 --- /dev/null +++ b/test/auth.ts @@ -0,0 +1,110 @@ +import assert from 'assert' +import { ImportMock } from 'ts-mock-imports' +import * as configModule from '../lib/config' +import { DropboxMiddleware } from '../lib/web/auth/dropbox' +import { EmailMiddleware } from '../lib/web/auth/email' +import { FacebookMiddleware } from '../lib/web/auth/facebook' +import { GithubMiddleware } from '../lib/web/auth/github' +import { GitlabMiddleware } from '../lib/web/auth/gitlab' +import { GoogleMiddleware } from '../lib/web/auth/google' +import { LdapMiddleware } from '../lib/web/auth/ldap' +import { OAuth2Middleware } from '../lib/web/auth/oauth2' +import { OPenIDMiddleware } from '../lib/web/auth/openid' +import { TwitterMiddleware } from '../lib/web/auth/twitter' + +describe('AuthMiddlewares', function () { + // We currently exclude the SAML Auth, because it needs a certificate file + const middlewareList = [{ + name: 'Facebook', + middleware: FacebookMiddleware, + config: { + facebook: { + clientID: 'foobar', + clientSecret: 'foobar' + } + } + }, { + name: 'Twitter', + middleware: TwitterMiddleware, + config: { + twitter: { + consumerKey: 'foobar', + consumerSecret: 'foobar' + } + } + }, { + name: 'GitHub', + middleware: GithubMiddleware, + config: { + github: { + clientID: 'foobar', + clientSecret: 'foobar' + } + } + }, { + name: 'Gitlab', + middleware: GitlabMiddleware, + config: { + gitlab: { + clientID: 'foobar', + clientSecret: 'foobar' + } + } + }, { + name: 'Dropbox', + middleware: DropboxMiddleware, + config: { + dropbox: { + clientID: 'foobar', + clientSecret: 'foobar' + } + } + }, { + name: 'Google', + middleware: GoogleMiddleware, + config: { + google: { + clientID: 'foobar', + clientSecret: 'foobar' + } + } + }, { + name: 'LDAP', + middleware: LdapMiddleware, + config: { + ldap: {} + } + }, { + name: 'OAuth2', + middleware: OAuth2Middleware, + config: { + oauth2: { + clientID: 'foobar', + clientSecret: 'foobar', + authorizationURL: 'foobar', + tokenURL: 'foobar', + userProfileURL: 'foobar', + scope: 'foobar' + } + } + }, { + name: 'Email', + middleware: EmailMiddleware, + config: {} + }, { + name: 'OpenID', + middleware: OPenIDMiddleware, + config: {} + }] + + middlewareList.forEach((middleware) => { + describe(middleware.name + 'Middleware', () => { + before(() => { + ImportMock.mockOther(configModule, 'config', middleware.config) + }) + it('can be instantiated', () => { + assert.ok(middleware.middleware.getMiddleware()) + }) + }) + }) +})