-
Notifications
You must be signed in to change notification settings - Fork 98
[PM-37608] Expand integration testing #1140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BTreston
wants to merge
6
commits into
main
Choose a base branch
from
ac/pm-37608-integration-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5beeb08
entra integration tests
BTreston dd96b03
Merge branch 'main' into ac/pm-37608-integration-tests
BTreston 8dcbf20
okta integration tests + fixtures
BTreston 5b1c850
remove WIP oneLogin service
BTreston 887dbbc
update CI tests
BTreston 3643bda
fix tests
BTreston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
libs/services/directory-services/entra-id-directory.service.integration.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * @jest-environment node | ||
| */ | ||
| import { config as dotenvConfig } from "dotenv"; | ||
| import { mock, MockProxy } from "jest-mock-extended"; | ||
|
|
||
| import { I18nService } from "@/libs/abstractions/i18n.service"; | ||
| import { LogService } from "@/libs/abstractions/log.service"; | ||
| import { StateService } from "@/libs/abstractions/state.service"; | ||
|
|
||
| import { | ||
| getEntraIdConfiguration, | ||
| getSyncConfiguration, | ||
| } from "../../../utils/entra/config-fixtures"; | ||
| import { allGroupFixtures, filteredGroupFixtures } from "../../../utils/entra/group-fixtures"; | ||
| import { allUserFixtures, groupAUserFixtures } from "../../../utils/entra/user-fixtures"; | ||
| import { DirectoryType } from "../../enums/directoryType"; | ||
|
|
||
| import { EntraIdDirectoryService } from "./entra-id-directory.service"; | ||
|
|
||
| // These tests integrate with a test Microsoft Entra ID tenant. | ||
| // Credentials are located in the shared Bitwarden collection for Directory Connector testing. | ||
| // Place the .env file attachment in the utils folder. | ||
|
|
||
| // Load .env variables | ||
| dotenvConfig({ path: "utils/.env" }); | ||
|
|
||
| // This filter targets integration test data. | ||
| // It should return data that matches the fixtures exactly. | ||
| const INTEGRATION_GROUP_FILTER = "include: Integration Testing Group A"; | ||
|
|
||
| // These tests are slow! | ||
| // Increase the default timeout from 5s to 30s | ||
| jest.setTimeout(30000); | ||
|
|
||
| describe("entraIdDirectoryService", () => { | ||
| let logService: MockProxy<LogService>; | ||
| let i18nService: MockProxy<I18nService>; | ||
| let stateService: MockProxy<StateService>; | ||
|
|
||
| let directoryService: EntraIdDirectoryService; | ||
|
|
||
| beforeEach(() => { | ||
| logService = mock(); | ||
| i18nService = mock(); | ||
| stateService = mock(); | ||
|
|
||
| stateService.getDirectoryType.mockResolvedValue(DirectoryType.EntraID); | ||
| stateService.getDirectory | ||
| .calledWith(DirectoryType.EntraID) | ||
| .mockResolvedValue(getEntraIdConfiguration()); | ||
| stateService.getUserDelta.mockResolvedValue(null); // do not use delta link, fetch from scratch | ||
| i18nService.t.mockImplementation((id) => id); // passthrough for error messages | ||
|
|
||
| directoryService = new EntraIdDirectoryService(logService, i18nService, stateService); | ||
| }); | ||
|
|
||
| it("syncs without filters (includes integration test data)", async () => { | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: true, groups: true })); | ||
|
|
||
| const [groups, users] = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(groups).toEqual(expect.arrayContaining(allGroupFixtures)); | ||
| expect(users).toEqual(expect.arrayContaining(allUserFixtures)); | ||
| }); | ||
|
|
||
| it("syncs users only (no groups)", async () => { | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: true, groups: false })); | ||
|
|
||
| const [groups, users] = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(groups).toBeUndefined(); | ||
| expect(users).toEqual(expect.arrayContaining(allUserFixtures)); | ||
| }); | ||
|
|
||
| it("syncs groups only (no users)", async () => { | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: false, groups: true })); | ||
|
|
||
| const [groups, users] = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(groups).toEqual(expect.arrayContaining(allGroupFixtures)); | ||
| expect(users).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("syncs using group filter (exact match for integration test data)", async () => { | ||
| stateService.getSync.mockResolvedValue( | ||
| getSyncConfiguration({ users: true, groups: true, groupFilter: INTEGRATION_GROUP_FILTER }), | ||
| ); | ||
|
|
||
| const result = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(result).toEqual([filteredGroupFixtures, groupAUserFixtures]); | ||
| }); | ||
|
|
||
| it("throws when credentials are invalid", async () => { | ||
| stateService.getDirectory | ||
| .calledWith(DirectoryType.EntraID) | ||
| .mockResolvedValue(getEntraIdConfiguration({ key: "bad-secret" })); | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: true, groups: true })); | ||
|
|
||
| await expect(directoryService.getEntries(true, true)).rejects.toThrow(); | ||
| }); | ||
| }); |
103 changes: 103 additions & 0 deletions
103
libs/services/directory-services/okta-directory.service.integration.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * @jest-environment node | ||
| */ | ||
| import { config as dotenvConfig } from "dotenv"; | ||
| import { mock, MockProxy } from "jest-mock-extended"; | ||
|
|
||
| import { I18nService } from "@/libs/abstractions/i18n.service"; | ||
| import { LogService } from "@/libs/abstractions/log.service"; | ||
| import { StateService } from "@/libs/abstractions/state.service"; | ||
|
|
||
| import { getOktaConfiguration, getSyncConfiguration } from "../../../utils/okta/config-fixtures"; | ||
| import { allGroupFixtures, integrationGroupFixtures } from "../../../utils/okta/group-fixtures"; | ||
| import { allUserFixtures, integrationGroupUserFixtures } from "../../../utils/okta/user-fixtures"; | ||
| import { DirectoryType } from "../../enums/directoryType"; | ||
|
|
||
| import { OktaDirectoryService } from "./okta-directory.service"; | ||
|
|
||
| // These tests integrate with a test Okta organization. | ||
| // Credentials are located in the shared Bitwarden collection for Directory Connector testing. | ||
| // Place the .env file attachment in the utils folder. | ||
|
|
||
| // Load .env variables | ||
| dotenvConfig({ path: "utils/.env" }); | ||
|
|
||
| // This filter targets the integration test groups exactly. | ||
| const INTEGRATION_GROUP_FILTER = "include: Integration Test Group A, Integration Test Group B"; | ||
|
|
||
| // These tests are slow! | ||
| // Increase the default timeout from 5s to 30s | ||
| jest.setTimeout(30000); | ||
|
|
||
| describe("oktaDirectoryService", () => { | ||
| let logService: MockProxy<LogService>; | ||
| let i18nService: MockProxy<I18nService>; | ||
| let stateService: MockProxy<StateService>; | ||
|
|
||
| let directoryService: OktaDirectoryService; | ||
|
|
||
| beforeEach(() => { | ||
| logService = mock(); | ||
| i18nService = mock(); | ||
| stateService = mock(); | ||
|
|
||
| stateService.getDirectoryType.mockResolvedValue(DirectoryType.Okta); | ||
| stateService.getDirectory | ||
| .calledWith(DirectoryType.Okta) | ||
| .mockResolvedValue(getOktaConfiguration()); | ||
| stateService.getLastUserSync.mockResolvedValue(null); // do not filter results by last modified date | ||
| stateService.getLastGroupSync.mockResolvedValue(null); // do not filter results by last modified date | ||
| i18nService.t.mockImplementation((id) => id); // passthrough for error messages | ||
|
|
||
| directoryService = new OktaDirectoryService(logService, i18nService, stateService); | ||
| }); | ||
|
|
||
| it("syncs without filters (includes integration test data)", async () => { | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: true, groups: true })); | ||
|
|
||
| const [groups, users] = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(groups).toEqual(expect.arrayContaining(allGroupFixtures)); | ||
| expect(users).toEqual(expect.arrayContaining(allUserFixtures)); | ||
| }); | ||
|
|
||
| it("syncs users only (no groups)", async () => { | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: true, groups: false })); | ||
|
|
||
| const [groups, users] = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(groups).toBeUndefined(); | ||
| expect(users).toEqual(expect.arrayContaining(allUserFixtures)); | ||
| }); | ||
|
|
||
| it("syncs groups only (no users)", async () => { | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: false, groups: true })); | ||
|
|
||
| const [groups, users] = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(groups).toEqual(expect.arrayContaining(allGroupFixtures)); | ||
| expect(users).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("syncs using group filter (exact match for integration test data)", async () => { | ||
| stateService.getSync.mockResolvedValue( | ||
| getSyncConfiguration({ users: true, groups: true, groupFilter: INTEGRATION_GROUP_FILTER }), | ||
| ); | ||
|
|
||
| const [groups, users] = await directoryService.getEntries(true, true); | ||
|
|
||
| expect(groups).toEqual(expect.arrayContaining(integrationGroupFixtures)); | ||
| expect(groups).toHaveLength(integrationGroupFixtures.length); | ||
| expect(users).toEqual(expect.arrayContaining(integrationGroupUserFixtures)); | ||
| expect(users).toHaveLength(integrationGroupUserFixtures.length); | ||
| }); | ||
|
|
||
| it("throws when credentials are invalid", async () => { | ||
| stateService.getDirectory | ||
| .calledWith(DirectoryType.Okta) | ||
| .mockResolvedValue(getOktaConfiguration({ token: "bad-token-00000" })); | ||
| stateService.getSync.mockResolvedValue(getSyncConfiguration({ users: true, groups: true })); | ||
|
|
||
| await expect(directoryService.getEntries(true, true)).rejects.toThrow(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { EntraIdConfiguration } from "@/libs/models/entraIdConfiguration"; | ||
| import { SyncConfiguration } from "@/libs/models/syncConfiguration"; | ||
|
|
||
| /** | ||
| * @returns a basic Entra ID configuration. Can be overridden by passing in a partial configuration. | ||
| */ | ||
| export const getEntraIdConfiguration = ( | ||
| config?: Partial<EntraIdConfiguration>, | ||
| ): EntraIdConfiguration => { | ||
| const tenant = process.env.ENTRA_TENANT_ID; | ||
| const applicationId = process.env.ENTRA_APPLICATION_ID; | ||
| const key = process.env.ENTRA_KEY; | ||
|
|
||
| if (!tenant || !applicationId || !key) { | ||
| throw new Error("Entra ID integration test credentials not configured."); | ||
| } | ||
|
|
||
| return { | ||
| identityAuthority: "login.microsoftonline.com", | ||
| tenant, | ||
| applicationId, | ||
| key, | ||
| ...(config ?? {}), | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * @returns a basic sync configuration. Can be overridden by passing in a partial configuration. | ||
| */ | ||
| export const getSyncConfiguration = (config?: Partial<SyncConfiguration>): SyncConfiguration => ({ | ||
| users: false, | ||
| groups: false, | ||
| interval: 5, | ||
| userFilter: "", | ||
| groupFilter: "", | ||
| removeDisabled: false, | ||
| overwriteExisting: false, | ||
| largeImport: false, | ||
| // Ldap properties - not optional for some reason | ||
| groupObjectClass: "", | ||
| userObjectClass: "", | ||
| groupPath: null, | ||
| userPath: null, | ||
| groupNameAttribute: "", | ||
| userEmailAttribute: "", | ||
| memberAttribute: "", | ||
| useEmailPrefixSuffix: false, | ||
| emailPrefixAttribute: "", | ||
| emailSuffix: null, | ||
| creationDateAttribute: "", | ||
| revisionDateAttribute: "", | ||
| ...(config ?? {}), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { Jsonify } from "type-fest"; | ||
|
|
||
| import { GroupEntry } from "@/libs/models/groupEntry"; | ||
|
|
||
| // These must match the Entra ID test tenant seed data | ||
|
|
||
| const allGroupsData: Jsonify<GroupEntry>[] = [ | ||
| { | ||
| externalId: "573783bf-d086-4e1e-9084-4b7b0d2a5969", | ||
| groupMemberReferenceIds: [], | ||
| name: "Integration Testing Group A", | ||
| referenceId: "573783bf-d086-4e1e-9084-4b7b0d2a5969", | ||
| userMemberExternalIds: [ | ||
| "34e12500-13ff-4700-afa0-285757ab7695", | ||
| "051c89c3-1788-44ce-9ee5-35dc1e6cb794", | ||
| "50fff556-010d-46e2-826a-c86ddf5816dc", | ||
| ], | ||
| users: [], | ||
| }, | ||
| { | ||
| externalId: "66578c29-73af-448b-b352-301f9588772b", | ||
| groupMemberReferenceIds: [], | ||
| name: "Integration Testing Group B", | ||
| referenceId: "66578c29-73af-448b-b352-301f9588772b", | ||
| userMemberExternalIds: [], | ||
| users: [], | ||
| }, | ||
| ]; | ||
|
|
||
| const filteredGroupsData: Jsonify<GroupEntry>[] = [ | ||
| { | ||
| externalId: "573783bf-d086-4e1e-9084-4b7b0d2a5969", | ||
| groupMemberReferenceIds: [], | ||
| name: "Integration Testing Group A", | ||
| referenceId: "573783bf-d086-4e1e-9084-4b7b0d2a5969", | ||
| userMemberExternalIds: [ | ||
| "34e12500-13ff-4700-afa0-285757ab7695", | ||
| "051c89c3-1788-44ce-9ee5-35dc1e6cb794", | ||
| "50fff556-010d-46e2-826a-c86ddf5816dc", | ||
| ], | ||
| users: [], | ||
| }, | ||
| ]; | ||
|
|
||
| export const allGroupFixtures = allGroupsData.map((g) => GroupEntry.fromJSON(g)); | ||
| export const filteredGroupFixtures = filteredGroupsData.map((g) => GroupEntry.fromJSON(g)); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.