Skip to content

Fix: TypeError in matchConnection for enterprise connections with no domains - #2736

Merged
ankita10119 merged 7 commits into
masterfrom
SDK-7978
Mar 17, 2026
Merged

ankita10119 merged 7 commits into
masterfrom
SDK-7978

Conversation

@ankita10119

@ankita10119 ankita10119 commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Added List() as a default fallback to x.get('domains')

return x.get('domains', List()).contains(target);

This returns an empty Immutable List when domains is absent, making .contains() return false safely instead of throwing.

References

Closes #2733

Testing

Manually ran a unit test (matchConnection.test.js) against the fix to verify the exact regression scenario:

  • Mocked core/index.connections to return a samlp enterprise connection with no domains field - replicating what the tenant API returns when no domains are configured on the connection
  • Called matchConnection with a valid email and asserted it does not throw

We wrote a test to reproduce the issue. Without the fix applied, the test throws TypeError: Cannot read properties of undefined (reading ‘contains’). With the fix, it passes cleanly.

Checklist

@ankita10119
ankita10119 requested a review from a team as a code owner March 9, 2026 18:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime TypeError in matchConnection when an enterprise connection payload omits the domains field (as can happen when no domains are configured), ensuring the lookup safely returns no match instead of throwing.

Changes:

  • Default domains to an empty Immutable List() before calling .contains().
  • Add a regression unit test covering the “enterprise connection with no domains” scenario.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/connection/enterprise.js Prevents .contains() from being called on undefined by providing an empty List() fallback for missing domains.
src/__tests__/connection/enterprise/matchConnection.test.js Adds a Jest regression test verifying matchConnection does not throw when domains is absent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/__tests__/connection/enterprise/matchConnection.test.js Outdated
Comment thread src/connection/enterprise.js
Refactor test to capture result of matchConnection call.
@ankita10119
ankita10119 merged commit a78660f into master Mar 17, 2026
5 checks passed
@ankita10119
ankita10119 deleted the SDK-7978 branch March 17, 2026 13:25
@ankita10119 ankita10119 mentioned this pull request Mar 19, 2026
ankita10119 added a commit that referenced this pull request Mar 19, 2026
**Fixed**
- Fix: TypeError when CordovaAuth0Plugin is not a constructor (auth0-js
9.30.1+) [\#2742](#2742)
([ankita10119](https://github.com/ankita10119))
- Fix: TypeError in matchConnection for enterprise connections with no
domains [\#2736](#2736)
([ankita10119](https://github.com/ankita10119))
ankita10119 added a commit that referenced this pull request Aug 17, 2026
…D screen (#2841)

### Changes

`connection/enterprise.js`
- `matchConnection`: added null guard on x.get('domains') before calling
`.contains()` - prevents a crash when a connection has no domains
configured
- `findADConnectionWithoutDomain`: same null guard before calling
`.isEmpty()`

 ` connection/enterprise/hrd_screen.jsx`
- Changed `domain !== null `to `domain` && `domain.trim()` - empty or
whitespace-only domain strings now fall back to the generic login
instructions instead of interpolating a blank value into the enterprise
instructions string

### References

- #2736 - "Fix: TypeError in matchConnection for enterprise connections
with no domains" (merged Mar 17, 2026, closes #2733)
- #2758 - "Fix: TypeError in matchConnection and
findADConnectionWithoutDomain for null/undefined domains" (merged Apr 1,
2026, closes #2749)

### Testing

* [ ] This change adds unit test coverage
* [ ] This change adds integration test coverage
* [ ] This change has been tested on the latest version of the
platform/language

New test file `matchConnection.test.js` covers:
  - Matching a connection by email domain
  - No match when domain differs
  - No throw when a connection has null domains
  - Returns false for an email with no domain part

`hrd_screen.test.js` adds two new cases:
  - Empty string domain falls back to generic instructions
  - Whitespace-only domain falls back to generic instructions

  All 407 tests pass.

### Checklist

* [ ] I have read the [Auth0 general contribution
guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
* [ ] I have read the [Auth0 Code of
Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
* [ ] All code quality tools/guidelines have been run/followed
* [ ] All relevant assets have been compiled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error thrown for enterprise connection with no domains configured

3 participants