Switch ignore ssl from a command-line flag to a server command
This commit is contained in:
parent
a0fb662773
commit
4ca10d29ed
|
@ -22,8 +22,8 @@ class Capybara::Driver::Webkit
|
|||
@options = options
|
||||
@rack_server = Capybara::Server.new(@app)
|
||||
@rack_server.boot if Capybara.run_server
|
||||
@browser = options[:browser] || Browser.new(
|
||||
:ignore_ssl_errors => options[:ignore_ssl_errors])
|
||||
@browser = options[:browser] || Browser.new
|
||||
@browser.ignore_ssl_errors if options[:ignore_ssl_errors]
|
||||
end
|
||||
|
||||
def current_url
|
||||
|
|
|
@ -12,7 +12,6 @@ class Capybara::Driver::Webkit
|
|||
@stdout = options.has_key?(:stdout) ?
|
||||
options[:stdout] :
|
||||
$stdout
|
||||
@ignore_ssl_errors = options[:ignore_ssl_errors]
|
||||
start_server
|
||||
connect
|
||||
end
|
||||
|
@ -84,6 +83,10 @@ class Capybara::Driver::Webkit
|
|||
end
|
||||
end
|
||||
|
||||
def ignore_ssl_errors
|
||||
command("IgnoreSslErrors")
|
||||
end
|
||||
|
||||
def command(name, *args)
|
||||
@socket.puts name
|
||||
@socket.puts args.size
|
||||
|
@ -170,7 +173,6 @@ class Capybara::Driver::Webkit
|
|||
|
||||
def server_pipe_and_pid(server_path)
|
||||
cmdline = [server_path]
|
||||
cmdline << "--ignore-ssl-errors" if @ignore_ssl_errors
|
||||
pipe = IO.popen(cmdline.join(" "))
|
||||
[pipe, pipe.pid]
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe Capybara::Driver::Webkit::Browser do
|
|||
|
||||
let(:browser) { Capybara::Driver::Webkit::Browser.new }
|
||||
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
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "RequestedUrl.h"
|
||||
#include "CurrentUrl.h"
|
||||
#include "ResizeWindow.h"
|
||||
#include "IgnoreSslErrors.h"
|
||||
|
||||
CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent) {
|
||||
m_page = page;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
@ -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();
|
||||
};
|
||||
|
|
@ -4,10 +4,9 @@
|
|||
|
||||
#include <QTcpServer>
|
||||
|
||||
Server::Server(QObject *parent, bool ignoreSslErrors) : QObject(parent) {
|
||||
Server::Server(QObject *parent) : QObject(parent) {
|
||||
m_tcp_server = new QTcpServer(this);
|
||||
m_page = new WebPage(this);
|
||||
m_page->setIgnoreSslErrors(ignoreSslErrors);
|
||||
}
|
||||
|
||||
bool Server::start() {
|
||||
|
|
|
@ -7,7 +7,7 @@ class Server : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Server(QObject *parent, bool ignoreSslErrors);
|
||||
Server(QObject *parent);
|
||||
bool start();
|
||||
quint16 server_port() const;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) {
|
|||
setUserStylesheet();
|
||||
|
||||
m_loading = false;
|
||||
m_ignoreSslErrors = false;
|
||||
this->setCustomNetworkAccessManager();
|
||||
|
||||
connect(this, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
|
||||
|
@ -33,7 +34,8 @@ void WebPage::setCustomNetworkAccessManager() {
|
|||
manager->setCookieJar(new NetworkCookieJar());
|
||||
this->setNetworkAccessManager(manager);
|
||||
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() {
|
||||
|
@ -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)
|
||||
reply->ignoreSslErrors(errors);
|
||||
}
|
||||
|
||||
void WebPage::setIgnoreSslErrors(bool ignore) {
|
||||
m_ignoreSslErrors = ignore;
|
||||
void WebPage::ignoreSslErrors() {
|
||||
m_ignoreSslErrors = true;
|
||||
}
|
||||
|
||||
bool WebPage::ignoreSslErrors() {
|
||||
return m_ignoreSslErrors;
|
||||
}
|
||||
|
||||
|
||||
int WebPage::getLastStatus() {
|
||||
return m_lastStatus;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,7 @@ class WebPage : public QWebPage {
|
|||
void setCustomNetworkAccessManager();
|
||||
bool render(const QString &fileName);
|
||||
virtual bool extension (Extension extension, const ExtensionOption *option=0, ExtensionReturn *output=0);
|
||||
void setIgnoreSslErrors(bool ignore);
|
||||
bool ignoreSslErrors();
|
||||
void ignoreSslErrors();
|
||||
QString consoleMessages();
|
||||
void resetConsoleMessages();
|
||||
void resetWindowSize();
|
||||
|
@ -30,7 +29,7 @@ class WebPage : public QWebPage {
|
|||
QString pageHeaders();
|
||||
void frameCreated(QWebFrame *);
|
||||
void replyFinished(QNetworkReply *reply);
|
||||
void ignoreSslErrors(QNetworkReply *reply, const QList<QSslError> &);
|
||||
void handleSslErrorsForReply(QNetworkReply *reply, const QList<QSslError> &);
|
||||
void handleUnsupportedContent(QNetworkReply *reply);
|
||||
|
||||
signals:
|
||||
|
|
|
@ -26,3 +26,4 @@ CHECK_COMMAND(ConsoleMessages)
|
|||
CHECK_COMMAND(RequestedUrl)
|
||||
CHECK_COMMAND(CurrentUrl)
|
||||
CHECK_COMMAND(ResizeWindow)
|
||||
CHECK_COMMAND(IgnoreSslErrors)
|
||||
|
|
|
@ -19,9 +19,8 @@ int main(int argc, char **argv) {
|
|||
app.setOrganizationDomain("thoughtbot.com");
|
||||
|
||||
QStringList args = app.arguments();
|
||||
bool ignoreSslErrors = args.contains("--ignore-ssl-errors");
|
||||
|
||||
Server server(0, ignoreSslErrors);
|
||||
Server server(0);
|
||||
|
||||
if (server.start()) {
|
||||
std::cout << "Capybara-webkit server started, listening on port: " << server.server_port() << std::endl;
|
||||
|
|
|
@ -2,6 +2,7 @@ TEMPLATE = app
|
|||
TARGET = webkit_server
|
||||
DESTDIR = .
|
||||
HEADERS = \
|
||||
IgnoreSslErrors.h \
|
||||
ResizeWindow.h \
|
||||
CurrentUrl.h \
|
||||
RequestedUrl.h \
|
||||
|
@ -39,6 +40,7 @@ HEADERS = \
|
|||
PageLoadingCommand.h \
|
||||
|
||||
SOURCES = \
|
||||
IgnoreSslErrors.cpp \
|
||||
ResizeWindow.cpp \
|
||||
CurrentUrl.cpp \
|
||||
RequestedUrl.cpp \
|
||||
|
|
Loading…
Reference in New Issue