mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
feat(core): Improve ldap/saml toggle and tests (#5771)
* improve ldap/saml toggle and tests * import cleanup * reject regular login users when saml is enabled * lint fix
This commit is contained in:
committed by
GitHub
parent
30aeeb70b4
commit
47ee357059
@@ -2,10 +2,11 @@ import type { SuperAgentTest } from 'supertest';
|
||||
import config from '@/config';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { setSamlLoginEnabled } from '@/sso/saml/samlHelpers';
|
||||
import { setCurrentAuthenticationMethod } from '@/sso/ssoHelpers';
|
||||
import { getCurrentAuthenticationMethod, setCurrentAuthenticationMethod } from '@/sso/ssoHelpers';
|
||||
import { randomEmail, randomName, randomValidPassword } from '../shared/random';
|
||||
import * as testDb from '../shared/testDb';
|
||||
import * as utils from '../shared/utils';
|
||||
import { sampleConfig } from './sampleMetadata';
|
||||
|
||||
let owner: User;
|
||||
let authOwnerAgent: SuperAgentTest;
|
||||
@@ -16,7 +17,7 @@ async function enableSaml(enable: boolean) {
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
const app = await utils.initTestServer({ endpointGroups: ['me'] });
|
||||
const app = await utils.initTestServer({ endpointGroups: ['me', 'saml'] });
|
||||
owner = await testDb.createOwner();
|
||||
authOwnerAgent = utils.createAuthAgent(app)(owner);
|
||||
});
|
||||
@@ -67,4 +68,66 @@ describe('Instance owner', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /sso/saml/config', () => {
|
||||
test('should post saml config', async () => {
|
||||
await authOwnerAgent
|
||||
.post('/sso/saml/config')
|
||||
.send({
|
||||
...sampleConfig,
|
||||
loginEnabled: true,
|
||||
})
|
||||
.expect(200);
|
||||
expect(getCurrentAuthenticationMethod()).toBe('saml');
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /sso/saml/config/toggle', () => {
|
||||
test('should toggle saml as default authentication method', async () => {
|
||||
await enableSaml(true);
|
||||
expect(getCurrentAuthenticationMethod()).toBe('saml');
|
||||
|
||||
await authOwnerAgent
|
||||
.post('/sso/saml/config/toggle')
|
||||
.send({
|
||||
loginEnabled: false,
|
||||
})
|
||||
.expect(200);
|
||||
expect(getCurrentAuthenticationMethod()).toBe('email');
|
||||
|
||||
await authOwnerAgent
|
||||
.post('/sso/saml/config/toggle')
|
||||
.send({
|
||||
loginEnabled: true,
|
||||
})
|
||||
.expect(200);
|
||||
expect(getCurrentAuthenticationMethod()).toBe('saml');
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /sso/saml/config/toggle', () => {
|
||||
test('should fail enable saml if default authentication is not email', async () => {
|
||||
await enableSaml(true);
|
||||
|
||||
await authOwnerAgent
|
||||
.post('/sso/saml/config/toggle')
|
||||
.send({
|
||||
loginEnabled: false,
|
||||
})
|
||||
.expect(200);
|
||||
expect(getCurrentAuthenticationMethod()).toBe('email');
|
||||
|
||||
await setCurrentAuthenticationMethod('ldap');
|
||||
expect(getCurrentAuthenticationMethod()).toBe('ldap');
|
||||
|
||||
await authOwnerAgent
|
||||
.post('/sso/saml/config/toggle')
|
||||
.send({
|
||||
loginEnabled: true,
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
expect(getCurrentAuthenticationMethod()).toBe('ldap');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user