Skip to content

Commit

Permalink
fix(server): correctly redirect cy.visit when using HTTP POST (#8550)
Browse files Browse the repository at this point in the history
Co-authored-by: Zach Bloomquist <github@chary.us>
  • Loading branch information
fras2560 and flotwig authored Sep 11, 2020
1 parent 7619aab commit 1244dd1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
16 changes: 11 additions & 5 deletions packages/server/__snapshots__/6_visit_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ exports['e2e visit / low response timeout / passes'] = `
✓ passes
issue #309: request accept header not set
✓ sets accept header to text/html,*/*
can be redirected from initial POST
✓ with status code 307
✓ with status code 301
✓ with status code 302
✓ with status code 303
✓ with status code 308
13 passing
18 passing
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 13
│ Passing: 13
│ Tests: 18
│ Passing: 18
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
Expand All @@ -68,9 +74,9 @@ exports['e2e visit / low response timeout / passes'] = `
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ visit_spec.coffee XX:XX 13 13 - - - │
│ ✔ visit_spec.coffee XX:XX 18 18 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 13 13 - - -
✔ All specs passed! XX:XX 18 18 - - -
`
Expand Down
1 change: 1 addition & 0 deletions packages/server/lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ module.exports = function (options = {}) {

_.defaults(options, {
headers: {},
followAllRedirects: true,
onBeforeReqInit (fn) {
return fn()
},
Expand Down
19 changes: 18 additions & 1 deletion packages/server/test/e2e/6_visit_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const onServer = function (app) {
})

// https://github.com/cypress-io/cypress/issues/5602
return app.get('/invalid-header-char', (req, res) => {
app.get('/invalid-header-char', (req, res) => {
// express/node may interfere if we just use res.setHeader
res.connection.write(
`\
Expand All @@ -96,6 +96,23 @@ foo\

return res.connection.end()
})

app.post('/redirect-post', (req, res) => {
const code = Number(req.query.code)

if (!code) {
return res.end('no code supplied')
}

// 307 keeps the same HTTP method
const url = code === 307 ? '/post-only' : '/timeout'

res.redirect(code, url)
})

app.post('/post-only', (req, res) => {
res.end('<html>it posted</html>')
})
}

describe('e2e visit', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,27 @@ describe "visits", ->

expect(headers.accept).to.eq("text/html,*/*")
expect(headers.host).to.eq("localhost:3434")

# https://github.com/cypress-io/cypress/issues/8544
context "can be redirected from initial POST", ->
it "with status code 307", ->
# 307 is slightly different, the request method must not change
cy.visit({
url: "http://localhost:3434/redirect-post?code",
qs: {
code: 307
},
method: 'POST'
})
.contains('it posted')

[301, 302, 303, 308].forEach (code) ->
it "with status code #{code}", ->
cy.visit({
url: "http://localhost:3434/redirect-post?code",
qs: {
code
},
method: 'POST'
})
.contains('timeout: 0')

4 comments on commit 1244dd1

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1244dd1 Sep 11, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/linux-x64/circle-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/circle-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1244dd1 Sep 11, 2020

Choose a reason for hiding this comment

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

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

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-x64/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1244dd1 Sep 11, 2020

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/win32-ia32/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip npm install https://cdn.cypress.io/beta/npm/5.2.0/appveyor-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1244dd1 Sep 11, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/5.2.0/darwin-x64/circle-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.zip
npm install https://cdn.cypress.io/beta/npm/5.2.0/circle-develop-1244dd136965bf64235aef087f98e9530b5af3d7/cypress.tgz

Please sign in to comment.