mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 12:07:08 -04:00
test(FrontendConfig): Move getAuthProviders to own test
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
e7a6472059
commit
f3cf4f4b1f
1 changed files with 352 additions and 325 deletions
|
@ -61,6 +61,8 @@ describe('FrontendConfigService', () => {
|
||||||
saml: [],
|
saml: [],
|
||||||
oauth2: [],
|
oauth2: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe('getAuthProviders', () => {
|
||||||
const facebook: AuthConfig['facebook'] = {
|
const facebook: AuthConfig['facebook'] = {
|
||||||
clientID: 'facebookTestId',
|
clientID: 'facebookTestId',
|
||||||
clientSecret: 'facebookTestSecret',
|
clientSecret: 'facebookTestSecret',
|
||||||
|
@ -149,11 +151,6 @@ describe('FrontendConfigService', () => {
|
||||||
accessRole: 'oauth2TestAccess',
|
accessRole: 'oauth2TestAccess',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
let index = 1;
|
|
||||||
for (const renderOrigin of [undefined, 'http://md-renderer.example.com']) {
|
|
||||||
for (const maxDocumentLength of [100000, 900]) {
|
|
||||||
for (const enableLogin of [true, false]) {
|
|
||||||
for (const enableRegister of [true, false]) {
|
|
||||||
for (const authConfigConfigured of [
|
for (const authConfigConfigured of [
|
||||||
facebook,
|
facebook,
|
||||||
twitter,
|
twitter,
|
||||||
|
@ -165,6 +162,147 @@ describe('FrontendConfigService', () => {
|
||||||
saml,
|
saml,
|
||||||
oauth2,
|
oauth2,
|
||||||
]) {
|
]) {
|
||||||
|
it(`works with ${JSON.stringify(authConfigConfigured)}`, async () => {
|
||||||
|
const appConfig: AppConfig = {
|
||||||
|
domain: domain,
|
||||||
|
rendererOrigin: domain,
|
||||||
|
port: 3000,
|
||||||
|
loglevel: Loglevel.ERROR,
|
||||||
|
};
|
||||||
|
const authConfig: AuthConfig = {
|
||||||
|
...emptyAuthConfig,
|
||||||
|
...authConfigConfigured,
|
||||||
|
};
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
imports: [
|
||||||
|
ConfigModule.forRoot({
|
||||||
|
isGlobal: true,
|
||||||
|
load: [
|
||||||
|
registerAs('appConfig', () => appConfig),
|
||||||
|
registerAs('authConfig', () => authConfig),
|
||||||
|
registerAs('customizationConfig', () => {
|
||||||
|
return { branding: {}, specialUrls: {} };
|
||||||
|
}),
|
||||||
|
registerAs('externalServicesConfig', () => {
|
||||||
|
return {};
|
||||||
|
}),
|
||||||
|
registerAs('noteConfig', () => {
|
||||||
|
return {
|
||||||
|
forbiddenNoteIds: [],
|
||||||
|
maxDocumentLength: 200,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
LoggerModule,
|
||||||
|
],
|
||||||
|
providers: [FrontendConfigService],
|
||||||
|
}).compile();
|
||||||
|
const service = module.get(FrontendConfigService);
|
||||||
|
const config = await service.getFrontendConfig();
|
||||||
|
if (authConfig.dropbox.clientID) {
|
||||||
|
expect(config.authProviders).toContainEqual({
|
||||||
|
type: AuthProviderType.DROPBOX,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.facebook.clientID) {
|
||||||
|
expect(config.authProviders).toContainEqual({
|
||||||
|
type: AuthProviderType.FACEBOOK,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.google.clientID) {
|
||||||
|
expect(config.authProviders).toContainEqual({
|
||||||
|
type: AuthProviderType.GOOGLE,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.github.clientID) {
|
||||||
|
expect(config.authProviders).toContainEqual({
|
||||||
|
type: AuthProviderType.GITHUB,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.local.enableLogin) {
|
||||||
|
expect(config.authProviders).toContainEqual({
|
||||||
|
type: AuthProviderType.LOCAL,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.twitter.consumerKey) {
|
||||||
|
expect(config.authProviders).toContainEqual({
|
||||||
|
type: AuthProviderType.TWITTER,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect(
|
||||||
|
config.authProviders.filter(
|
||||||
|
(provider) => provider.type === AuthProviderType.GITLAB,
|
||||||
|
).length,
|
||||||
|
).toEqual(authConfig.gitlab.length);
|
||||||
|
expect(
|
||||||
|
config.authProviders.filter(
|
||||||
|
(provider) => provider.type === AuthProviderType.LDAP,
|
||||||
|
).length,
|
||||||
|
).toEqual(authConfig.ldap.length);
|
||||||
|
expect(
|
||||||
|
config.authProviders.filter(
|
||||||
|
(provider) => provider.type === AuthProviderType.SAML,
|
||||||
|
).length,
|
||||||
|
).toEqual(authConfig.saml.length);
|
||||||
|
expect(
|
||||||
|
config.authProviders.filter(
|
||||||
|
(provider) => provider.type === AuthProviderType.OAUTH2,
|
||||||
|
).length,
|
||||||
|
).toEqual(authConfig.oauth2.length);
|
||||||
|
if (authConfig.gitlab.length > 0) {
|
||||||
|
expect(
|
||||||
|
config.authProviders.find(
|
||||||
|
(provider) => provider.type === AuthProviderType.GITLAB,
|
||||||
|
),
|
||||||
|
).toEqual({
|
||||||
|
type: AuthProviderType.GITLAB,
|
||||||
|
providerName: authConfig.gitlab[0].providerName,
|
||||||
|
identifier: authConfig.gitlab[0].identifier,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.ldap.length > 0) {
|
||||||
|
expect(
|
||||||
|
config.authProviders.find(
|
||||||
|
(provider) => provider.type === AuthProviderType.LDAP,
|
||||||
|
),
|
||||||
|
).toEqual({
|
||||||
|
type: AuthProviderType.LDAP,
|
||||||
|
providerName: authConfig.ldap[0].providerName,
|
||||||
|
identifier: authConfig.ldap[0].identifier,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.saml.length > 0) {
|
||||||
|
expect(
|
||||||
|
config.authProviders.find(
|
||||||
|
(provider) => provider.type === AuthProviderType.SAML,
|
||||||
|
),
|
||||||
|
).toEqual({
|
||||||
|
type: AuthProviderType.SAML,
|
||||||
|
providerName: authConfig.saml[0].providerName,
|
||||||
|
identifier: authConfig.saml[0].identifier,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (authConfig.oauth2.length > 0) {
|
||||||
|
expect(
|
||||||
|
config.authProviders.find(
|
||||||
|
(provider) => provider.type === AuthProviderType.OAUTH2,
|
||||||
|
),
|
||||||
|
).toEqual({
|
||||||
|
type: AuthProviderType.OAUTH2,
|
||||||
|
providerName: authConfig.oauth2[0].providerName,
|
||||||
|
identifier: authConfig.oauth2[0].identifier,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let index = 1;
|
||||||
|
for (const renderOrigin of [undefined, 'http://md-renderer.example.com']) {
|
||||||
|
for (const maxDocumentLength of [100000, 900]) {
|
||||||
|
for (const enableLogin of [true, false]) {
|
||||||
|
for (const enableRegister of [true, false]) {
|
||||||
for (const customName of [undefined, 'Test Branding Name']) {
|
for (const customName of [undefined, 'Test Branding Name']) {
|
||||||
for (const customLogo of [
|
for (const customLogo of [
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -203,7 +341,6 @@ describe('FrontendConfigService', () => {
|
||||||
enableLogin,
|
enableLogin,
|
||||||
enableRegister,
|
enableRegister,
|
||||||
},
|
},
|
||||||
...authConfigConfigured,
|
|
||||||
};
|
};
|
||||||
const customizationConfig: CustomizationConfig = {
|
const customizationConfig: CustomizationConfig = {
|
||||||
branding: {
|
branding: {
|
||||||
|
@ -232,10 +369,7 @@ describe('FrontendConfigService', () => {
|
||||||
isGlobal: true,
|
isGlobal: true,
|
||||||
load: [
|
load: [
|
||||||
registerAs('appConfig', () => appConfig),
|
registerAs('appConfig', () => appConfig),
|
||||||
registerAs(
|
registerAs('authConfig', () => authConfig),
|
||||||
'authConfig',
|
|
||||||
() => authConfig,
|
|
||||||
),
|
|
||||||
registerAs(
|
registerAs(
|
||||||
'customizationConfig',
|
'customizationConfig',
|
||||||
() => customizationConfig,
|
() => customizationConfig,
|
||||||
|
@ -244,10 +378,7 @@ describe('FrontendConfigService', () => {
|
||||||
'externalServicesConfig',
|
'externalServicesConfig',
|
||||||
() => externalServicesConfig,
|
() => externalServicesConfig,
|
||||||
),
|
),
|
||||||
registerAs(
|
registerAs('noteConfig', () => noteConfig),
|
||||||
'noteConfig',
|
|
||||||
() => noteConfig,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
LoggerModule,
|
LoggerModule,
|
||||||
|
@ -257,111 +388,8 @@ describe('FrontendConfigService', () => {
|
||||||
|
|
||||||
const service = module.get(FrontendConfigService);
|
const service = module.get(FrontendConfigService);
|
||||||
const config = await service.getFrontendConfig();
|
const config = await service.getFrontendConfig();
|
||||||
expect(config.allowRegister).toEqual(
|
expect(config.allowRegister).toEqual(enableRegister);
|
||||||
enableRegister,
|
|
||||||
);
|
|
||||||
if (authConfig.dropbox.clientID) {
|
|
||||||
expect(config.authProviders).toContainEqual({
|
|
||||||
type: AuthProviderType.DROPBOX,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.facebook.clientID) {
|
|
||||||
expect(config.authProviders).toContainEqual({
|
|
||||||
type: AuthProviderType.FACEBOOK,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.google.clientID) {
|
|
||||||
expect(config.authProviders).toContainEqual({
|
|
||||||
type: AuthProviderType.GOOGLE,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.github.clientID) {
|
|
||||||
expect(config.authProviders).toContainEqual({
|
|
||||||
type: AuthProviderType.GITHUB,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.local.enableLogin) {
|
|
||||||
expect(config.authProviders).toContainEqual({
|
|
||||||
type: AuthProviderType.LOCAL,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.twitter.consumerKey) {
|
|
||||||
expect(config.authProviders).toContainEqual({
|
|
||||||
type: AuthProviderType.TWITTER,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect(
|
|
||||||
config.authProviders.filter(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.GITLAB,
|
|
||||||
).length,
|
|
||||||
).toEqual(authConfig.gitlab.length);
|
|
||||||
expect(
|
|
||||||
config.authProviders.filter(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.LDAP,
|
|
||||||
).length,
|
|
||||||
).toEqual(authConfig.ldap.length);
|
|
||||||
expect(
|
|
||||||
config.authProviders.filter(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.SAML,
|
|
||||||
).length,
|
|
||||||
).toEqual(authConfig.saml.length);
|
|
||||||
expect(
|
|
||||||
config.authProviders.filter(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.OAUTH2,
|
|
||||||
).length,
|
|
||||||
).toEqual(authConfig.oauth2.length);
|
|
||||||
if (authConfig.gitlab.length > 0) {
|
|
||||||
expect(
|
|
||||||
config.authProviders.find(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.GITLAB,
|
|
||||||
),
|
|
||||||
).toEqual({
|
|
||||||
type: AuthProviderType.GITLAB,
|
|
||||||
providerName: authConfig.gitlab[0].providerName,
|
|
||||||
identifier: authConfig.gitlab[0].identifier,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.ldap.length > 0) {
|
|
||||||
expect(
|
|
||||||
config.authProviders.find(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.LDAP,
|
|
||||||
),
|
|
||||||
).toEqual({
|
|
||||||
type: AuthProviderType.LDAP,
|
|
||||||
providerName: authConfig.ldap[0].providerName,
|
|
||||||
identifier: authConfig.ldap[0].identifier,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.saml.length > 0) {
|
|
||||||
expect(
|
|
||||||
config.authProviders.find(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.SAML,
|
|
||||||
),
|
|
||||||
).toEqual({
|
|
||||||
type: AuthProviderType.SAML,
|
|
||||||
providerName: authConfig.saml[0].providerName,
|
|
||||||
identifier: authConfig.saml[0].identifier,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (authConfig.oauth2.length > 0) {
|
|
||||||
expect(
|
|
||||||
config.authProviders.find(
|
|
||||||
(provider) =>
|
|
||||||
provider.type === AuthProviderType.OAUTH2,
|
|
||||||
),
|
|
||||||
).toEqual({
|
|
||||||
type: AuthProviderType.OAUTH2,
|
|
||||||
providerName: authConfig.oauth2[0].providerName,
|
|
||||||
identifier: authConfig.oauth2[0].identifier,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
expect(config.allowAnonymous).toEqual(false);
|
expect(config.allowAnonymous).toEqual(false);
|
||||||
expect(config.branding.name).toEqual(customName);
|
expect(config.branding.name).toEqual(customName);
|
||||||
expect(config.branding.logo).toEqual(
|
expect(config.branding.logo).toEqual(
|
||||||
|
@ -413,5 +441,4 @@ describe('FrontendConfigService', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue