From f516aaf243078535bcc3287d9c63f0cacc47c1e8 Mon Sep 17 00:00:00 2001 From: Clement Michaud Date: Fri, 14 Jul 2017 00:25:11 +0200 Subject: [PATCH] Adding one integration test for redis --- Gruntfile.js | 12 ++++++++---- docker-compose.yml | 7 ++----- example/redis/docker-compose.yml | 6 ++++++ package.json | 4 ++-- scripts/dc-example.sh | 2 +- scripts/dc-test.sh | 2 +- scripts/run-int-test.sh | 4 +++- src/server/index.ts | 4 ++-- src/server/lib/Server.ts | 4 +++- test/integration/Dockerfile | 1 - test/integration/config.yml | 3 +++ test/integration/docker-compose.yml | 1 + test/integration/redis.test.ts | 23 +++++++++++++++++++++++ 13 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 example/redis/docker-compose.yml create mode 100644 test/integration/redis.test.ts diff --git a/Gruntfile.js b/Gruntfile.js index 3313edc2d..0c9777516 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -13,16 +13,20 @@ module.exports = function (grunt) { args: ['-c', 'tslint.json', '-p', 'tsconfig.json'] }, "test": { - cmd: "npm", - args: ['run', 'test'] + cmd: "./node_modules/.bin/mocha", + args: ['--compilers', 'ts:ts-node/register', '--recursive', 'test/client', 'test/server'] + }, + "test-int": { + cmd: "./node_modules/.bin/mocha", + args: ['--compilers', 'ts:ts-node/register', '--recursive', 'test/integration'] }, "docker-build": { cmd: "docker", args: ['build', '-t', 'clems4ever/authelia', '.'] }, "docker-restart": { - cmd: "docker-compose", - args: ['-f', 'docker-compose.yml', '-f', 'docker-compose.dev.yml', 'restart', 'auth'] + cmd: "./scripts/dc-example.sh", + args: ['up', '-d'] }, "minify": { cmd: "./node_modules/.bin/uglifyjs", diff --git a/docker-compose.yml b/docker-compose.yml index 600aacdfc..ace1d5db6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,10 +6,7 @@ services: volumes: - ./config.template.yml:/etc/authelia/config.yml:ro - ./notifications:/var/lib/authelia/notifications - networks: - - example-network - - redis: - image: redis + depends_on: + - redis networks: - example-network diff --git a/example/redis/docker-compose.yml b/example/redis/docker-compose.yml new file mode 100644 index 000000000..5e4153624 --- /dev/null +++ b/example/redis/docker-compose.yml @@ -0,0 +1,6 @@ +version: '2' +services: + redis: + image: redis + networks: + - example-network diff --git a/package.json b/package.json index abaab5f49..fa8d97882 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "authelia": "dist/src/server/index.js" }, "scripts": { - "test": "./node_modules/.bin/mocha --compilers ts:ts-node/register --recursive test/client test/server", + "test": "./node_modules/.bin/grunt test", "cover": "NODE_ENV=test nyc npm t", "serve": "node dist/server/index.js" }, @@ -61,7 +61,7 @@ "@types/proxyquire": "^1.3.27", "@types/query-string": "^4.3.1", "@types/randomstring": "^1.1.5", - "@types/request": "0.0.45", + "@types/request": "0.0.46", "@types/sinon": "^2.2.1", "@types/speakeasy": "^2.0.1", "@types/tmp": "0.0.33", diff --git a/scripts/dc-example.sh b/scripts/dc-example.sh index 1abd427b4..4b04a22ec 100755 --- a/scripts/dc-example.sh +++ b/scripts/dc-example.sh @@ -2,4 +2,4 @@ set -e -docker-compose -f docker-compose.base.yml -f docker-compose.yml -f example/nginx/docker-compose.yml -f example/ldap/docker-compose.yml $* +docker-compose -f docker-compose.base.yml -f docker-compose.yml -f example/redis/docker-compose.yml -f example/nginx/docker-compose.yml -f example/ldap/docker-compose.yml $* diff --git a/scripts/dc-test.sh b/scripts/dc-test.sh index df285b0c0..533f363cb 100755 --- a/scripts/dc-test.sh +++ b/scripts/dc-test.sh @@ -2,4 +2,4 @@ set -e -docker-compose -f docker-compose.base.yml -f example/ldap/docker-compose.yml -f test/integration/docker-compose.yml $* +docker-compose -f docker-compose.base.yml -f example/redis/docker-compose.yml -f example/ldap/docker-compose.yml -f test/integration/docker-compose.yml $* diff --git a/scripts/run-int-test.sh b/scripts/run-int-test.sh index efa09a77f..cf3df97ab 100755 --- a/scripts/run-int-test.sh +++ b/scripts/run-int-test.sh @@ -6,7 +6,9 @@ echo "Build services images..." ./scripts/dc-test.sh build echo "Start services..." -./scripts/dc-test.sh up -d authelia nginx openldap +./scripts/dc-test.sh up -d redis openldap +sleep 2 +./scripts/dc-test.sh up -d authelia nginx sleep 3 docker ps -a diff --git a/src/server/index.ts b/src/server/index.ts index a40dc23ad..70f2b72c1 100755 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -15,7 +15,7 @@ if (!configurationFilepath) { console.log("Parse configuration file: %s", configurationFilepath); -const yaml_config = YAML.load(configurationFilepath); +const yamlContent = YAML.load(configurationFilepath); const deps: GlobalDependencies = { u2f: require("u2f"), @@ -29,7 +29,7 @@ const deps: GlobalDependencies = { }; const server = new Server(); -server.start(yaml_config, deps) +server.start(yamlContent, deps) .then(() => { console.log("The server is started!"); }); diff --git a/src/server/lib/Server.ts b/src/server/lib/Server.ts index 1123bb055..adda7e431 100644 --- a/src/server/lib/Server.ts +++ b/src/server/lib/Server.ts @@ -5,7 +5,7 @@ import { GlobalDependencies } from "../../types/Dependencies"; import { AuthenticationRegulator } from "./AuthenticationRegulator"; import UserDataStore from "./UserDataStore"; import ConfigurationAdapter from "./ConfigurationAdapter"; -import { Ā TOTPValidator } from "./TOTPValidator"; +import { TOTPValidator } from "./TOTPValidator"; import { TOTPGenerator } from "./TOTPGenerator"; import RestApi from "./RestApi"; import { LdapClient } from "./LdapClient"; @@ -42,6 +42,8 @@ export default class Server { // by default the level of logs is info deps.winston.level = config.logs_level; console.log("Log level = ", deps.winston.level); + + deps.winston.debug("Content of YAML configuration file is %s", JSON.stringify(yamlConfiguration, undefined, 2)); deps.winston.debug("Authelia configuration is %s", JSON.stringify(config, undefined, 2)); ServerVariables.fill(app, config, deps); diff --git a/test/integration/Dockerfile b/test/integration/Dockerfile index fff701585..16e8a2093 100644 --- a/test/integration/Dockerfile +++ b/test/integration/Dockerfile @@ -2,4 +2,3 @@ FROM node:7-alpine WORKDIR /usr/src -CMD ["./node_modules/.bin/mocha", "--compilers", "ts:ts-node/register", "--recursive", "test/integration"] diff --git a/test/integration/config.yml b/test/integration/config.yml index 5ec8a6d77..7854350ea 100644 --- a/test/integration/config.yml +++ b/test/integration/config.yml @@ -73,6 +73,9 @@ session: secret: unsecure_secret expiration: 3600000 domain: test.local + redis: + host: redis + port: 6379 # The directory where the DB files will be saved diff --git a/test/integration/docker-compose.yml b/test/integration/docker-compose.yml index 2920725a0..afaab5b1f 100644 --- a/test/integration/docker-compose.yml +++ b/test/integration/docker-compose.yml @@ -11,6 +11,7 @@ services: int-test: build: ./test/integration + command: ./node_modules/.bin/mocha --compilers ts:ts-node/register --recursive test/integration volumes: - ./:/usr/src networks: diff --git a/test/integration/redis.test.ts b/test/integration/redis.test.ts new file mode 100644 index 000000000..185d9da4c --- /dev/null +++ b/test/integration/redis.test.ts @@ -0,0 +1,23 @@ + +import Redis = require("redis"); +import Assert = require("assert"); + +const redisOptions = { + host: "redis", + port: 6379 +}; + +describe("test redis is correctly used", function () { + let redisClient: Redis.RedisClient; + + before(function () { + redisClient = Redis.createClient(redisOptions); + }); + + it("should have registered at least one session", function (done) { + redisClient.dbsize(function (err: Error, count: number) { + Assert.equal(1, count); + done(); + }); + }); +}); \ No newline at end of file