n8n/packages/cli/test/unit/PermissionChecker.test.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

386 lines
11 KiB
TypeScript
Raw Normal View History

import { v4 as uuid } from 'uuid';
import { Container } from 'typedi';
import type { WorkflowSettings } from 'n8n-workflow';
import { SubworkflowOperationError, Workflow } from 'n8n-workflow';
import config from '@/config';
import { User } from '@db/entities/User';
import { WorkflowRepository } from '@db/repositories/workflow.repository';
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
import { UserRepository } from '@/databases/repositories/user.repository';
import { generateNanoId } from '@/databases/utils/generators';
import { License } from '@/License';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import { NodeTypes } from '@/NodeTypes';
import { OwnershipService } from '@/services/ownership.service';
import { PermissionChecker } from '@/UserManagement/PermissionChecker';
import { mockInstance } from '../shared/mocking';
import {
randomCredentialPayload as randomCred,
randomName,
randomPositiveDigit,
} from '../integration/shared/random';
import { LicenseMocker } from '../integration/shared/license';
import * as testDb from '../integration/shared/testDb';
import type { SaveCredentialFunction } from '../integration/shared/types';
import { mockNodeTypesData } from './Helpers';
import { affixRoleToSaveCredential } from '../integration/shared/db/credentials';
import { createOwner, createUser } from '../integration/shared/db/users';
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
export const toTargetCallErrorMsg = (subworkflowId: string) =>
`Target workflow ID ${subworkflowId} may not be called`;
export function createParentWorkflow() {
return Container.get(WorkflowRepository).create({
id: generateNanoId(),
name: randomName(),
active: false,
connections: {},
nodes: [
{
name: '',
typeVersion: 1,
type: 'n8n-nodes-base.executeWorkflow',
position: [0, 0],
parameters: {},
},
],
});
}
export function createSubworkflow({
policy,
callerIds,
}: {
policy?: WorkflowSettings.CallerPolicy;
callerIds?: string;
} = {}) {
return new Workflow({
id: uuid(),
nodes: [],
connections: {},
active: false,
nodeTypes: mockNodeTypes,
settings: {
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
...(policy ? { callerPolicy: policy } : {}),
...(callerIds ? { callerIds } : {}),
},
});
}
refactor(core): Implement soft-deletions for executions (#7092) Based on #7065 | Story: https://linear.app/n8n/issue/PAY-771 n8n on filesystem mode marks binary data to delete on manual execution deletion, on unsaved execution completion, and on every execution pruning cycle. We later prune binary data in a separate cycle via these marker files, based on the configured TTL. In the context of introducing an S3 client to manage binary data, the filesystem mode's mark-and-prune setup is too tightly coupled to the general binary data management client interface. This PR... - Ensures the deletion of an execution causes the deletion of any binary data associated to it. This does away with the need for binary data TTL and simplifies the filesystem mode's mark-and-prune setup. - Refactors all execution deletions (including pruning) to cause soft deletions, hard-deletes soft-deleted executions based on the existing pruning config, and adjusts execution endpoints to filter out soft-deleted executions. This reduces DB load, and keeps binary data around long enough for users to access it when building workflows with unsaved executions. - Moves all execution pruning work from an execution lifecycle hook to `execution.repository.ts`. This keeps related logic in a single place. - Removes all marking logic from the binary data manager. This simplifies the interface that the S3 client will meet. - Adds basic sanity-check tests to pruning logic and execution deletion. Out of scope: - Improving existing pruning logic. - Improving existing execution repository logic. - Adjusting dir structure for filesystem mode. --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2023-09-20 06:21:42 -07:00
let saveCredential: SaveCredentialFunction;
const mockNodeTypes = mockInstance(NodeTypes);
mockInstance(LoadNodesAndCredentials, {
loadedNodes: mockNodeTypesData(['start', 'actionNetwork']),
});
let permissionChecker: PermissionChecker;
beforeAll(async () => {
await testDb.init();
saveCredential = affixRoleToSaveCredential('credential:owner');
permissionChecker = Container.get(PermissionChecker);
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
describe('check()', () => {
beforeEach(async () => {
await testDb.truncate(['Workflow', 'Credentials']);
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
afterAll(async () => {
await testDb.terminate();
});
test('should allow if workflow has no creds', async () => {
const userId = uuid();
const workflow = new Workflow({
id: randomPositiveDigit().toString(),
name: 'test',
active: false,
connections: {},
nodeTypes: mockNodeTypes,
nodes: [
{
id: uuid(),
name: 'Start',
type: 'n8n-nodes-base.start',
typeVersion: 1,
parameters: {},
position: [0, 0],
},
],
});
expect(async () => await permissionChecker.check(workflow, userId)).not.toThrow();
});
test('should allow if requesting user is instance owner', async () => {
const owner = await createOwner();
const workflow = new Workflow({
id: randomPositiveDigit().toString(),
name: 'test',
active: false,
connections: {},
nodeTypes: mockNodeTypes,
nodes: [
{
id: uuid(),
name: 'Action Network',
type: 'n8n-nodes-base.actionNetwork',
parameters: {},
typeVersion: 1,
position: [0, 0],
credentials: {
actionNetworkApi: {
id: randomPositiveDigit().toString(),
name: 'Action Network Account',
},
},
},
],
});
expect(async () => await permissionChecker.check(workflow, owner.id)).not.toThrow();
});
test('should allow if workflow creds are valid subset', async () => {
const [owner, member] = await Promise.all([createOwner(), createUser()]);
const ownerCred = await saveCredential(randomCred(), { user: owner });
const memberCred = await saveCredential(randomCred(), { user: member });
const workflow = new Workflow({
id: randomPositiveDigit().toString(),
name: 'test',
active: false,
connections: {},
nodeTypes: mockNodeTypes,
nodes: [
{
id: uuid(),
name: 'Action Network',
type: 'n8n-nodes-base.actionNetwork',
parameters: {},
typeVersion: 1,
position: [0, 0],
credentials: {
actionNetworkApi: {
id: ownerCred.id,
name: ownerCred.name,
},
},
},
{
id: uuid(),
name: 'Action Network 2',
type: 'n8n-nodes-base.actionNetwork',
parameters: {},
typeVersion: 1,
position: [0, 0],
credentials: {
actionNetworkApi: {
id: memberCred.id,
name: memberCred.name,
},
},
},
],
});
expect(async () => await permissionChecker.check(workflow, owner.id)).not.toThrow();
});
test('should deny if workflow creds are not valid subset', async () => {
const member = await createUser();
const memberCred = await saveCredential(randomCred(), { user: member });
const workflowDetails = {
id: randomPositiveDigit().toString(),
name: 'test',
active: false,
connections: {},
nodeTypes: mockNodeTypes,
nodes: [
{
id: uuid(),
name: 'Action Network',
type: 'n8n-nodes-base.actionNetwork',
parameters: {},
typeVersion: 1,
position: [0, 0] as [number, number],
credentials: {
actionNetworkApi: {
id: memberCred.id,
name: memberCred.name,
},
},
},
{
id: uuid(),
name: 'Action Network 2',
type: 'n8n-nodes-base.actionNetwork',
parameters: {},
typeVersion: 1,
position: [0, 0] as [number, number],
credentials: {
actionNetworkApi: {
id: 'non-existing-credential-id',
name: 'Non-existing credential name',
},
},
},
],
};
const workflowEntity = await Container.get(WorkflowRepository).save(workflowDetails);
await Container.get(SharedWorkflowRepository).save({
workflow: workflowEntity,
user: member,
role: 'workflow:owner',
});
const workflow = new Workflow(workflowDetails);
await expect(permissionChecker.check(workflow, member.id)).rejects.toThrow();
});
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
describe('checkSubworkflowExecutePolicy()', () => {
const ownershipService = mockInstance(OwnershipService);
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
let license: LicenseMocker;
beforeAll(() => {
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
license = new LicenseMocker();
license.mock(Container.get(License));
license.enable('feat:sharing');
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
describe('no caller policy', () => {
test('should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION', async () => {
config.set('workflows.callerPolicyDefaultOption', 'none');
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
const parentWorkflow = createParentWorkflow();
const subworkflow = createSubworkflow(); // no caller policy
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
ownershipService.getWorkflowOwnerCached.mockResolvedValue(new User());
const check = permissionChecker.checkSubworkflowExecutePolicy(subworkflow, parentWorkflow.id);
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
await expect(check).rejects.toThrow(toTargetCallErrorMsg(subworkflow.id));
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
config.load(config.default);
});
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
describe('overridden caller policy', () => {
test('if no sharing, should override policy to workflows-from-same-owner', async () => {
license.disable('feat:sharing');
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
const parentWorkflow = createParentWorkflow();
const subworkflow = createSubworkflow({ policy: 'any' }); // should be overridden
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
const firstUser = Container.get(UserRepository).create({ id: uuid() });
const secondUser = Container.get(UserRepository).create({ id: uuid() });
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
ownershipService.getWorkflowOwnerCached.mockResolvedValueOnce(firstUser); // parent workflow
ownershipService.getWorkflowOwnerCached.mockResolvedValueOnce(secondUser); // subworkflow
const check = permissionChecker.checkSubworkflowExecutePolicy(subworkflow, parentWorkflow.id);
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
await expect(check).rejects.toThrow(toTargetCallErrorMsg(subworkflow.id));
try {
await permissionChecker.checkSubworkflowExecutePolicy(subworkflow, uuid());
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
} catch (error) {
if (error instanceof SubworkflowOperationError) {
expect(error.description).toBe(
`${firstUser.firstName} (${firstUser.email}) can make this change. You may need to tell them the ID of this workflow, which is ${subworkflow.id}`,
);
}
}
license.enable('feat:sharing');
});
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
describe('workflows-from-list caller policy', () => {
test('should allow if caller list contains parent workflow ID', async () => {
const parentWorkflow = createParentWorkflow();
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
const subworkflow = createSubworkflow({
policy: 'workflowsFromAList',
callerIds: `123,456,bcdef, ${parentWorkflow.id}`,
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
});
const check = permissionChecker.checkSubworkflowExecutePolicy(subworkflow, parentWorkflow.id);
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
await expect(check).resolves.not.toThrow();
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
test('should deny if caller list does not contain parent workflow ID', async () => {
const parentWorkflow = createParentWorkflow();
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
const subworkflow = createSubworkflow({
policy: 'workflowsFromAList',
callerIds: 'xyz',
});
const check = permissionChecker.checkSubworkflowExecutePolicy(subworkflow, parentWorkflow.id);
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
await expect(check).rejects.toThrow();
});
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
describe('any caller policy', () => {
test('should not throw', async () => {
const parentWorkflow = createParentWorkflow();
const subworkflow = createSubworkflow({ policy: 'any' });
ownershipService.getWorkflowOwnerCached.mockResolvedValue(new User());
const check = permissionChecker.checkSubworkflowExecutePolicy(subworkflow, parentWorkflow.id);
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
await expect(check).resolves.not.toThrow();
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
});
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
describe('workflows-from-same-owner caller policy', () => {
test('should deny if the two workflows are owned by different users', async () => {
const parentWorkflowOwner = Container.get(UserRepository).create({ id: uuid() });
const subworkflowOwner = Container.get(UserRepository).create({ id: uuid() });
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
ownershipService.getWorkflowOwnerCached.mockResolvedValueOnce(parentWorkflowOwner); // parent workflow
ownershipService.getWorkflowOwnerCached.mockResolvedValueOnce(subworkflowOwner); // subworkflow
const subworkflow = createSubworkflow({ policy: 'workflowsFromSameOwner' });
const check = permissionChecker.checkSubworkflowExecutePolicy(subworkflow, uuid());
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
await expect(check).rejects.toThrow(toTargetCallErrorMsg(subworkflow.id));
});
test('should allow if both workflows are owned by the same user', async () => {
test(core): Improve tests for subworkflow caller policy checks (no-changelog) (#7954) ## Summary Deduplicate, separate, organize and speed up tests for subworkflow caller policy checks. Follow-up to: https://github.com/n8n-io/n8n/pull/7913 ``` PASS test/unit/PermissionChecker.test.ts check() ✓ should allow if workflow has no creds (3 ms) ✓ should allow if requesting user is instance owner (83 ms) ✓ should allow if workflow creds are valid subset (151 ms) ✓ should deny if workflow creds are not valid subset (85 ms) checkSubworkflowExecutePolicy() no caller policy ✓ should fall back to N8N_WORKFLOW_CALLER_POLICY_DEFAULT_OPTION (1 ms) overridden caller policy ✓ if no sharing, policy becomes workflows-from-same-owner (1 ms) workflows-from-list caller policy ✓ should allow if caller list contains parent workflow ID ✓ should deny if caller list does not contain parent workflow ID (1 ms) any caller policy ✓ should not throw workflows-from-same-owner caller policy ✓ should deny if the two workflows are owned by different users (1 ms) ✓ should allow if both workflows are owned by the same user ``` ... #### How to test the change: 1. ... ## Issues fixed Include links to Github issue or Community forum post or **Linear ticket**: > Important in order to close automatically and provide context to reviewers ... ## Review / Merge checklist - [ ] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] [Docs updated](https://github.com/n8n-io/n8n-docs) or follow-up ticket created. - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. A feature is not complete without tests. > > *(internal)* You can use Slack commands to trigger [e2e tests](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#a39f9e5ba64a48b58a71d81c837e8227) or [deploy test instance](https://www.notion.so/n8n/How-to-use-Test-Instances-d65f49dfc51f441ea44367fb6f67eb0a?pvs=4#f6a177d32bde4b57ae2da0b8e454bfce) or [deploy early access version on Cloud](https://www.notion.so/n8n/Cloudbot-3dbe779836004972b7057bc989526998?pvs=4#fef2d36ab02247e1a0f65a74f6fb534e).
2023-12-08 02:21:43 -08:00
const parentWorkflow = createParentWorkflow();
const bothWorkflowsOwner = Container.get(UserRepository).create({ id: uuid() });
ownershipService.getWorkflowOwnerCached.mockResolvedValueOnce(bothWorkflowsOwner); // parent workflow
ownershipService.getWorkflowOwnerCached.mockResolvedValueOnce(bothWorkflowsOwner); // subworkflow
const subworkflow = createSubworkflow({ policy: 'workflowsFromSameOwner' });
const check = permissionChecker.checkSubworkflowExecutePolicy(subworkflow, parentWorkflow.id);
await expect(check).resolves.not.toThrow();
});
});
});