Skip to content

Commit

Permalink
Add test for relative url resolution on redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Soo committed Mar 26, 2020
1 parent cd55b2d commit 354e69e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions test/src/helpers/xhr_server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ class XhrServer
# Returns a HTTP redirect. Used to test the redirection handling code.
@app.all '/_/redirect/:status/:next_page', (request, response) =>
response.statusCode = parseInt(request.params.status)
response.header 'Location',
"http://#{request.get('host')}/_/#{request.params.next_page}"
if request.query.relative
url = "/#{request.params.next_page}"
else
url = "http://#{request.get('host')}/_/#{request.params.next_page}"
response.header 'Location', url
body = "<p>This is supposed to have a redirect link</p>"
response.header 'Content-Type', 'text/html'
response.header 'Content-Length', body.length.toString()
Expand Down
7 changes: 7 additions & 0 deletions test/src/redirect_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ describe 'XMLHttpRequest', ->
done()
@xhr.send()

it 'resolves effective request uri for the next location', (done) ->
@xhr.open 'GET', 'http://localhost:8912/_/redirect/302/method?relative=true'
@xhr.onload = =>
expect(@xhr._url['href']).to.match(/http:\/\/localhost:8912\/method/)
done()
@xhr.send()

it 'persists custom request headers across redirects', (done) ->
@xhr.open 'GET', 'http://localhost:8912/_/redirect/302/headers'
@xhr.setRequestHeader 'X-Redirect-Test', 'should be preserved'
Expand Down

0 comments on commit 354e69e

Please sign in to comment.