first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { mockInstance } from '@n8n/backend-test-utils';
|
||||
|
||||
import { ActiveWorkflowManager } from '@/active-workflow-manager';
|
||||
|
||||
import { createUser } from './shared/db/users';
|
||||
import type { SuperAgentTest } from './shared/types';
|
||||
import * as utils from './shared/utils/';
|
||||
|
||||
describe('Auth Middleware', () => {
|
||||
mockInstance(ActiveWorkflowManager);
|
||||
|
||||
const testServer = utils.setupTestServer({
|
||||
endpointGroups: ['me', 'auth', 'owner', 'users', 'invitations'],
|
||||
});
|
||||
|
||||
/** Routes requiring a valid `n8n-auth` cookie for a user, either owner or member. */
|
||||
const ROUTES_REQUIRING_AUTHENTICATION = [
|
||||
['patch', '/me'],
|
||||
['patch', '/me/password'],
|
||||
['post', '/me/survey'],
|
||||
] as const;
|
||||
|
||||
/** Routes requiring a valid `n8n-auth` cookie for an owner. */
|
||||
const ROUTES_REQUIRING_AUTHORIZATION = [
|
||||
['post', '/invitations'],
|
||||
['delete', '/users/123'],
|
||||
] as const;
|
||||
|
||||
describe('Routes requiring Authentication', () => {
|
||||
[...ROUTES_REQUIRING_AUTHENTICATION, ...ROUTES_REQUIRING_AUTHORIZATION].forEach(
|
||||
([method, endpoint]) => {
|
||||
test(`${method} ${endpoint} should return 401 Unauthorized if no cookie`, async () => {
|
||||
const { statusCode } = await testServer.authlessAgent[method](endpoint);
|
||||
expect(statusCode).toBe(401);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('Routes requiring Authorization', () => {
|
||||
let authMemberAgent: SuperAgentTest;
|
||||
beforeAll(async () => {
|
||||
const member = await createUser({ role: { slug: 'global:member' } });
|
||||
authMemberAgent = testServer.authAgentFor(member);
|
||||
});
|
||||
|
||||
ROUTES_REQUIRING_AUTHORIZATION.forEach(async ([method, endpoint]) => {
|
||||
test(`${method} ${endpoint} should return 403 Forbidden for member`, async () => {
|
||||
const { statusCode } = await authMemberAgent[method](endpoint);
|
||||
expect(statusCode).toBe(403);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user