1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00

Switch ignore ssl from a command-line flag to a server command

This commit is contained in:
Joe Ferris 2012-05-04 13:56:21 -04:00
parent a0fb662773
commit 4ca10d29ed
13 changed files with 46 additions and 22 deletions

View file

@ -22,8 +22,8 @@ class Capybara::Driver::Webkit
@options = options @options = options
@rack_server = Capybara::Server.new(@app) @rack_server = Capybara::Server.new(@app)
@rack_server.boot if Capybara.run_server @rack_server.boot if Capybara.run_server
@browser = options[:browser] || Browser.new( @browser = options[:browser] || Browser.new
:ignore_ssl_errors => options[:ignore_ssl_errors]) @browser.ignore_ssl_errors if options[:ignore_ssl_errors]
end end
def current_url def current_url

View file

@ -12,7 +12,6 @@ class Capybara::Driver::Webkit
@stdout = options.has_key?(:stdout) ? @stdout = options.has_key?(:stdout) ?
options[:stdout] : options[:stdout] :
$stdout $stdout
@ignore_ssl_errors = options[:ignore_ssl_errors]
start_server start_server
connect connect
end end
@ -84,6 +83,10 @@ class Capybara::Driver::Webkit
end end
end end
def ignore_ssl_errors
command("IgnoreSslErrors")
end
def command(name, *args) def command(name, *args)
@socket.puts name @socket.puts name
@socket.puts args.size @socket.puts args.size
@ -170,7 +173,6 @@ class Capybara::Driver::Webkit
def server_pipe_and_pid(server_path) def server_pipe_and_pid(server_path)
cmdline = [server_path] cmdline = [server_path]
cmdline << "--ignore-ssl-errors" if @ignore_ssl_errors
pipe = IO.popen(cmdline.join(" ")) pipe = IO.popen(cmdline.join(" "))
[pipe, pipe.pid] [pipe, pipe.pid]
end end

View file

@ -9,7 +9,7 @@ describe Capybara::Driver::Webkit::Browser do
let(:browser) { Capybara::Driver::Webkit::Browser.new } let(:browser) { Capybara::Driver::Webkit::Browser.new }
let(:browser_ignore_ssl_err) { let(:browser_ignore_ssl_err) {
Capybara::Driver::Webkit::Browser.new(:ignore_ssl_errors => true) Capybara::Driver::Webkit::Browser.new.tap { |browser| browser.ignore_ssl_errors }
} }
describe '#server_port' do describe '#server_port' do

View file

@ -23,6 +23,7 @@
#include "RequestedUrl.h" #include "RequestedUrl.h"
#include "CurrentUrl.h" #include "CurrentUrl.h"
#include "ResizeWindow.h" #include "ResizeWindow.h"
#include "IgnoreSslErrors.h"
CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) { CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) {
m_page = page; m_page = page;

12
src/IgnoreSslErrors.cpp Normal file
View file

@ -0,0 +1,12 @@
#include "IgnoreSslErrors.h"
#include "WebPage.h"
IgnoreSslErrors::IgnoreSslErrors(WebPage *page, QStringList &arguments, QObject *parent) :
Command(page, arguments, parent) {
}
void IgnoreSslErrors::start() {
page()->ignoreSslErrors();
emit finished(new Response(true));
}

12
src/IgnoreSslErrors.h Normal file
View file

@ -0,0 +1,12 @@
#include "Command.h"
class WebPage;
class IgnoreSslErrors : public Command {
Q_OBJECT
public:
IgnoreSslErrors(WebPage *page, QStringList &arguments, QObject *parent = 0);
virtual void start();
};

View file

@ -4,10 +4,9 @@
#include <QTcpServer> #include <QTcpServer>
Server::Server(QObject *parent, bool ignoreSslErrors) : QObject(parent) { Server::Server(QObject *parent) : QObject(parent) {
m_tcp_server = new QTcpServer(this); m_tcp_server = new QTcpServer(this);
m_page = new WebPage(this); m_page = new WebPage(this);
m_page->setIgnoreSslErrors(ignoreSslErrors);
} }
bool Server::start() { bool Server::start() {

View file

@ -7,7 +7,7 @@ class Server : public QObject {
Q_OBJECT Q_OBJECT
public: public:
Server(QObject *parent, bool ignoreSslErrors); Server(QObject *parent);
bool start(); bool start();
quint16 server_port() const; quint16 server_port() const;

View file

@ -12,6 +12,7 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
setUserStylesheet(); setUserStylesheet();
m_loading = false; m_loading = false;
m_ignoreSslErrors = false;
this->setCustomNetworkAccessManager(); this->setCustomNetworkAccessManager();
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted())); connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
@ -33,7 +34,8 @@ void WebPage::setCustomNetworkAccessManager() {
manager->setCookieJar(new NetworkCookieJar()); manager->setCookieJar(new NetworkCookieJar());
this->setNetworkAccessManager(manager); this->setNetworkAccessManager(manager);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *))); connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyFinished(QNetworkReply *)));
connect(manager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)), this, SLOT(ignoreSslErrors(QNetworkReply *, QList<QSslError>))); connect(manager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)),
this, SLOT(handleSslErrorsForReply(QNetworkReply *, QList<QSslError>)));
} }
void WebPage::loadJavascript() { void WebPage::loadJavascript() {
@ -205,20 +207,15 @@ void WebPage::replyFinished(QNetworkReply *reply) {
} }
} }
void WebPage::ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &errors) { void WebPage::handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &errors) {
if (m_ignoreSslErrors) if (m_ignoreSslErrors)
reply->ignoreSslErrors(errors); reply->ignoreSslErrors(errors);
} }
void WebPage::setIgnoreSslErrors(bool ignore) { void WebPage::ignoreSslErrors() {
m_ignoreSslErrors = ignore; m_ignoreSslErrors = true;
} }
bool WebPage::ignoreSslErrors() {
return m_ignoreSslErrors;
}
int WebPage::getLastStatus() { int WebPage::getLastStatus() {
return m_lastStatus; return m_lastStatus;
} }

