mirror of
https://github.com/cypress-io/cypress.git
synced 2026-01-27 01:18:56 -06:00
fix(server): correctly redirect cy.visit when using HTTP POST (#8550)
Co-authored-by: Zach Bloomquist <github@chary.us>
This commit is contained in:
@@ -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 │
|
||||
@@ -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 - - -
|
||||
|
||||
|
||||
`
|
||||
|
||||
@@ -602,6 +602,7 @@ module.exports = function (options = {}) {
|
||||
|
||||
_.defaults(options, {
|
||||
headers: {},
|
||||
followAllRedirects: true,
|
||||
onBeforeReqInit (fn) {
|
||||
return fn()
|
||||
},
|
||||
|
||||
@@ -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(
|
||||
`\
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user