From a0021f357169464a9d55e385b6634a2912b40f23 Mon Sep 17 00:00:00 2001 From: "ankitatripathi.mp@gmail.com" Date: Mon, 9 Mar 2026 23:31:17 +0530 Subject: [PATCH 1/5] Fix: TypeError in matchConnection for enterprise connections with no domains --- package.json | 8 +++++++- src/__tests__/__mocks__/undici.js | 2 ++ src/connection/enterprise.js | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 src/__tests__/__mocks__/undici.js diff --git a/package.json b/package.json index 93580450b..5dc41e5ca 100644 --- a/package.json +++ b/package.json @@ -156,6 +156,11 @@ "/src/", "/src/__tests__" ], + "moduleNameMapper": { + "^cheerio$": "/node_modules/cheerio/dist/commonjs/index.js", + "^cheerio/lib/utils$": "/node_modules/cheerio/dist/commonjs/utils.js", + "^undici$": "/src/__tests__/__mocks__/undici.js" + }, "setupFiles": [ "/src/__tests__/setup-tests.js" ], @@ -171,7 +176,8 @@ "/test/", "/lib/", "/src/__tests__/testUtils.js", - "/src/__tests__/setup-tests.js" + "/src/__tests__/setup-tests.js", + "/src/__tests__/__mocks__/" ], "coverageReporters": [ "lcov", diff --git a/src/__tests__/__mocks__/undici.js b/src/__tests__/__mocks__/undici.js new file mode 100644 index 000000000..8d90f1d00 --- /dev/null +++ b/src/__tests__/__mocks__/undici.js @@ -0,0 +1,2 @@ +// Stub for undici - only used by cheerio.fromUrl() which is not called in tests +module.exports = {}; diff --git a/src/connection/enterprise.js b/src/connection/enterprise.js index be15a3b76..9feaa36e1 100644 --- a/src/connection/enterprise.js +++ b/src/connection/enterprise.js @@ -79,7 +79,7 @@ export function matchConnection(m, email, strategies = []) { const target = emailDomain(email); if (!target) return false; return l.connections(m, 'enterprise', ...strategies).find(x => { - return x.get('domains').contains(target); + return x.get('domains', List()).contains(target); }); } From d33da4c7b821ff692958116cba46bbc6ee83cbd4 Mon Sep 17 00:00:00 2001 From: "ankitatripathi.mp@gmail.com" Date: Tue, 10 Mar 2026 15:39:58 +0530 Subject: [PATCH 2/5] Removed package.json changes --- package.json | 9 +-------- src/__tests__/__mocks__/undici.js | 2 -- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 src/__tests__/__mocks__/undici.js diff --git a/package.json b/package.json index 5dc41e5ca..87e57cd16 100644 --- a/package.json +++ b/package.json @@ -156,11 +156,6 @@ "/src/", "/src/__tests__" ], - "moduleNameMapper": { - "^cheerio$": "/node_modules/cheerio/dist/commonjs/index.js", - "^cheerio/lib/utils$": "/node_modules/cheerio/dist/commonjs/utils.js", - "^undici$": "/src/__tests__/__mocks__/undici.js" - }, "setupFiles": [ "/src/__tests__/setup-tests.js" ], @@ -175,9 +170,7 @@ "/node_modules/", "/test/", "/lib/", - "/src/__tests__/testUtils.js", - "/src/__tests__/setup-tests.js", - "/src/__tests__/__mocks__/" + "/src/__tests__/testUtils.js" ], "coverageReporters": [ "lcov", diff --git a/src/__tests__/__mocks__/undici.js b/src/__tests__/__mocks__/undici.js deleted file mode 100644 index 8d90f1d00..000000000 --- a/src/__tests__/__mocks__/undici.js +++ /dev/null @@ -1,2 +0,0 @@ -// Stub for undici - only used by cheerio.fromUrl() which is not called in tests -module.exports = {}; From bb11bb816632ddfdce092a0f313851f09a94b9d4 Mon Sep 17 00:00:00 2001 From: Ankita Tripathi <51994119+ankita10119@users.noreply.github.com> Date: Tue, 10 Mar 2026 15:51:05 +0530 Subject: [PATCH 3/5] Add setup-tests.js to testPathIgnorePatterns --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 87e57cd16..93580450b 100644 --- a/package.json +++ b/package.json @@ -170,7 +170,8 @@ "/node_modules/", "/test/", "/lib/", - "/src/__tests__/testUtils.js" + "/src/__tests__/testUtils.js", + "/src/__tests__/setup-tests.js" ], "coverageReporters": [ "lcov", From c1387f1851437c21620b775539c0df6d3634554e Mon Sep 17 00:00:00 2001 From: "ankitatripathi.mp@gmail.com" Date: Thu, 12 Mar 2026 11:53:46 +0530 Subject: [PATCH 4/5] Added the test for the fix --- .../enterprise/matchConnection.test.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/__tests__/connection/enterprise/matchConnection.test.js diff --git a/src/__tests__/connection/enterprise/matchConnection.test.js b/src/__tests__/connection/enterprise/matchConnection.test.js new file mode 100644 index 000000000..85ab26a2b --- /dev/null +++ b/src/__tests__/connection/enterprise/matchConnection.test.js @@ -0,0 +1,23 @@ +import I from 'immutable'; +import { matchConnection } from '../../../connection/enterprise'; + +jest.mock('core/index', () => ({ + connections: jest.fn() +})); + +describe('matchConnection', () => { + afterEach(() => jest.resetAllMocks()); + + it('does not throw when enterprise connection has no domains configured', () => { + const { connections } = require('core/index'); + + // Simulate tenant endpoint returning a connection with no domains field + connections.mockReturnValue( + I.fromJS([{ name: 'samlp-connection', strategy: 'samlp', type: 'enterprise' }]) + ); + + const m = I.fromJS({ id: '__lock__' }); + + expect(() => matchConnection(m, 'test@example.com')).not.toThrow(); + }); +}); From 6cba5d5113f74597b4ae1e89e39f7c3524b89d0e Mon Sep 17 00:00:00 2001 From: Ankita Tripathi <51994119+ankita10119@users.noreply.github.com> Date: Tue, 17 Mar 2026 16:19:32 +0530 Subject: [PATCH 5/5] Update matchConnection test to check result Refactor test to capture result of matchConnection call. --- src/__tests__/connection/enterprise/matchConnection.test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/__tests__/connection/enterprise/matchConnection.test.js b/src/__tests__/connection/enterprise/matchConnection.test.js index 85ab26a2b..2c350b8db 100644 --- a/src/__tests__/connection/enterprise/matchConnection.test.js +++ b/src/__tests__/connection/enterprise/matchConnection.test.js @@ -18,6 +18,10 @@ describe('matchConnection', () => { const m = I.fromJS({ id: '__lock__' }); - expect(() => matchConnection(m, 'test@example.com')).not.toThrow(); + let result; + expect(() => { + result = matchConnection(m, 'test@example.com'); + }).not.toThrow(); + expect(result).toBeFalsy(); }); });