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

This commit is contained in:
2026-03-17 16:22:57 +03:30
commit 3d5eaf9445
15349 changed files with 2847338 additions and 0 deletions
@@ -0,0 +1,303 @@
import { mockDeep } from 'jest-mock-extended';
import type { IExecuteFunctions, INode } from 'n8n-workflow';
import { microsoftApiRequest, microsoftApiPaginateRequest } from '../GenericFunctions';
describe('Microsoft Entra GenericFunctions', () => {
let mockExecuteFunctions: jest.Mocked<IExecuteFunctions>;
let mockNode: INode;
let mockRequestWithAuthentication: jest.Mock;
let mockRequestWithAuthenticationPaginated: jest.Mock;
beforeEach(() => {
mockExecuteFunctions = mockDeep<IExecuteFunctions>();
mockRequestWithAuthentication = jest.fn();
mockRequestWithAuthenticationPaginated = jest.fn();
mockExecuteFunctions.helpers.requestWithAuthentication = mockRequestWithAuthentication;
mockExecuteFunctions.helpers.requestWithAuthenticationPaginated =
mockRequestWithAuthenticationPaginated;
mockNode = {
id: 'test-node',
name: 'Test Entra Node',
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [0, 0],
parameters: {},
};
mockExecuteFunctions.getNode.mockReturnValue(mockNode);
mockExecuteFunctions.getCredentials = jest.fn();
jest.clearAllMocks();
});
afterEach(() => {
jest.resetAllMocks();
});
describe('microsoftApiRequest', () => {
describe('graphApiBaseUrl from credentials', () => {
it('should use base URL from credentials', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://graph.microsoft.us',
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://graph.microsoft.us/v1.0/groups',
json: true,
}),
);
});
it('should fall back to default when credentials.graphApiBaseUrl is empty', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: '',
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/groups',
json: true,
}),
);
});
it('should fall back to default when credentials.graphApiBaseUrl is undefined', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/groups',
json: true,
}),
);
});
it('should strip trailing slashes from base URL using regex', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://graph.microsoft.com/',
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/groups',
json: true,
}),
);
});
it('should strip multiple trailing slashes from base URL', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://graph.microsoft.com///',
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/groups',
json: true,
}),
);
});
it('should use US Government cloud endpoint', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://graph.microsoft.us',
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://graph.microsoft.us/v1.0/groups',
json: true,
}),
);
});
it('should use US Government DOD cloud endpoint', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://dod-graph.microsoft.us',
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://dod-graph.microsoft.us/v1.0/groups',
json: true,
}),
);
});
it('should use China cloud endpoint', async () => {
const mockResponse = { data: 'test' };
mockRequestWithAuthentication.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://microsoftgraph.chinacloudapi.cn',
});
await microsoftApiRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthentication).toHaveBeenCalledWith(
'microsoftEntraOAuth2Api',
expect.objectContaining({
method: 'GET',
url: 'https://microsoftgraph.chinacloudapi.cn/v1.0/groups',
json: true,
}),
);
});
});
});
describe('microsoftApiPaginateRequest', () => {
describe('graphApiBaseUrl from credentials', () => {
it('should use base URL from credentials', async () => {
const mockResponse = [{ body: { value: [{ id: '1', name: 'Group 1' }] } }];
mockRequestWithAuthenticationPaginated.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://graph.microsoft.us',
});
await microsoftApiPaginateRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthenticationPaginated).toHaveBeenCalledWith(
expect.objectContaining({
method: 'GET',
uri: 'https://graph.microsoft.us/v1.0/groups',
json: true,
}),
0,
expect.objectContaining({
continue: expect.any(String),
request: expect.any(Object),
requestInterval: 0,
}),
'microsoftEntraOAuth2Api',
);
});
it('should fall back to default when credentials.graphApiBaseUrl is empty', async () => {
const mockResponse = [{ body: { value: [{ id: '1', name: 'Group 1' }] } }];
mockRequestWithAuthenticationPaginated.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: '',
});
await microsoftApiPaginateRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthenticationPaginated).toHaveBeenCalledWith(
expect.objectContaining({
method: 'GET',
uri: 'https://graph.microsoft.com/v1.0/groups',
json: true,
}),
0,
expect.objectContaining({
continue: expect.any(String),
request: expect.any(Object),
requestInterval: 0,
}),
'microsoftEntraOAuth2Api',
);
});
it('should strip trailing slashes from base URL using regex', async () => {
const mockResponse = [{ body: { value: [{ id: '1', name: 'Group 1' }] } }];
mockRequestWithAuthenticationPaginated.mockResolvedValue(mockResponse);
mockExecuteFunctions.getCredentials.mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
graphApiBaseUrl: 'https://graph.microsoft.com/',
});
await microsoftApiPaginateRequest.call(mockExecuteFunctions, 'GET', '/groups');
expect(mockRequestWithAuthenticationPaginated).toHaveBeenCalledWith(
expect.objectContaining({
method: 'GET',
uri: 'https://graph.microsoft.com/v1.0/groups',
json: true,
}),
0,
expect.objectContaining({
continue: expect.any(String),
request: expect.any(Object),
requestInterval: 0,
}),
'microsoftEntraOAuth2Api',
);
});
});
});
});
@@ -0,0 +1,749 @@
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import { NodeConnectionTypes, type WorkflowTestData } from 'n8n-workflow';
import { microsoftEntraApiResponse, microsoftEntraNodeResponse } from './mocks';
describe('Microsoft Entra Node', () => {
const baseUrl = 'https://graph.microsoft.com/v1.0';
const testHarness = new NodeTestHarness();
describe('Group description', () => {
const tests: WorkflowTestData[] = [
{
description: 'should create group',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'create',
displayName: 'Group Display Name',
groupType: 'Unified',
mailEnabled: true,
mailNickname: 'MailNickname',
membershipType: 'DynamicMembership',
securityEnabled: true,
additionalFields: {
isAssignableToRole: true,
description: 'Group Description',
membershipRule: 'department -eq "Marketing"',
membershipRuleProcessingState: 'On',
preferredDataLocation: 'Preferred Data Location',
uniqueName: 'UniqueName',
visibility: 'Public',
},
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [microsoftEntraNodeResponse.createGroup],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'post',
path: '/groups',
statusCode: 201,
requestBody: {
displayName: 'Group Display Name',
mailNickname: 'MailNickname',
mailEnabled: true,
membershipRule: 'department -eq "Marketing"',
membershipRuleProcessingState: 'On',
securityEnabled: true,
groupTypes: ['Unified', 'DynamicMembership'],
},
responseBody: microsoftEntraApiResponse.postGroup,
},
{
method: 'patch',
path: `/groups/${microsoftEntraApiResponse.postGroup.id}`,
statusCode: 204,
requestBody: {
description: 'Group Description',
preferredDataLocation: 'Preferred Data Location',
uniqueName: 'UniqueName',
visibility: 'Public',
},
responseBody: {},
},
],
},
},
{
description: 'should delete group',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'delete',
group: {
__rl: true,
value: 'a8eb60e3-0145-4d7e-85ef-c6259784761b',
mode: 'id',
},
options: {},
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [microsoftEntraNodeResponse.deleteGroup],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'delete',
path: '/groups/a8eb60e3-0145-4d7e-85ef-c6259784761b',
statusCode: 204,
responseBody: {},
},
],
},
},
{
description: 'should get group',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'get',
group: {
__rl: true,
value: 'a8eb60e3-0145-4d7e-85ef-c6259784761b',
mode: 'id',
},
output: 'raw',
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [microsoftEntraNodeResponse.getGroup],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'get',
path: '/groups/a8eb60e3-0145-4d7e-85ef-c6259784761b',
statusCode: 200,
responseBody: microsoftEntraApiResponse.getGroup,
},
],
},
},
{
description: 'should get group with fields output and members',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'get',
group: {
__rl: true,
value: 'a8eb60e3-0145-4d7e-85ef-c6259784761b',
mode: 'id',
},
output: 'fields',
fields: [
'assignedLabels',
'assignedLicenses',
'createdDateTime',
'classification',
'deletedDateTime',
'description',
'displayName',
'expirationDateTime',
'groupTypes',
'visibility',
'unseenCount',
'theme',
'uniqueName',
'serviceProvisioningErrors',
'securityIdentifier',
'renewedDateTime',
'securityEnabled',
'autoSubscribeNewMembers',
'allowExternalSenders',
'licenseProcessingState',
'isManagementRestricted',
'isSubscribedByMail',
'isAssignableToRole',
'id',
'hideFromOutlookClients',
'hideFromAddressLists',
'onPremisesProvisioningErrors',
'onPremisesSecurityIdentifier',
'onPremisesSamAccountName',
'onPremisesNetBiosName',
'onPremisesSyncEnabled',
'preferredDataLocation',
'preferredLanguage',
'proxyAddresses',
'onPremisesLastSyncDateTime',
'onPremisesDomainName',
'membershipRuleProcessingState',
'membershipRule',
'mailNickname',
'mailEnabled',
'mail',
],
options: {
includeMembers: true,
},
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [microsoftEntraNodeResponse.getGroupWithProperties],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'get',
path: '/groups/a8eb60e3-0145-4d7e-85ef-c6259784761b?$select=assignedLabels,assignedLicenses,createdDateTime,classification,deletedDateTime,description,displayName,expirationDateTime,groupTypes,visibility,unseenCount,theme,uniqueName,serviceProvisioningErrors,securityIdentifier,renewedDateTime,securityEnabled,autoSubscribeNewMembers,allowExternalSenders,licenseProcessingState,isManagementRestricted,isSubscribedByMail,isAssignableToRole,id,hideFromOutlookClients,hideFromAddressLists,onPremisesProvisioningErrors,onPremisesSecurityIdentifier,onPremisesSamAccountName,onPremisesNetBiosName,onPremisesSyncEnabled,preferredDataLocation,preferredLanguage,proxyAddresses,onPremisesLastSyncDateTime,onPremisesDomainName,membershipRuleProcessingState,membershipRule,mailNickname,mailEnabled,mail,id&$expand=members($select=id,accountEnabled,createdDateTime,displayName,employeeId,mail,securityIdentifier,userPrincipalName,userType)',
statusCode: 200,
responseBody: microsoftEntraApiResponse.getGroupWithProperties,
},
],
},
},
{
description: 'should get all groups with simple output',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'getAll',
returnAll: true,
filter: '',
output: 'simple',
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [new Array(102).fill(microsoftEntraNodeResponse.getGroup[0])],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'get',
path: '/groups?$select=id,createdDateTime,description,displayName,mail,mailEnabled,mailNickname,securityEnabled,securityIdentifier,visibility',
statusCode: 200,
responseBody: {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#groups',
'@odata.nextLink':
'https://graph.microsoft.com/v1.0/groups?$select=id,createdDateTime,description,displayName,mail,mailEnabled,mailNickname,securityEnabled,securityIdentifier,visibility&$skiptoken=RFNwdAIAAQAAACpHcm91cF9jYzEzY2Y5Yy1lOWNiLTQ3NjUtODMzYS05MDIzZDhhMjhlZjMqR3JvdXBfY2MxM2NmOWMtZTljYi00NzY1LTgzM2EtOTAyM2Q4YTI4ZWYzAAAAAAAAAAAAAAA',
value: new Array(100).fill(microsoftEntraApiResponse.getGroup),
},
},
{
method: 'get',
path: '/groups?$select=id,createdDateTime,description,displayName,mail,mailEnabled,mailNickname,securityEnabled,securityIdentifier,visibility&$skiptoken=RFNwdAIAAQAAACpHcm91cF9jYzEzY2Y5Yy1lOWNiLTQ3NjUtODMzYS05MDIzZDhhMjhlZjMqR3JvdXBfY2MxM2NmOWMtZTljYi00NzY1LTgzM2EtOTAyM2Q4YTI4ZWYzAAAAAAAAAAAAAAA',
statusCode: 200,
responseBody: {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#groups',
value: new Array(2).fill(microsoftEntraApiResponse.getGroup),
},
},
],
},
},
{
description: 'should get limit 10 groups with raw output',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'getAll',
limit: 10,
filter: '',
output: 'raw',
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [new Array(10).fill(microsoftEntraNodeResponse.getGroup[0])],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'get',
path: '/groups?$top=10',
statusCode: 200,
responseBody: {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#groups',
'@odata.nextLink':
'https://graph.microsoft.com/v1.0/groups?$top=10&$skiptoken=RFNwdAIAAQAAACpHcm91cF9jYzEzY2Y5Yy1lOWNiLTQ3NjUtODMzYS05MDIzZDhhMjhlZjMqR3JvdXBfY2MxM2NmOWMtZTljYi00NzY1LTgzM2EtOTAyM2Q4YTI4ZWYzAAAAAAAAAAAAAAA',
value: new Array(10).fill(microsoftEntraApiResponse.getGroup),
},
},
],
},
},
{
description: 'should get all groups with options and filter',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'getAll',
returnAll: true,
filter: "startswith(displayName,'group')",
output: 'fields',
fields: [
'assignedLabels',
'assignedLicenses',
'createdDateTime',
'classification',
'deletedDateTime',
'description',
'displayName',
'expirationDateTime',
'groupTypes',
'visibility',
'theme',
'uniqueName',
'serviceProvisioningErrors',
'securityIdentifier',
'renewedDateTime',
'securityEnabled',
'licenseProcessingState',
'isManagementRestricted',
'isAssignableToRole',
'onPremisesProvisioningErrors',
'onPremisesSecurityIdentifier',
'onPremisesSamAccountName',
'onPremisesNetBiosName',
'onPremisesSyncEnabled',
'preferredDataLocation',
'preferredLanguage',
'proxyAddresses',
'onPremisesLastSyncDateTime',
'onPremisesDomainName',
'membershipRuleProcessingState',
'membershipRule',
'mailNickname',
'mailEnabled',
'mail',
],
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [
new Array(102).fill(microsoftEntraNodeResponse.getGroupWithProperties[0]),
],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'get',
path: "/groups?$filter=startswith(displayName,'group')&$select=assignedLabels,assignedLicenses,createdDateTime,classification,deletedDateTime,description,displayName,expirationDateTime,groupTypes,visibility,theme,uniqueName,serviceProvisioningErrors,securityIdentifier,renewedDateTime,securityEnabled,licenseProcessingState,isManagementRestricted,isAssignableToRole,onPremisesProvisioningErrors,onPremisesSecurityIdentifier,onPremisesSamAccountName,onPremisesNetBiosName,onPremisesSyncEnabled,preferredDataLocation,preferredLanguage,proxyAddresses,onPremisesLastSyncDateTime,onPremisesDomainName,membershipRuleProcessingState,membershipRule,mailNickname,mailEnabled,mail,id",
statusCode: 200,
responseBody: {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#groups',
'@odata.nextLink':
"https://graph.microsoft.com/v1.0/groups?$filter=startswith(displayName,'group')&$select=assignedLabels,assignedLicenses,createdDateTime,classification,deletedDateTime,description,displayName,expirationDateTime,groupTypes,visibility,theme,uniqueName,serviceProvisioningErrors,securityIdentifier,renewedDateTime,securityEnabled,licenseProcessingState,isManagementRestricted,isAssignableToRole,onPremisesProvisioningErrors,onPremisesSecurityIdentifier,onPremisesSamAccountName,onPremisesNetBiosName,onPremisesSyncEnabled,preferredDataLocation,preferredLanguage,proxyAddresses,onPremisesLastSyncDateTime,onPremisesDomainName,membershipRuleProcessingState,membershipRule,mailNickname,mailEnabled,mail,id&$skiptoken=RFNwdAIAAQAAACpHcm91cF9jYzEzY2Y5Yy1lOWNiLTQ3NjUtODMzYS05MDIzZDhhMjhlZjMqR3JvdXBfY2MxM2NmOWMtZTljYi00NzY1LTgzM2EtOTAyM2Q4YTI4ZWYzAAAAAAAAAAAAAAA",
value: new Array(100).fill(microsoftEntraApiResponse.getGroupWithProperties),
},
},
{
method: 'get',
path: "/groups?$filter=startswith(displayName,'group')&$select=assignedLabels,assignedLicenses,createdDateTime,classification,deletedDateTime,description,displayName,expirationDateTime,groupTypes,visibility,theme,uniqueName,serviceProvisioningErrors,securityIdentifier,renewedDateTime,securityEnabled,licenseProcessingState,isManagementRestricted,isAssignableToRole,onPremisesProvisioningErrors,onPremisesSecurityIdentifier,onPremisesSamAccountName,onPremisesNetBiosName,onPremisesSyncEnabled,preferredDataLocation,preferredLanguage,proxyAddresses,onPremisesLastSyncDateTime,onPremisesDomainName,membershipRuleProcessingState,membershipRule,mailNickname,mailEnabled,mail,id&$skiptoken=RFNwdAIAAQAAACpHcm91cF9jYzEzY2Y5Yy1lOWNiLTQ3NjUtODMzYS05MDIzZDhhMjhlZjMqR3JvdXBfY2MxM2NmOWMtZTljYi00NzY1LTgzM2EtOTAyM2Q4YTI4ZWYzAAAAAAAAAAAAAAA",
statusCode: 200,
responseBody: {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#groups',
value: new Array(2).fill(microsoftEntraApiResponse.getGroupWithProperties),
},
},
],
},
},
{
description: 'should update group',
input: {
workflowData: {
nodes: [
{
parameters: {},
id: '416e4fc1-5055-4e61-854e-a6265256ac26',
name: 'When clicking Execute workflow',
type: 'n8n-nodes-base.manualTrigger',
position: [820, 380],
typeVersion: 1,
},
{
parameters: {
resource: 'group',
operation: 'update',
group: {
__rl: true,
value: 'a8eb60e3-0145-4d7e-85ef-c6259784761b',
mode: 'id',
},
updateFields: {
allowExternalSenders: true,
autoSubscribeNewMembers: true,
description: 'Group Description',
displayName: 'Group Display Name',
mailNickname: 'MailNickname',
membershipRule: 'department -eq "Marketing"',
membershipRuleProcessingState: 'On',
preferredDataLocation: 'Preferred Data Location',
securityEnabled: true,
uniqueName: 'UniqueName',
visibility: 'Public',
},
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [microsoftEntraNodeResponse.updateGroup],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'patch',
path: `/groups/${microsoftEntraApiResponse.postGroup.id}`,
statusCode: 204,
requestBody: {
description: 'Group Description',
displayName: 'Group Display Name',
mailNickname: 'MailNickname',
membershipRule: 'department -eq "Marketing"',
membershipRuleProcessingState: 'On',
preferredDataLocation: 'Preferred Data Location',
securityEnabled: true,
uniqueName: 'UniqueName',
visibility: 'Public',
},
responseBody: {},
},
{
method: 'patch',
path: `/groups/${microsoftEntraApiResponse.postGroup.id}`,
statusCode: 204,
requestBody: {
allowExternalSenders: true,
autoSubscribeNewMembers: true,
},
responseBody: {},
},
],
},
},
];
for (const testData of tests) {
testHarness.setupTest(testData);
}
});
});
@@ -0,0 +1,226 @@
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import type { ILoadOptionsFunctions, WorkflowTestData } from 'n8n-workflow';
import { NodeConnectionTypes } from 'n8n-workflow';
import { microsoftEntraApiResponse, microsoftEntraNodeResponse } from './mocks';
import { MicrosoftEntra } from '../MicrosoftEntra.node';
describe('Microsoft Entra Node', () => {
const testHarness = new NodeTestHarness();
const baseUrl = 'https://graph.microsoft.com/v1.0';
describe('Credentials', () => {
const credentials = {
microsoftEntraOAuth2Api: {
scope: '',
oauthTokenData: {
access_token: 'ACCESSTOKEN',
},
},
};
const tests: WorkflowTestData[] = [
{
description: 'should use correct credentials',
input: {
workflowData: {
nodes: [
{
parameters: {},
type: 'n8n-nodes-base.manualTrigger',
typeVersion: 1,
position: [0, 0],
id: '1307e408-a8a5-464e-b858-494953e2f43b',
name: 'When clicking Execute workflow',
},
{
parameters: {
resource: 'group',
operation: 'get',
group: {
__rl: true,
value: 'a8eb60e3-0145-4d7e-85ef-c6259784761b',
mode: 'id',
},
filter: '',
output: 'raw',
requestOptions: {},
},
type: 'n8n-nodes-base.microsoftEntra',
typeVersion: 1,
position: [220, 0],
id: '3429f7f2-dfca-4b72-8913-43a582e96e66',
name: 'Microsoft Entra ID',
credentials: {
microsoftEntraOAuth2Api: {
id: 'Hot2KwSMSoSmMVqd',
name: 'Microsoft Entra ID (Azure Active Directory) account',
},
},
},
],
connections: {
'When clicking Execute workflow': {
main: [
[
{
node: 'Microsoft Entra ID',
type: NodeConnectionTypes.Main,
index: 0,
},
],
],
},
},
},
},
output: {
nodeData: {
'Microsoft Entra ID': [microsoftEntraNodeResponse.getGroup],
},
},
nock: {
baseUrl,
mocks: [
{
method: 'get',
path: `/groups/${microsoftEntraApiResponse.getGroup.id}`,
statusCode: 200,
responseBody: {
...microsoftEntraApiResponse.getGroup,
},
},
],
},
},
];
for (const testData of tests) {
testHarness.setupTest(testData, { credentials });
}
});
describe('Load options', () => {
it('should load group properties', async () => {
const mockContext = {
helpers: {
requestWithAuthentication: jest
.fn()
.mockReturnValue(microsoftEntraApiResponse.metadata.groups),
},
getCurrentNodeParameter: jest.fn(),
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const properties = await node.methods.loadOptions.getGroupProperties.call(mockContext);
expect(properties).toEqual(microsoftEntraNodeResponse.loadOptions.getGroupProperties);
});
it('should load user properties', async () => {
const mockContext = {
helpers: {
requestWithAuthentication: jest
.fn()
.mockReturnValue(microsoftEntraApiResponse.metadata.users),
},
getCurrentNodeParameter: jest.fn(),
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const properties = await node.methods.loadOptions.getUserProperties.call(mockContext);
expect(properties).toEqual(microsoftEntraNodeResponse.loadOptions.getUserProperties);
});
});
describe('List search', () => {
it('should list search groups', async () => {
const mockResponse = {
value: Array.from({ length: 2 }, (_, i) => ({
id: (i + 1).toString(),
displayName: `Group ${i + 1}`,
})),
'@odata.nextLink': '',
};
const mockRequestWithAuthentication = jest.fn().mockReturnValue(mockResponse);
const mockContext = {
helpers: {
requestWithAuthentication: mockRequestWithAuthentication,
},
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const listSearchResult = await node.methods.listSearch.getGroups.call(mockContext);
expect(mockRequestWithAuthentication).toHaveBeenCalledWith('microsoftEntraOAuth2Api', {
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/groups',
json: true,
headers: {},
body: {},
qs: {
$select: 'id,displayName',
},
});
expect(listSearchResult).toEqual({
results: mockResponse.value.map((x) => ({ name: x.displayName, value: x.id })),
paginationToken: mockResponse['@odata.nextLink'],
});
});
it('should list search users', async () => {
const mockResponse = {
value: Array.from({ length: 2 }, (_, i) => ({
id: (i + 1).toString(),
displayName: `User ${i + 1}`,
})),
'@odata.nextLink': '',
};
const mockRequestWithAuthentication = jest.fn().mockReturnValue(mockResponse);
const mockContext = {
helpers: {
requestWithAuthentication: mockRequestWithAuthentication,
},
getCredentials: jest.fn().mockResolvedValue({
oauthTokenData: {
access_token: 'test-access-token',
},
}),
} as unknown as ILoadOptionsFunctions;
const node = new MicrosoftEntra();
const listSearchResult = await node.methods.listSearch.getUsers.call(mockContext);
expect(mockRequestWithAuthentication).toHaveBeenCalledWith('microsoftEntraOAuth2Api', {
method: 'GET',
url: 'https://graph.microsoft.com/v1.0/users',
json: true,
headers: {},
body: {},
qs: {
$select: 'id,displayName',
},
});
expect(listSearchResult).toEqual({
results: mockResponse.value.map((x) => ({ name: x.displayName, value: x.id })),
paginationToken: mockResponse['@odata.nextLink'],
});
});
});
});
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long