diff --git a/Gruntfile.js b/Gruntfile.js index 3313edc2..0c977751 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 600aacdf..ace1d5db 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 00000000..5e415362 --- /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 abaab5f4..fa8d9788 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 1abd427b..4b04a22e 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 df285b0c..533f363c 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 efa09a77..cf3df97a 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 a40dc23a..70f2b72c 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 1123bb05..adda7e43 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 fff70158..16e8a209 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 5ec8a6d7..7854350e 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 2920725a..afaab5b1 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 00000000..185d9da4 --- /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