apollographql / apollographql/apollo-server
Add integration test suite for CORS requests
- Dominant language
- TypeScript
- Stars
- 14k
- Forks
- 2k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 2
Description
The [docs](https://www.apollographql.com/docs/apollo-server/security/cors#configuring-cors-options-for-apollo-server) mention that in v4 the user is responsible for setting up the CORS handler (and not the integration package). Nonetheless, it would be nice if there were integration tests that make sure that the recommended way is indeed working as intended.
For example, while developing https://github.com/apollo-server-integrations/apollo-server-integration-h3 I noticed that preflight requests shouldn't hit the apollo http handler (since it only accepts GET and POST). Thus, depending on the framework either the cors handler or the integration package should handle preflights.
https://github.com/JabRef/JabRefOnline/blob/214c8b991827a2b71f6c0dd675a12280e8b874a9/server/e2e.test.ts#L44-L78 can serve as a very simple starting point. The usage could look as follows:
```ts
defineIntegrationTestSuite(
async (
serverOptions: ApolloServerOptions,
testOptions?: CreateServerForIntegrationTestsOptions
) => {
// the usual stuff, setting up the apollo server as well as the app
if (testOptions.corsOptions) {
// add cors handler (depends on the framework of course), something like
app.use('/', cors(testOptions.corsOptions))
}
}
```
Contributor guide
Research direction
Start by reviewing the Apollo Server v4 CORS documentation and the existing integration test suites. Use the linked JabRef e2e test as a simple reference, then determine how each integration routes CORS preflight requests without sending them to the Apollo HTTP handler. Done means the recommended CORS setup is covered by integration tests, including preflight behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100