mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
Read configuration of redis from the yaml file.
This commit is contained in:
parent
925b58fabc
commit
e947fed979
|
@ -109,7 +109,7 @@ module.exports = function (grunt) {
|
||||||
},
|
},
|
||||||
client: {
|
client: {
|
||||||
files: ['src/client/**/*.ts', 'test/client/**/*.ts'],
|
files: ['src/client/**/*.ts', 'test/client/**/*.ts'],
|
||||||
tasks: ['build'],
|
tasks: ['build-dev'],
|
||||||
options: {
|
options: {
|
||||||
interrupt: true,
|
interrupt: true,
|
||||||
atBegin: true
|
atBegin: true
|
||||||
|
@ -117,9 +117,10 @@ module.exports = function (grunt) {
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
files: ['src/server/**/*.ts', 'test/server/**/*.ts'],
|
files: ['src/server/**/*.ts', 'test/server/**/*.ts'],
|
||||||
tasks: ['build', 'run:docker-restart', 'run:make-dev-views' ],
|
tasks: ['build-dev', 'run:docker-restart', 'run:make-dev-views' ],
|
||||||
options: {
|
options: {
|
||||||
interrupt: true,
|
interrupt: true,
|
||||||
|
atBegin: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import * as ObjectPath from "object-path";
|
import * as ObjectPath from "object-path";
|
||||||
import { AppConfiguration, UserConfiguration, NotifierConfiguration, ACLConfiguration, LdapConfiguration } from "./../../types/Configuration";
|
import { AppConfiguration, UserConfiguration, NotifierConfiguration, ACLConfiguration, LdapConfiguration, SessionRedisOptions } from "./../../types/Configuration";
|
||||||
|
|
||||||
const LDAP_URL_ENV_VARIABLE = "LDAP_URL";
|
const LDAP_URL_ENV_VARIABLE = "LDAP_URL";
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ function adaptFromUserConfiguration(userConfiguration: UserConfiguration): AppCo
|
||||||
domain: ObjectPath.get<object, string>(userConfiguration, "session.domain"),
|
domain: ObjectPath.get<object, string>(userConfiguration, "session.domain"),
|
||||||
secret: ObjectPath.get<object, string>(userConfiguration, "session.secret"),
|
secret: ObjectPath.get<object, string>(userConfiguration, "session.secret"),
|
||||||
expiration: get_optional<number>(userConfiguration, "session.expiration", 3600000), // in ms
|
expiration: get_optional<number>(userConfiguration, "session.expiration", 3600000), // in ms
|
||||||
|
redis: ObjectPath.get<object, SessionRedisOptions>(userConfiguration, "session.redis")
|
||||||
},
|
},
|
||||||
store_directory: get_optional<string>(userConfiguration, "store_directory", undefined),
|
store_directory: get_optional<string>(userConfiguration, "store_directory", undefined),
|
||||||
logs_level: get_optional<string>(userConfiguration, "logs_level", "info"),
|
logs_level: get_optional<string>(userConfiguration, "logs_level", "info"),
|
||||||
|
|
|
@ -21,14 +21,14 @@ import * as http from "http";
|
||||||
export default class Server {
|
export default class Server {
|
||||||
private httpServer: http.Server;
|
private httpServer: http.Server;
|
||||||
|
|
||||||
start(yaml_configuration: UserConfiguration, deps: GlobalDependencies): BluebirdPromise<void> {
|
start(yamlConfiguration: UserConfiguration, deps: GlobalDependencies): BluebirdPromise<void> {
|
||||||
const config = ConfigurationAdapter.adapt(yaml_configuration);
|
const config = ConfigurationAdapter.adapt(yamlConfiguration);
|
||||||
|
|
||||||
const view_directory = Path.resolve(__dirname, "../views");
|
const viewsDirectory = Path.resolve(__dirname, "../views");
|
||||||
const public_html_directory = Path.resolve(__dirname, "../public_html");
|
const publicHtmlDirectory = Path.resolve(__dirname, "../public_html");
|
||||||
|
|
||||||
const app = Express();
|
const app = Express();
|
||||||
app.use(Express.static(public_html_directory));
|
app.use(Express.static(publicHtmlDirectory));
|
||||||
app.use(BodyParser.urlencoded({ extended: false }));
|
app.use(BodyParser.urlencoded({ extended: false }));
|
||||||
app.use(BodyParser.json());
|
app.use(BodyParser.json());
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ export default class Server {
|
||||||
const sessionOptions = SessionConfigurationBuilder.build(config, deps);
|
const sessionOptions = SessionConfigurationBuilder.build(config, deps);
|
||||||
app.use(deps.session(sessionOptions));
|
app.use(deps.session(sessionOptions));
|
||||||
|
|
||||||
app.set("views", view_directory);
|
app.set("views", viewsDirectory);
|
||||||
app.set("view engine", "pug");
|
app.set("view engine", "pug");
|
||||||
|
|
||||||
// by default the level of logs is info
|
// by default the level of logs is info
|
||||||
|
|
|
@ -19,7 +19,8 @@ export default class SessionConfigurationBuilder {
|
||||||
|
|
||||||
if (configuration.session.redis) {
|
if (configuration.session.redis) {
|
||||||
let redisOptions;
|
let redisOptions;
|
||||||
if (configuration.session.redis.host && configuration.session.redis.port) {
|
if (configuration.session.redis.host
|
||||||
|
&& configuration.session.redis.port) {
|
||||||
redisOptions = {
|
redisOptions = {
|
||||||
host: configuration.session.redis.host,
|
host: configuration.session.redis.host,
|
||||||
port: configuration.session.redis.port
|
port: configuration.session.redis.port
|
||||||
|
@ -31,7 +32,6 @@ export default class SessionConfigurationBuilder {
|
||||||
sessionOptions.store = new RedisStore(redisOptions);
|
sessionOptions.store = new RedisStore(redisOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionOptions;
|
return sessionOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,14 +24,16 @@ export interface ACLConfiguration {
|
||||||
users: ACLUsersRules;
|
users: ACLUsersRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SessionRedisOptions {
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface SessionCookieConfiguration {
|
interface SessionCookieConfiguration {
|
||||||
secret: string;
|
secret: string;
|
||||||
expiration?: number;
|
expiration?: number;
|
||||||
domain?: string;
|
domain?: string;
|
||||||
redis?: {
|
redis?: SessionRedisOptions;
|
||||||
host: string;
|
|
||||||
port: number;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GmailNotifierConfiguration {
|
export interface GmailNotifierConfiguration {
|
||||||
|
|
123
test/server/SessionConfigurationBuilder.test.ts
Normal file
123
test/server/SessionConfigurationBuilder.test.ts
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
import SessionConfigurationBuilder from "../../src/server/lib/SessionConfigurationBuilder";
|
||||||
|
import { AppConfiguration } from "../../src/types/Configuration";
|
||||||
|
import { GlobalDependencies } from "../../src/types/Dependencies";
|
||||||
|
import ExpressSession = require("express-session");
|
||||||
|
import ConnectRedis = require("connect-redis");
|
||||||
|
import sinon = require("sinon");
|
||||||
|
import Assert = require("assert");
|
||||||
|
|
||||||
|
describe.only("test session configuration builder", function () {
|
||||||
|
it("should return session options without redis options", function () {
|
||||||
|
const configuration: AppConfiguration = {
|
||||||
|
access_control: {
|
||||||
|
default: [],
|
||||||
|
users: {},
|
||||||
|
groups: {}
|
||||||
|
},
|
||||||
|
ldap: {
|
||||||
|
url: "ldap://ldap",
|
||||||
|
base_dn: "dc=example,dc=com",
|
||||||
|
user: "user",
|
||||||
|
password: "password"
|
||||||
|
},
|
||||||
|
logs_level: "debug",
|
||||||
|
notifier: {
|
||||||
|
filesystem: {
|
||||||
|
filename: "/test"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
port: 8080,
|
||||||
|
session: {
|
||||||
|
domain: "example.com",
|
||||||
|
expiration: 3600,
|
||||||
|
secret: "secret"
|
||||||
|
},
|
||||||
|
store_in_memory: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const deps: GlobalDependencies = {
|
||||||
|
ConnectRedis: sinon.spy() as any,
|
||||||
|
ldapjs: sinon.spy() as any,
|
||||||
|
nedb: sinon.spy() as any,
|
||||||
|
nodemailer: sinon.spy() as any,
|
||||||
|
session: sinon.spy() as any,
|
||||||
|
speakeasy: sinon.spy() as any,
|
||||||
|
u2f: sinon.spy() as any,
|
||||||
|
winston: sinon.spy() as any
|
||||||
|
};
|
||||||
|
|
||||||
|
const options = SessionConfigurationBuilder.build(configuration, deps);
|
||||||
|
|
||||||
|
const expectedOptions = {
|
||||||
|
secret: "secret",
|
||||||
|
resave: false,
|
||||||
|
saveUninitialized: true,
|
||||||
|
cookie: {
|
||||||
|
secure: false,
|
||||||
|
maxAge: 3600,
|
||||||
|
domain: "example.com"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Assert.deepEqual(expectedOptions, options);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should return session options with redis options", function () {
|
||||||
|
const configuration: AppConfiguration = {
|
||||||
|
access_control: {
|
||||||
|
default: [],
|
||||||
|
users: {},
|
||||||
|
groups: {}
|
||||||
|
},
|
||||||
|
ldap: {
|
||||||
|
url: "ldap://ldap",
|
||||||
|
base_dn: "dc=example,dc=com",
|
||||||
|
user: "user",
|
||||||
|
password: "password"
|
||||||
|
},
|
||||||
|
logs_level: "debug",
|
||||||
|
notifier: {
|
||||||
|
filesystem: {
|
||||||
|
filename: "/test"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
port: 8080,
|
||||||
|
session: {
|
||||||
|
domain: "example.com",
|
||||||
|
expiration: 3600,
|
||||||
|
secret: "secret",
|
||||||
|
redis: {
|
||||||
|
host: "redis.example.com",
|
||||||
|
port: 6379
|
||||||
|
}
|
||||||
|
},
|
||||||
|
store_in_memory: true
|
||||||
|
};
|
||||||
|
|
||||||
|
const deps: GlobalDependencies = {
|
||||||
|
ConnectRedis: sinon.stub().returns({ RedisStore: sinon.spy() }) as any,
|
||||||
|
ldapjs: sinon.spy() as any,
|
||||||
|
nedb: sinon.spy() as any,
|
||||||
|
nodemailer: sinon.spy() as any,
|
||||||
|
session: sinon.spy() as any,
|
||||||
|
speakeasy: sinon.spy() as any,
|
||||||
|
u2f: sinon.spy() as any,
|
||||||
|
winston: sinon.spy() as any
|
||||||
|
};
|
||||||
|
|
||||||
|
const options = SessionConfigurationBuilder.build(configuration, deps);
|
||||||
|
|
||||||
|
const expectedOptions: ExpressSession.SessionOptions = {
|
||||||
|
secret: "secret",
|
||||||
|
resave: false,
|
||||||
|
saveUninitialized: true,
|
||||||
|
cookie: {
|
||||||
|
secure: false,
|
||||||
|
maxAge: 3600,
|
||||||
|
domain: "example.com"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Assert(expectedOptions.store != undefined);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user