mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🐛 Fix test to suport API dynamic loading
This commit is contained in:
parent
5d1838ccf5
commit
104db9c438
|
@ -30,7 +30,7 @@
|
||||||
"start:default": "cd bin && ./n8n",
|
"start:default": "cd bin && ./n8n",
|
||||||
"start:windows": "cd bin && n8n",
|
"start:windows": "cd bin && n8n",
|
||||||
"test": "npm run test:sqlite",
|
"test": "npm run test:sqlite",
|
||||||
"test:sqlite": "export N8N_LOG_LEVEL='debug'; export DB_TYPE=sqlite; jest",
|
"test:sqlite": "export N8N_LOG_LEVEL='silent'; export DB_TYPE=sqlite; jest",
|
||||||
"test:postgres": "export N8N_LOG_LEVEL='silent'; export DB_TYPE=postgresdb && jest",
|
"test:postgres": "export N8N_LOG_LEVEL='silent'; export DB_TYPE=postgresdb && jest",
|
||||||
"test:mysql": "export N8N_LOG_LEVEL='silent'; export DB_TYPE=mysqldb && jest",
|
"test:mysql": "export N8N_LOG_LEVEL='silent'; export DB_TYPE=mysqldb && jest",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
|
|
|
@ -18,7 +18,7 @@ let globalOwnerRole: Role;
|
||||||
let globalMemberRole: Role;
|
let globalMemberRole: Role;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({ endpointGroups: ['auth'], applyAuth: true });
|
app = await utils.initTestServer({ endpointGroups: ['auth'], applyAuth: true });
|
||||||
const initResult = await testDb.init();
|
const initResult = await testDb.init();
|
||||||
testDbName = initResult.testDbName;
|
testDbName = initResult.testDbName;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ let app: express.Application;
|
||||||
let testDbName = '';
|
let testDbName = '';
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({ endpointGroups: ['auth'], applyAuth: true });
|
app = await utils.initTestServer({ endpointGroups: ['auth'], applyAuth: true });
|
||||||
const initResult = await testDb.init();
|
const initResult = await testDb.init();
|
||||||
testDbName = initResult.testDbName;
|
testDbName = initResult.testDbName;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ let testDbName = '';
|
||||||
let globalMemberRole: Role;
|
let globalMemberRole: Role;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({
|
app = await utils.initTestServer({
|
||||||
applyAuth: true,
|
applyAuth: true,
|
||||||
endpointGroups: ['me', 'auth', 'owner', 'users'],
|
endpointGroups: ['me', 'auth', 'owner', 'users'],
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,7 +19,7 @@ let globalMemberRole: Role;
|
||||||
let saveCredential: SaveCredentialFunction;
|
let saveCredential: SaveCredentialFunction;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({
|
app = await utils.initTestServer({
|
||||||
endpointGroups: ['credentials'],
|
endpointGroups: ['credentials'],
|
||||||
applyAuth: true,
|
applyAuth: true,
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,7 @@ let globalOwnerRole: Role;
|
||||||
let globalMemberRole: Role;
|
let globalMemberRole: Role;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({ endpointGroups: ['me'], applyAuth: true });
|
app = await utils.initTestServer({ endpointGroups: ['me'], applyAuth: true });
|
||||||
const initResult = await testDb.init();
|
const initResult = await testDb.init();
|
||||||
testDbName = initResult.testDbName;
|
testDbName = initResult.testDbName;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ let testDbName = '';
|
||||||
let globalOwnerRole: Role;
|
let globalOwnerRole: Role;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({ endpointGroups: ['owner'], applyAuth: true });
|
app = await utils.initTestServer({ endpointGroups: ['owner'], applyAuth: true });
|
||||||
const initResult = await testDb.init();
|
const initResult = await testDb.init();
|
||||||
testDbName = initResult.testDbName;
|
testDbName = initResult.testDbName;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ let globalOwnerRole: Role;
|
||||||
let globalMemberRole: Role;
|
let globalMemberRole: Role;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({ endpointGroups: ['passwordReset'], applyAuth: true });
|
app = await utils.initTestServer({ endpointGroups: ['passwordReset'], applyAuth: true });
|
||||||
const initResult = await testDb.init();
|
const initResult = await testDb.init();
|
||||||
testDbName = initResult.testDbName;
|
testDbName = initResult.testDbName;
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ let credentialOwnerRole: Role;
|
||||||
jest.mock('../../../src/telemetry');
|
jest.mock('../../../src/telemetry');
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({ endpointGroups: ['publicApi'], applyAuth: false });
|
app = await utils.initTestServer({ endpointGroups: ['publicApi'], applyAuth: false });
|
||||||
const initResult = await testDb.init();
|
const initResult = await testDb.init();
|
||||||
testDbName = initResult.testDbName;
|
testDbName = initResult.testDbName;
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ afterAll(async () => {
|
||||||
await testDb.terminate(testDbName);
|
await testDb.terminate(testDbName);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users should fail due to missing API Key', async () => {
|
test('GET /users should fail due to missing API Key', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: false, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: false, user: owner });
|
||||||
|
@ -83,7 +83,7 @@ test.skip('GET /users should fail due to missing API Key', async () => {
|
||||||
expect(response.statusCode).toBe(401);
|
expect(response.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users should fail due to invalid API Key', async () => {
|
test('GET /users should fail due to invalid API Key', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
owner.apiKey = null;
|
owner.apiKey = null;
|
||||||
|
@ -95,7 +95,7 @@ test.skip('GET /users should fail due to invalid API Key', async () => {
|
||||||
expect(response.statusCode).toBe(401);
|
expect(response.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users should fail due to member trying to access owner only endpoint', async () => {
|
test('GET /users should fail due to member trying to access owner only endpoint', async () => {
|
||||||
|
|
||||||
const member = await testDb.createUser();
|
const member = await testDb.createUser();
|
||||||
|
|
||||||
|
@ -106,32 +106,21 @@ test.skip('GET /users should fail due to member trying to access owner only endp
|
||||||
expect(response.statusCode).toBe(403);
|
expect(response.statusCode).toBe(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users should fail due no instance owner not setup', async () => {
|
test('GET /users should return all users', async () => {
|
||||||
config.set('userManagement.isInstanceOwnerSetUp', false);
|
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
||||||
|
|
||||||
const response = await authOwnerAgent.get('/v1/users');
|
|
||||||
|
|
||||||
expect(response.statusCode).toBe(500);
|
|
||||||
});
|
|
||||||
|
|
||||||
test.skip('GET /users should return all users', async () => {
|
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
|
||||||
|
|
||||||
await testDb.createUser();
|
await testDb.createUser();
|
||||||
|
|
||||||
const response = await authOwnerAgent.get('/v1/users');
|
const response = await authOwnerAgent.get('/v1/users');
|
||||||
|
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
expect(response.body.users.length).toBe(2);
|
expect(response.body.data.length).toBe(2);
|
||||||
expect(response.body.nextCursor).toBeNull();
|
expect(response.body.nextCursor).toBeNull();
|
||||||
|
|
||||||
for (const user of response.body.users) {
|
for (const user of response.body.data) {
|
||||||
const {
|
const {
|
||||||
id,
|
id,
|
||||||
email,
|
email,
|
||||||
|
@ -153,15 +142,26 @@ test.skip('GET /users should return all users', async () => {
|
||||||
expect(personalizationAnswers).toBeUndefined();
|
expect(personalizationAnswers).toBeUndefined();
|
||||||
expect(password).toBeUndefined();
|
expect(password).toBeUndefined();
|
||||||
expect(resetPasswordToken).toBeUndefined();
|
expect(resetPasswordToken).toBeUndefined();
|
||||||
//virtual method not working
|
expect(isPending).toBe(false);
|
||||||
//expect(isPending).toBe(false);
|
|
||||||
expect(globalRole).toBeUndefined();
|
expect(globalRole).toBeUndefined();
|
||||||
expect(createdAt).toBeDefined();
|
expect(createdAt).toBeDefined();
|
||||||
expect(updatedAt).toBeDefined();
|
expect(updatedAt).toBeDefined();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:identifier should fail due to missing API Key', async () => {
|
test('GET /users should fail due no instance owner not setup', async () => {
|
||||||
|
config.set('userManagement.isInstanceOwnerSetUp', false);
|
||||||
|
|
||||||
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
||||||
|
|
||||||
|
const response = await authOwnerAgent.get('/v1/users');
|
||||||
|
|
||||||
|
expect(response.statusCode).toBe(500);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('GET /users/:identifier should fail due to missing API Key', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: false, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: false, user: owner });
|
||||||
|
@ -173,7 +173,7 @@ test.skip('GET /users/:identifier should fail due to missing API Key', async ()
|
||||||
expect(response.statusCode).toBe(401);
|
expect(response.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:identifier should fail due to invalid API Key', async () => {
|
test('GET /users/:identifier should fail due to invalid API Key', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
owner.apiKey = null;
|
owner.apiKey = null;
|
||||||
|
@ -185,7 +185,7 @@ test.skip('GET /users/:identifier should fail due to invalid API Key', async ()
|
||||||
expect(response.statusCode).toBe(401);
|
expect(response.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:identifier should fail due to member trying to access owner only endpoint', async () => {
|
test('GET /users/:identifier should fail due to member trying to access owner only endpoint', async () => {
|
||||||
const member = await testDb.createUser();
|
const member = await testDb.createUser();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: member });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: member });
|
||||||
|
@ -195,7 +195,7 @@ test.skip('GET /users/:identifier should fail due to member trying to access own
|
||||||
expect(response.statusCode).toBe(403);
|
expect(response.statusCode).toBe(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:identifier should fail due no instance owner not setup', async () => {
|
test('GET /users/:identifier should fail due no instance owner not setup', async () => {
|
||||||
config.set('userManagement.isInstanceOwnerSetUp', false);
|
config.set('userManagement.isInstanceOwnerSetUp', false);
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
@ -207,7 +207,7 @@ test.skip('GET /users/:identifier should fail due no instance owner not setup',
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:email with unexisting email should return 404', async () => {
|
test('GET /users/:email with unexisting email should return 404', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
||||||
|
@ -217,17 +217,17 @@ test.skip('GET /users/:email with unexisting email should return 404', async ()
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:id with unexisting id should return 404', async () => {
|
test('GET /users/:id with unexisting id should return 404', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
||||||
|
|
||||||
const response = await authOwnerAgent.get(`/v1/users/123`);
|
const response = await authOwnerAgent.get(`/v1/users/test@gmail.com`);
|
||||||
|
|
||||||
expect(response.statusCode).toBe(404);
|
expect(response.statusCode).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:email should return a user', async () => {
|
test('GET /users/:email should return a user', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
||||||
|
@ -264,7 +264,7 @@ test.skip('GET /users/:email should return a user', async () => {
|
||||||
expect(updatedAt).toBeDefined();
|
expect(updatedAt).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('GET /users/:id should return a user', async () => {
|
test('GET /users/:id should return a user', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
||||||
|
@ -301,7 +301,7 @@ test.skip('GET /users/:id should return a user', async () => {
|
||||||
expect(updatedAt).toBeDefined();
|
expect(updatedAt).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('POST /users should fail due to missing API Key', async () => {
|
test('POST /users should fail due to missing API Key', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: false, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: false, user: owner });
|
||||||
|
@ -313,7 +313,7 @@ test.skip('POST /users should fail due to missing API Key', async () => {
|
||||||
expect(response.statusCode).toBe(401);
|
expect(response.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('POST /users should fail due to invalid API Key', async () => {
|
test('POST /users should fail due to invalid API Key', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
owner.apiKey = null;
|
owner.apiKey = null;
|
||||||
|
@ -325,7 +325,7 @@ test.skip('POST /users should fail due to invalid API Key', async () => {
|
||||||
expect(response.statusCode).toBe(401);
|
expect(response.statusCode).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('POST /users should fail due to member trying to access owner only endpoint', async () => {
|
test('POST /users should fail due to member trying to access owner only endpoint', async () => {
|
||||||
const member = await testDb.createUser();
|
const member = await testDb.createUser();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: member });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: member });
|
||||||
|
@ -335,7 +335,7 @@ test.skip('POST /users should fail due to member trying to access owner only end
|
||||||
expect(response.statusCode).toBe(403);
|
expect(response.statusCode).toBe(403);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('POST /users should fail due instance owner not setup', async () => {
|
test('POST /users should fail due instance owner not setup', async () => {
|
||||||
config.set('userManagement.isInstanceOwnerSetUp', false);
|
config.set('userManagement.isInstanceOwnerSetUp', false);
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
@ -347,7 +347,7 @@ test.skip('POST /users should fail due instance owner not setup', async () => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('POST /users should fail due smtp email not setup', async () => {
|
test('POST /users should fail due smtp email not setup', async () => {
|
||||||
config.set('userManagement.emails.mode', '');
|
config.set('userManagement.emails.mode', '');
|
||||||
|
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
@ -359,7 +359,7 @@ test.skip('POST /users should fail due smtp email not setup', async () => {
|
||||||
expect(response.statusCode).toBe(500);
|
expect(response.statusCode).toBe(500);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('POST /users should fail due not valid body structure', async () => {
|
test('POST /users should fail due not valid body structure', async () => {
|
||||||
const owner = await Db.collections.User!.findOneOrFail();
|
const owner = await Db.collections.User!.findOneOrFail();
|
||||||
|
|
||||||
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
const authOwnerAgent = utils.createAgent(app, { apiPath: 'public', auth: true, user: owner });
|
||||||
|
|
|
@ -11,7 +11,8 @@ export function randomString(min: number, max: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randomApiKey() {
|
export function randomApiKey() {
|
||||||
return randomBytes(20).toString('hex');
|
const ramdonKey = randomBytes(20).toString('hex');
|
||||||
|
return `n8n_api_${ramdonKey}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chooseRandomly = <T>(array: T[]) => array[Math.floor(Math.random() * array.length)];
|
const chooseRandomly = <T>(array: T[]) => array[Math.floor(Math.random() * array.length)];
|
||||||
|
|
|
@ -35,7 +35,7 @@ import type { N8nApp } from '../../../src/UserManagement/Interfaces';
|
||||||
* @param applyAuth Whether to apply auth middleware to test server.
|
* @param applyAuth Whether to apply auth middleware to test server.
|
||||||
* @param endpointGroups Groups of endpoints to apply to test server.
|
* @param endpointGroups Groups of endpoints to apply to test server.
|
||||||
*/
|
*/
|
||||||
export function initTestServer({
|
export async function initTestServer({
|
||||||
applyAuth,
|
applyAuth,
|
||||||
endpointGroups,
|
endpointGroups,
|
||||||
}: {
|
}: {
|
||||||
|
@ -66,7 +66,7 @@ export function initTestServer({
|
||||||
if (routerEndpoints.length) {
|
if (routerEndpoints.length) {
|
||||||
const map: Record<string, express.Router | express.Router[]> = {
|
const map: Record<string, express.Router | express.Router[]> = {
|
||||||
credentials: credentialsController,
|
credentials: credentialsController,
|
||||||
//publicApi,
|
publicApi: await loadPublicApiVersions(),
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const group of routerEndpoints) {
|
for (const group of routerEndpoints) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ let workflowOwnerRole: Role;
|
||||||
let credentialOwnerRole: Role;
|
let credentialOwnerRole: Role;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
app = utils.initTestServer({ endpointGroups: ['users'], applyAuth: true });
|
app = await utils.initTestServer({ endpointGroups: ['users'], applyAuth: true });
|
||||||
const initResult = await testDb.init();
|
const initResult = await testDb.init();
|
||||||
testDbName = initResult.testDbName;
|
testDbName = initResult.testDbName;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue