test: add integration tests for CORS with various origin configurations#402
Open
mahmoodhamdi wants to merge 1 commit intoexpressjs:masterfrom
Open
Conversation
Add Express integration tests (via supertest) covering scenarios not exercised by the existing example-app tests: - Specific origin with credentials, exposed headers, and maxAge - Preflight with specific origin and credentials - Dynamic origin function allowing/rejecting origins - Regex origin matching and rejection - Array of mixed string and regex origins Also fix deprecated app.del() to app.delete() in the pre-flight README example.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Added 10 Express integration tests (via supertest) covering CORS scenarios not exercised by the existing
example-apptests, and fixed deprecatedapp.del()usage in the README.Why
The existing integration tests in
test/example-app.jsonly test default CORS (wildcard origin). Real-world usage often involves specific origins, dynamic origin functions, regex patterns, and credentials — none of which had integration-level coverage through Express.While working with
corsin my Express APIs, I noticed these gaps and wrote tests that validate the middleware works correctly end-to-end in an Express app for:Specific origin with credentials:
Access-Control-Allow-Origin,Access-Control-Allow-Credentials,Access-Control-Expose-Headers, andVaryheaders on actual requestsAccess-Control-Max-Ageand credentialsDynamic origin function:
Access-Control-Allow-Originheader)Regex origin:
Array of origins (mixed string + regex):
Docs fix:
app.del()toapp.delete()in the pre-flight example —app.del()is a deprecated alias removed in Express 5Testing