Permalink
Browse files

Move to driver_spec, use rack app.

  • Loading branch information...
1 parent ec0c23a commit eee6437a0db5292fc6a9566ea18d6c9f415c3418 @halogenandtoast halogenandtoast committed Jun 15, 2012
Showing with 29 additions and 78 deletions.
  1. +0 −74 spec/browser_spec.rb
  2. +28 −0 spec/driver_spec.rb
  3. +1 −4 src/NetworkAccessManager.cpp
View
@@ -134,80 +134,6 @@
end
end
- describe "basic auth" do
- before do
- @host = '127.0.0.1'
- @user = 'user'
- @password = 'password'
-
- @server = TCPServer.new(@host, 0)
- @port = @server.addr[1]
- @server_thread = Thread.new(@server) do |serv|
- while conn = serv.accept do
- begin
- request = []
- until (line = conn.readline.strip).empty?
- request << line
- end
-
- request_lines = request.dup
- response = request_lines.shift
- @headers = {}
- while (line = request_lines.shift || "").strip != ""
- header, value = line.split(": ", 2)
- @headers[header] = value
- end
-
- if @headers["Authorization"]
- html = "<html><head></head><body>Ok</body></html>"
- conn.write "HTTP/1.1 200 OK\r\n"
- conn.write "Content-Type:text/html\r\n"
- conn.write "Content-Length: %i\r\n" % html.size
- conn.write "\r\n"
- conn.write html
- conn.write "\r\n\r\n"
- conn.close
- else
- html = <<-HTML
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
- <HTML>
- <HEAD>
- <TITLE>Error</TITLE>
- <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
- </HEAD>
- <BODY><H1>401 Unauthorized.</H1></BODY>
- </HTML>
- HTML
-
- conn.write "HTTP/1.1 401 Authorization Required\r\n"
- conn.write "Content-Type:text/html\r\n"
- conn.write "Content-Length: %i\r\n" % html.size
- conn.write %{WWW-Authenticate: Basic realm="Secure Area"\r\n}
- conn.write "\r\n"
- conn.write html
- conn.write "\r\n\r\n"
- conn.close
- end
- rescue Exception => e
- $stdout.puts e.to_s
- end
- end
- end
- end
-
- after(:each) do
- @server_thread.kill
- @server.close
- end
-
- it "can authenticate a request" do
- browser.authenticate('user', 'password')
- browser.visit("http://#{@host}:#{@port}/")
- @headers["Authorization"].should == "Basic "+Base64.encode64("user:password").strip
- end
- end
-
describe "forking", :skip_on_windows => true do
it "only shuts down the server from the main process" do
browser.reset!
View
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'capybara/driver/webkit'
+require 'base64'
describe Capybara::Driver::Webkit do
subject { Capybara::Driver::Webkit.new(@app, :browser => $webkit_browser) }
@@ -1549,4 +1550,31 @@ def which_for(character)
subject.source.should == "Hello\0World"
end
end
+
+ describe "basic auth" do
+ before(:all) do
+ @app = lambda do |env|
+ if env["REQUEST_PATH"] == "/hello/world"
+ [200, {"Content-Type" => "text/html", "Content-Length" => "0"}, [""]]
+ else
+ if env["HTTP_AUTHORIZATION"]
+ header = env["HTTP_AUTHORIZATION"]
+ [200, {"Content-Type" => "text/html", "Content-Length" => header.length.to_s}, [header]]
+ else
+ html = "401 Unauthorized."
+ [401,
+ {"Content-Type" => "text/html", "Content-Length" => html.length.to_s, "WWW-Authenticate" => 'Basic realm="Secure Area"'},
+ [html]]
+ end
+ end
+ end
+ end
+
+ it "can authenticate a request" do
+ subject.browser.authenticate('user', 'password')
+ subject.visit("/")
+ subject.body.should include("Basic "+Base64.encode64("user:password").strip)
+ end
+ end
+
end
@@ -37,12 +37,9 @@ void NetworkAccessManager::setPassword(const QString &password) {
m_password = password;
}
+
void NetworkAccessManager::provideAuthentication(QNetworkReply *reply, QAuthenticator *authenticator) {
Q_UNUSED(reply);
- std::ofstream out;
- out.open("/tmp/foo");
- out << "Setting: " << m_userName.toUtf8().constData() << ":" << m_password.toUtf8().constData();
- out.close();
authenticator->setUser(m_userName);
authenticator->setPassword(m_password);
}

0 comments on commit eee6437

Please sign in to comment.