teampoltergeist / poltergeist

A PhantomJS driver for Capybara

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Capybara::Poltergeist::StatusFailError on 302 redirects with port numbers

deepfryed opened this issue · comments

Flagging this while I continue investigation why integration specs fail in some cases with 302s on version 1.16.0

Meta

Poltergeist Version:
1.16.0

Phantomjs version
2.1.1

Expected Behavior

Redirect successfully to location

Actual Behavior

Looks like Phantomjs error but perhaps need to be handled in browser.js

Steps to reproduce

Ruby test server

#!/usr/bin/env ruby

# To run: ruby server.rb

require 'socket'

header, body = DATA.read.split(/[\r\n]{2}/, 2)

response = header.split(/[\r\n]/).join("\r\n")
response << "\r\n\r\n"
response << body.split(/\n/).join("\n")

server = TCPServer.new('127.0.0.1', 64778)
server.listen(1024)

puts "listening ..."
loop do
  c = server.accept
  Thread.new { c.write(response); c.close }
end

__END__
HTTP/1.1 302 Found
Location: http://127.0.0.1:64778/login
Content-Type: text/html; charset=utf-8
Content-Length: 5
Cache-Control: no-cache
Date: Sun, 27 Aug 2017 23:10:13 GMT
Connection: Close

hello

Phantomjs test script

// To run: phantomjs get.js

var page = require('webpage').create();
page.open('http://127.0.0.1:64778/logout', function(status) {
  console.log("Status: " + status);
  phantom.exit();
});

Logs

$ curl -i http://127.0.0.1:64778/logout
HTTP/1.1 302 Found
Location: http://127.0.0.1:80/login
Content-Type: text/html; charset=utf-8
Content-Length: 5
Cache-Control: no-cache
Date: Sun, 27 Aug 2017 23:10:13 GMT
Connection: Close

hello

$ phantomjs get.js 
Status: success

$ curl -i http://127.0.0.1:64778/logout
HTTP/1.1 302 Found
Location: http://127.0.0.1:64778/login
Content-Type: text/html; charset=utf-8
Content-Length: 5
Cache-Control: no-cache
Date: Sun, 27 Aug 2017 23:10:13 GMT
Connection: Close

hello

$ phantomjs get.js 
Status: fail

Failure

It seems like Phantomjs is unable to handle redirect to a non-standard ports out of the box. Might need to inject code to handle this, but not sure at what stage.

https://github.com/teampoltergeist/poltergeist/blob/master/lib/capybara/poltergeist/client/compiled/browser.js#L138

Barking up the wrong tree. This was an infinite redirect error, I'll have to look elsewhere to see what's failing.

Looks like some sort of concurrency issue that's fixed by using thin instead of webrick for capybara - error which might be been masked until we upgraded to poltergeist 1.1.6.0