mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-09 01:21:01 +00:00
feat: add minimalPasswordStrength to authConfig
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
28176cbcca
commit
ac5e059243
3 changed files with 149 additions and 0 deletions
|
@ -15,6 +15,144 @@ describe('authConfig', () => {
|
|||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
};
|
||||
|
||||
describe('local', () => {
|
||||
const enableLogin = true;
|
||||
const enableRegister = true;
|
||||
const minimalPasswordStrength = 1;
|
||||
const completeLocalConfig = {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_AUTH_LOCAL_ENABLE_LOGIN: String(enableLogin),
|
||||
HD_AUTH_LOCAL_ENABLE_REGISTER: String(enableRegister),
|
||||
HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH: String(minimalPasswordStrength),
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
};
|
||||
describe('is correctly parsed', () => {
|
||||
it('when given correct and complete environment variables', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
...neededAuthConfig,
|
||||
...completeLocalConfig,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
const config = authConfig();
|
||||
expect(config.local.enableLogin).toEqual(enableLogin);
|
||||
expect(config.local.enableRegister).toEqual(enableRegister);
|
||||
expect(config.local.minimalPasswordStrength).toEqual(
|
||||
minimalPasswordStrength,
|
||||
);
|
||||
restore();
|
||||
});
|
||||
|
||||
it('when HD_AUTH_LOCAL_ENABLE_LOGIN is not set', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
...neededAuthConfig,
|
||||
...completeLocalConfig,
|
||||
HD_AUTH_LOCAL_ENABLE_LOGIN: undefined,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
const config = authConfig();
|
||||
expect(config.local.enableLogin).toEqual(false);
|
||||
expect(config.local.enableRegister).toEqual(enableRegister);
|
||||
expect(config.local.minimalPasswordStrength).toEqual(
|
||||
minimalPasswordStrength,
|
||||
);
|
||||
restore();
|
||||
});
|
||||
|
||||
it('when HD_AUTH_LOCAL_ENABLE_REGISTER is not set', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
...neededAuthConfig,
|
||||
...completeLocalConfig,
|
||||
HD_AUTH_LOCAL_ENABLE_REGISTER: undefined,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
const config = authConfig();
|
||||
expect(config.local.enableLogin).toEqual(enableLogin);
|
||||
expect(config.local.enableRegister).toEqual(false);
|
||||
expect(config.local.minimalPasswordStrength).toEqual(
|
||||
minimalPasswordStrength,
|
||||
);
|
||||
restore();
|
||||
});
|
||||
|
||||
it('when HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH is not set', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
...neededAuthConfig,
|
||||
...completeLocalConfig,
|
||||
HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH: undefined,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
const config = authConfig();
|
||||
expect(config.local.enableLogin).toEqual(enableLogin);
|
||||
expect(config.local.enableRegister).toEqual(enableRegister);
|
||||
expect(config.local.minimalPasswordStrength).toEqual(2);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('fails to be parsed', () => {
|
||||
it('when HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH is 5', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
...neededAuthConfig,
|
||||
...completeLocalConfig,
|
||||
HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH: '5',
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
'"HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH" must be less than or equal to 4',
|
||||
);
|
||||
restore();
|
||||
});
|
||||
it('when HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH is -1', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
...neededAuthConfig,
|
||||
...completeLocalConfig,
|
||||
HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH: '-1',
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
'"HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH" must be greater than or equal to 0',
|
||||
);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ldap', () => {
|
||||
const ldapNames = ['futurama'];
|
||||
const providerName = 'Futurama LDAP';
|
||||
|
|
|
@ -38,6 +38,7 @@ export interface AuthConfig {
|
|||
local: {
|
||||
enableLogin: boolean;
|
||||
enableRegister: boolean;
|
||||
minimalPasswordStrength: number;
|
||||
};
|
||||
facebook: {
|
||||
clientID: string;
|
||||
|
@ -126,6 +127,12 @@ const authSchema = Joi.object({
|
|||
.default(false)
|
||||
.optional()
|
||||
.label('HD_AUTH_LOCAL_ENABLE_REGISTER'),
|
||||
minimalPasswordStrength: Joi.number()
|
||||
.default(2)
|
||||
.min(0)
|
||||
.max(4)
|
||||
.optional()
|
||||
.label('HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH'),
|
||||
},
|
||||
facebook: {
|
||||
clientID: Joi.string().optional().label('HD_AUTH_FACEBOOK_CLIENT_ID'),
|
||||
|
@ -368,6 +375,9 @@ export default registerAs('authConfig', () => {
|
|||
local: {
|
||||
enableLogin: process.env.HD_AUTH_LOCAL_ENABLE_LOGIN,
|
||||
enableRegister: process.env.HD_AUTH_LOCAL_ENABLE_REGISTER,
|
||||
minimalPasswordStrength: parseOptionalNumber(
|
||||
process.env.HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH,
|
||||
),
|
||||
},
|
||||
facebook: {
|
||||
clientID: process.env.HD_AUTH_FACEBOOK_CLIENT_ID,
|
||||
|
|
|
@ -17,6 +17,7 @@ export default registerAs(
|
|||
local: {
|
||||
enableLogin: true,
|
||||
enableRegister: true,
|
||||
minimalPasswordStrength: 2,
|
||||
},
|
||||
facebook: {
|
||||
clientID: '',
|
||||
|
|
Loading…
Reference in a new issue