mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 10:45:20 -04:00
fix: error in toArrayConfig
If an empty string or undefined is provided the method should not return [], but undefined instead. This way defaults defined in Joi function as expected. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
5db2229771
commit
91d7f1a529
4 changed files with 19 additions and 15 deletions
|
@ -66,7 +66,7 @@ export interface AuthConfig {
|
||||||
searchAttributes: string[];
|
searchAttributes: string[];
|
||||||
usernameField: string;
|
usernameField: string;
|
||||||
useridField: string;
|
useridField: string;
|
||||||
tlsCa: string[];
|
tlsCa?: string[];
|
||||||
}[];
|
}[];
|
||||||
saml: {
|
saml: {
|
||||||
identifier: string;
|
identifier: string;
|
||||||
|
@ -78,8 +78,8 @@ export interface AuthConfig {
|
||||||
identifierFormat: string;
|
identifierFormat: string;
|
||||||
disableRequestedAuthnContext: string;
|
disableRequestedAuthnContext: string;
|
||||||
groupAttribute: string;
|
groupAttribute: string;
|
||||||
requiredGroups: string[];
|
requiredGroups?: string[];
|
||||||
externalGroups: string;
|
externalGroups?: string[];
|
||||||
attribute: {
|
attribute: {
|
||||||
id: string;
|
id: string;
|
||||||
username: string;
|
username: string;
|
||||||
|
@ -241,18 +241,18 @@ const authSchema = Joi.object({
|
||||||
|
|
||||||
export default registerAs('authConfig', () => {
|
export default registerAs('authConfig', () => {
|
||||||
// ToDo: Validate these with Joi to prevent duplicate entries?
|
// ToDo: Validate these with Joi to prevent duplicate entries?
|
||||||
const gitlabNames = toArrayConfig(process.env.HD_AUTH_GITLABS, ',').map(
|
const gitlabNames = (
|
||||||
|
toArrayConfig(process.env.HD_AUTH_GITLABS, ',') ?? []
|
||||||
|
).map((name) => name.toUpperCase());
|
||||||
|
const ldapNames = (toArrayConfig(process.env.HD_AUTH_LDAPS, ',') ?? []).map(
|
||||||
(name) => name.toUpperCase(),
|
(name) => name.toUpperCase(),
|
||||||
);
|
);
|
||||||
const ldapNames = toArrayConfig(process.env.HD_AUTH_LDAPS, ',').map((name) =>
|
const samlNames = (toArrayConfig(process.env.HD_AUTH_SAMLS, ',') ?? []).map(
|
||||||
name.toUpperCase(),
|
|
||||||
);
|
|
||||||
const samlNames = toArrayConfig(process.env.HD_AUTH_SAMLS, ',').map((name) =>
|
|
||||||
name.toUpperCase(),
|
|
||||||
);
|
|
||||||
const oauth2Names = toArrayConfig(process.env.HD_AUTH_OAUTH2S, ',').map(
|
|
||||||
(name) => name.toUpperCase(),
|
(name) => name.toUpperCase(),
|
||||||
);
|
);
|
||||||
|
const oauth2Names = (
|
||||||
|
toArrayConfig(process.env.HD_AUTH_OAUTH2S, ',') ?? []
|
||||||
|
).map((name) => name.toUpperCase());
|
||||||
|
|
||||||
const gitlabs = gitlabNames.map((gitlabName) => {
|
const gitlabs = gitlabNames.map((gitlabName) => {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -14,7 +14,8 @@ import {
|
||||||
describe('config utils', () => {
|
describe('config utils', () => {
|
||||||
describe('toArrayConfig', () => {
|
describe('toArrayConfig', () => {
|
||||||
it('empty', () => {
|
it('empty', () => {
|
||||||
expect(toArrayConfig('')).toEqual([]);
|
expect(toArrayConfig('')).toEqual(undefined);
|
||||||
|
expect(toArrayConfig(undefined)).toEqual(undefined);
|
||||||
});
|
});
|
||||||
it('one element', () => {
|
it('one element', () => {
|
||||||
expect(toArrayConfig('one')).toEqual(['one']);
|
expect(toArrayConfig('one')).toEqual(['one']);
|
||||||
|
|
|
@ -5,9 +5,12 @@
|
||||||
*/
|
*/
|
||||||
import { Loglevel } from './loglevel.enum';
|
import { Loglevel } from './loglevel.enum';
|
||||||
|
|
||||||
export function toArrayConfig(configValue?: string, separator = ','): string[] {
|
export function toArrayConfig(
|
||||||
|
configValue?: string,
|
||||||
|
separator = ',',
|
||||||
|
): string[] | undefined {
|
||||||
if (!configValue) {
|
if (!configValue) {
|
||||||
return [];
|
return undefined;
|
||||||
}
|
}
|
||||||
if (!configValue.includes(separator)) {
|
if (!configValue.includes(separator)) {
|
||||||
return [configValue.trim()];
|
return [configValue.trim()];
|
||||||
|
|
|
@ -121,7 +121,7 @@ describe('FrontendConfigService', () => {
|
||||||
disableRequestedAuthnContext: 'samlTestUrl',
|
disableRequestedAuthnContext: 'samlTestUrl',
|
||||||
groupAttribute: 'samlTestUrl',
|
groupAttribute: 'samlTestUrl',
|
||||||
requiredGroups: ['samlTestUrl'],
|
requiredGroups: ['samlTestUrl'],
|
||||||
externalGroups: 'samlTestUrl',
|
externalGroups: ['samlTestUrl'],
|
||||||
attribute: {
|
attribute: {
|
||||||
id: 'samlTestUrl',
|
id: 'samlTestUrl',
|
||||||
username: 'samlTestUrl',
|
username: 'samlTestUrl',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue