Skip to content

Commit

Permalink
fix: misc cy origin cleanup (#23914)
Browse files Browse the repository at this point in the history
* chore: remove cannot_visit_previous_origin error message as it is no longer used

* fix: wrap MaybeEndRequestWithBufferedResponse fullCrossOrigin check around feature flag
  • Loading branch information
AtofStryker authored Sep 21, 2022
1 parent 085bc1e commit cd2fde9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
16 changes: 0 additions & 16 deletions packages/driver/src/cypress/error_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1250,22 +1250,6 @@ export default {
docsUrl: 'https://on.cypress.io/session-api',
},
},
cannot_visit_previous_origin (args) {
return {
message: stripIndent`\
${cmd('visit')} failed because you are attempting to visit a URL from a previous origin inside of ${cmd('origin')}.
Instead of placing the ${cmd('visit')} inside of ${cmd('origin')}, the ${cmd('visit')} should be placed outside of the ${cmd('origin')} block.
\`<commands targeting ${args.attemptedUrl.origin} go here>\`
\`cy.origin('${args.previousUrl.originPolicy}', () => {\`
\` <commands targeting ${args.previousUrl.origin} go here>\`
\`})\`
\`cy.visit('${args.originalUrl}')\``,
}
},
aut_error_prior_to_spec_bridge_attach ({ args }) {
const { errorMessage, autLocation } = args

Expand Down
2 changes: 1 addition & 1 deletion packages/proxy/lib/http/request-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const MaybeEndRequestWithBufferedResponse: RequestMiddleware = function () {

if (buffer) {
this.debug('ending request with buffered response')
this.res.wantsInjection = buffer.isCrossOrigin ? 'fullCrossOrigin' : 'full'
this.res.wantsInjection = this.config.experimentalSessionAndOrigin && buffer.isCrossOrigin ? 'fullCrossOrigin' : 'full'

return this.onResponse(buffer.response, buffer.stream)
}
Expand Down
28 changes: 27 additions & 1 deletion packages/proxy/test/unit/http/request-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('http/request-middleware', () => {
})
})

it('sets wantsInjection to fullCrossOrigin when a cross origin request is buffered', async () => {
it('sets wantsInjection to fullCrossOrigin when a cross origin request is buffered and experimentalSessionAndOrigin=true', async () => {
const buffers = new HttpBuffers()
const buffer = { url: 'https://www.cypress.io/', isCrossOrigin: true } as HttpBuffer

Expand All @@ -341,6 +341,9 @@ describe('http/request-middleware', () => {
req: {
proxiedUrl: 'https://www.cypress.io/',
},
config: {
experimentalSessionAndOrigin: true,
},
res: {} as Partial<CypressOutgoingResponse>,
}

Expand All @@ -350,6 +353,29 @@ describe('http/request-middleware', () => {
})
})

it('sets wantsInjection to full when a cross origin request is buffered and experimentalSessionAndOrigin=false', async () => {
const buffers = new HttpBuffers()
const buffer = { url: 'https://www.cypress.io/', isCrossOrigin: true } as HttpBuffer

buffers.set(buffer)

const ctx = {
buffers,
req: {
proxiedUrl: 'https://www.cypress.io/',
},
config: {
experimentalSessionAndOrigin: false,
},
res: {} as Partial<CypressOutgoingResponse>,
}

await testMiddleware([MaybeEndRequestWithBufferedResponse], ctx)
.then(() => {
expect(ctx.res.wantsInjection).to.equal('full')
})
})

it('wantsInjection is not set when the request is not buffered', async () => {
const buffers = new HttpBuffers()
const buffer = { url: 'https://www.cypress.io/', isCrossOrigin: true } as HttpBuffer
Expand Down

6 comments on commit cd2fde9

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cd2fde9 Sep 21, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/linux-x64/develop-cd2fde90474dd4cb00fbb96a17fbaab94d8290d3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cd2fde9 Sep 21, 2022

Choose a reason for hiding this comment

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

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/linux-arm64/develop-cd2fde90474dd4cb00fbb96a17fbaab94d8290d3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cd2fde9 Sep 21, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/darwin-arm64/develop-cd2fde90474dd4cb00fbb96a17fbaab94d8290d3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cd2fde9 Sep 21, 2022

Choose a reason for hiding this comment

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

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/darwin-x64/develop-cd2fde90474dd4cb00fbb96a17fbaab94d8290d3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cd2fde9 Sep 21, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/win32-x64/develop-cd2fde90474dd4cb00fbb96a17fbaab94d8290d3/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on cd2fde9 Sep 22, 2022

Choose a reason for hiding this comment

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

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.9.0/win32-x64/develop-cd2fde90474dd4cb00fbb96a17fbaab94d8290d3/cypress.tgz

Please sign in to comment.