View file

@ -15,8 +15,7 @@ class WebPage : public QWebPage {
void setCustomNetworkAccessManager(); void setCustomNetworkAccessManager();
bool render(const QString &fileName); bool render(const QString &fileName);
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0); virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
void setIgnoreSslErrors(bool ignore); void ignoreSslErrors();
bool ignoreSslErrors();
QString consoleMessages(); QString consoleMessages();
void resetConsoleMessages(); void resetConsoleMessages();
void resetWindowSize(); void resetWindowSize();
@ -30,7 +29,7 @@ class WebPage : public QWebPage {
QString pageHeaders(); QString pageHeaders();
void frameCreated(QWebFrame *); void frameCreated(QWebFrame *);
void replyFinished(QNetworkReply *reply); void replyFinished(QNetworkReply *reply);
void ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &); void handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &);
void handleUnsupportedContent(QNetworkReply *reply); void handleUnsupportedContent(QNetworkReply *reply);
signals: signals:

View file

@ -26,3 +26,4 @@ CHECK_COMMAND(ConsoleMessages)
CHECK_COMMAND(RequestedUrl) CHECK_COMMAND(RequestedUrl)
CHECK_COMMAND(CurrentUrl) CHECK_COMMAND(CurrentUrl)
CHECK_COMMAND(ResizeWindow) CHECK_COMMAND(ResizeWindow)
CHECK_COMMAND(IgnoreSslErrors)

View file

@ -19,9 +19,8 @@ int main(int argc, char **argv) {
app.setOrganizationDomain("thoughtbot.com"); app.setOrganizationDomain("thoughtbot.com");
QStringList args = app.arguments(); QStringList args = app.arguments();
bool ignoreSslErrors = args.contains("--ignore-ssl-errors");
Server server(0, ignoreSslErrors); Server server(0);
if (server.start()) { if (server.start()) {
std::cout << "Capybara-webkit server started, listening on port: " << server.server_port() << std::endl; std::cout << "Capybara-webkit server started, listening on port: " << server.server_port() << std::endl;

View file

@ -2,6 +2,7 @@ TEMPLATE = app
TARGET = webkit_server TARGET = webkit_server
DESTDIR = . DESTDIR = .
HEADERS = \ HEADERS = \
IgnoreSslErrors.h \
ResizeWindow.h \ ResizeWindow.h \
CurrentUrl.h \ CurrentUrl.h \
RequestedUrl.h \ RequestedUrl.h \
@ -39,6 +40,7 @@ HEADERS = \
PageLoadingCommand.h \ PageLoadingCommand.h \
SOURCES = \ SOURCES = \
IgnoreSslErrors.cpp \
ResizeWindow.cpp \ ResizeWindow.cpp \
CurrentUrl.cpp \ CurrentUrl.cpp \
RequestedUrl.cpp \ RequestedUrl.cpp \