-
Notifications
You must be signed in to change notification settings - Fork 3.4k
test: use @cypress/debugging-proxy to validate behavior for various proxy scenarios #31597
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ec03f1
use debugging proxy for various record scenarios
cacieprins 6c28cc4
rm unnecessary debug
cacieprins 0cf4da2
Merge branch 'develop' into system-test-record-through-proxy
cacieprins 6865d1f
Merge branch 'develop' into system-test-record-through-proxy
cacieprins 8d7c57c
Merge branch 'develop' into system-test-record-through-proxy
cacieprins f46646f
Apply suggestions from code review
cacieprins 2fd41bf
Merge branch 'develop' into system-test-record-through-proxy
cacieprins a185df0
Merge branch 'develop' into system-test-record-through-proxy
cacieprins 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,18 @@ | ||
| { | ||
| "development": { | ||
| "api_url": "http://localhost:1234/" | ||
| "preliminary_url": "http://localhost:1234/", | ||
| "primary_url": "http://localhost:1234/" | ||
| }, | ||
| "test": { | ||
| "api_url": "http://localhost:1234/" | ||
| "preliminary_url": "http://localhost:1234/", | ||
| "primary_url": "http://localhost:4321/" | ||
| }, | ||
| "staging": { | ||
| "api_url": "https://api-staging.cypress.io/" | ||
| "preliminary_url": "https://api-proxy-staging.cypress.io", | ||
| "primary_url": "https://api-staging.cypress.io/" | ||
| }, | ||
| "production": { | ||
| "api_url": "https://api.cypress.io/" | ||
| "preliminary_url": "https://api-proxy.cypress.io", | ||
| "primary_url": "https://api.cypress.io/" | ||
| } | ||
| } |
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
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
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
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,163 @@ | ||
| import DebugProxy from '@cypress/debugging-proxy' | ||
| import systemTests from '../lib/system-tests' | ||
| import { | ||
| createRoutes, | ||
| setupStubbedServer, | ||
| setupPrimaryAlternateStubbedServer as setupPreliminaryAlternateStubbedServer, | ||
| encryptBody, | ||
| } from '../lib/serverStub' | ||
| import { test as apiUrls } from '@packages/server/config/app.json' | ||
|
|
||
| describe('recording through proxy', () => { | ||
| let proxy: DebugProxy | ||
|
|
||
| const expectedPaths = [ | ||
| 'runs', | ||
| 'runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances', | ||
| 'instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/tests', | ||
| 'instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/results', | ||
| 'instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/artifacts', | ||
| 'instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/stdout', | ||
| 'runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances', | ||
| ] | ||
| const preliminaryHost = apiUrls.preliminary_url | ||
| const primaryHost = apiUrls.primary_url | ||
| const preliminaryPort = Number(new URL(apiUrls.preliminary_url).port) | ||
| const primaryPort = Number(new URL(apiUrls.primary_url).port) | ||
|
|
||
| function expectedUrls (host: typeof preliminaryHost | typeof primaryHost) { | ||
| return expectedPaths.map((path) => `${host}${path}`) | ||
| } | ||
|
|
||
| beforeEach(async () => { | ||
| proxy = new DebugProxy({ | ||
| host: 'localhost', | ||
| keepRequests: true, | ||
| }) | ||
|
|
||
| await proxy.start(3128) | ||
|
|
||
| process.env.DISABLE_API_RETRIES = 'true' | ||
| process.env.HTTP_PROXY = 'http://localhost:3128' | ||
| process.env.HTTP_PROXY_TARGET_FOR_ORIGIN_REQUESTS = 'http://localhost:3128' | ||
| process.env.NO_PROXY = '<-loopback>' | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await proxy.stop() | ||
| }) | ||
|
|
||
| describe('when the initial preflight is not proxied and returns the preliminary host on preflight', () => { | ||
| setupStubbedServer(createRoutes({ | ||
| sendPreflight: { | ||
| method: 'post', | ||
| url: '/preflight', | ||
| res: async (req, res) => { | ||
| const preflightResponse = { encrypt: true, apiUrl: preliminaryHost } | ||
|
|
||
| return res.json(await encryptBody(req, res, preflightResponse)) | ||
| }, | ||
| }, | ||
| })) | ||
|
|
||
| it('sends all api requests to the preliminary host', async function () { | ||
| await systemTests.exec(this, { | ||
| key: 'f858a2bc-b469-4e48-be67-0876339ee7e1', | ||
| configFile: 'cypress-with-project-id.config.js', | ||
| spec: 'record_pass*', | ||
| expectedExitCode: 0, | ||
| record: true, | ||
| }) | ||
|
|
||
| const proxiedUrls = proxy.getRequests().map(({ url }) => url) | ||
|
|
||
| expect(proxiedUrls).not.to.include(`${preliminaryHost}/preflight`) | ||
| expect(proxiedUrls).to.include.members(expectedUrls(preliminaryHost)) | ||
| }) | ||
| }) | ||
|
|
||
| describe('when the preliminary preflight is not proxied, and returns the primary host', () => { | ||
| setupPreliminaryAlternateStubbedServer([{ | ||
| routes: { | ||
| sendPreflight: { | ||
| method: 'post', | ||
| url: '/preflight', | ||
| res: async (req, res) => { | ||
| const preflightResponse = { encrypt: true, apiUrl: primaryHost } | ||
|
|
||
| return res.json(await encryptBody(req, res, preflightResponse)) | ||
| }, | ||
| }, | ||
| }, | ||
| port: 1234, | ||
| }, { | ||
| routes: createRoutes(), | ||
| port: 4321, | ||
| }]) | ||
|
|
||
| it('makes subsequent requests to the primary host', async function () { | ||
| await systemTests.exec(this, { | ||
| key: 'f858a2bc-b469-4e48-be67-0876339ee7e1', | ||
| configFile: 'cypress-with-project-id.config.js', | ||
| spec: 'record_pass*', | ||
| expectedExitCode: 0, | ||
| record: true, | ||
| }) | ||
|
|
||
| const proxiedUrls = proxy.getRequests().map(({ url }) => url) | ||
|
|
||
| expect(proxiedUrls).not.to.include(`${preliminaryHost}/preflight`) | ||
|
|
||
| expect(proxy.getRequests().map(({ url }) => url)).to.include.members(expectedUrls(primaryHost)) | ||
| }) | ||
| }) | ||
|
|
||
| describe('when the preliminary preflight is not proxied and fails, a preflight is sent to the primary api host via the proxy.', () => { | ||
| let preliminaryHostPreflightCalled = false | ||
|
|
||
| setupPreliminaryAlternateStubbedServer( | ||
| [ | ||
| { | ||
| routes: { | ||
| sendPreflight: { | ||
| method: 'post', | ||
| url: '/preflight', | ||
| res: async (req, res) => { | ||
| preliminaryHostPreflightCalled = true | ||
|
|
||
| return res.status(500).send('Server Error') | ||
| }, | ||
| }, | ||
| }, | ||
| port: preliminaryPort, | ||
| }, | ||
| { | ||
| routes: createRoutes(), | ||
| port: primaryPort, | ||
| }, | ||
| ], | ||
| ) | ||
|
|
||
| beforeEach(() => { | ||
| preliminaryHostPreflightCalled = false | ||
| }) | ||
|
|
||
| it('makes all subsequent requests to the primary host through the proxy', async function () { | ||
| await systemTests.exec(this, { | ||
| key: 'f858a2bc-b469-4e48-be67-0876339ee7e1', | ||
| configFile: 'cypress-with-project-id.config.js', | ||
| spec: 'record_pass*', | ||
| expectedExitCode: 0, | ||
| record: true, | ||
| }) | ||
|
|
||
| expect(preliminaryHostPreflightCalled).to.be.true | ||
|
|
||
| const proxiedUrls = proxy.getRequests().map(({ url }) => url) | ||
|
|
||
| expect(proxiedUrls).not.to.include(`${preliminaryHost}/preflight`) | ||
| expect(proxiedUrls).not.to.include.members(expectedUrls(preliminaryHost)) | ||
| expect(proxiedUrls).to.include.members(expectedUrls(primaryHost)) | ||
| }) | ||
| }) | ||
| }) |
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.