new command «certificate» to install CA certificate for SSL

master
Marc Wäckerlin 10 years ago
parent 953133e99e
commit 4e7cfafe77
  1. 34
      src/commands.hxx
  2. 7
      src/exceptions.hxx
  3. 39
      src/testgui.hxx

@ -1397,6 +1397,40 @@ class Timeout: public Command {
}; };
class Certificate: public Command {
public:
QString tag() const {
return "";
}
QString description() const {
return
"certificate <filename>"
"\n\n"
"Load a CA certificate that will be accepted on SSL connections.";
}
QString command() const {
return "";
}
std::shared_ptr<Command> parse(Script*, QString args,
QStringList&, int) {
std::shared_ptr<Certificate> cmd(new (Certificate));
cmd->_filename = args.trimmed();
return cmd;
}
bool execute(Script* script, QWebFrame*) {
Logger log(this, script);
QString filename(script->replacevars(_filename));
QFile cacertfile(filename);
if (!cacertfile.exists()) throw FileNotFound(filename);
QSslCertificate cacert(&cacertfile);
if (cacert.isNull()) throw NotACertificate(filename);
QSslSocket::addDefaultCaCertificate(cacert);
return true;
}
private:
QString _filename;
};
/* Template: /* Template:
class : public Command { class : public Command {
public: public:

@ -107,6 +107,13 @@ class FileNotFound: public TestFailed {
FileNotFound(QString arg): TestFailed("file not found: "+arg) {} FileNotFound(QString arg): TestFailed("file not found: "+arg) {}
}; };
class NotACertificate: public TestFailed {
public:
NotACertificate(QString arg):
TestFailed("file is not a certificate: "+arg) {
}
};
class NotUnattended: public TestFailed { class NotUnattended: public TestFailed {
public: public:
NotUnattended(): TestFailed("web page is not in unattended test mode") {} NotUnattended(): TestFailed("web page is not in unattended test mode") {}

@ -14,6 +14,7 @@
#include <QWebFrame> #include <QWebFrame>
#include <QWebElement> #include <QWebElement>
#include <QFileDialog> #include <QFileDialog>
#include <QScrollBar>
#include <QFile> #include <QFile>
#include <QMessageBox> #include <QMessageBox>
#include <ui_testgui.h> #include <ui_testgui.h>
@ -49,7 +50,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
void on__load_clicked() { void on__load_clicked() {
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("load "+_url->text()); appendCommand("load "+_url->text());
_web->load(_url->text()); _web->load(_url->text());
} }
void on__abort_clicked() { void on__abort_clicked() {
@ -109,6 +110,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
} }
void on__actionClear_triggered() { void on__actionClear_triggered() {
_testscript->clear(); _testscript->clear();
_log->clear();
_filename.clear(); _filename.clear();
_actionSave->setEnabled(false); _actionSave->setEnabled(false);
_actionRevertToSaved->setEnabled(false); _actionRevertToSaved->setEnabled(false);
@ -171,7 +173,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
void on__web_linkClicked(const QUrl& url) { void on__web_linkClicked(const QUrl& url) {
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("load "+url.url()); appendCommand("load "+url.url());
} }
void on__web_loadProgress(int progress) { void on__web_loadProgress(int progress) {
enterText(true); enterText(true);
@ -180,7 +182,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
void on__web_loadStarted() { void on__web_loadStarted() {
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("expect loadStarted"); appendCommand("expect loadStarted");
_progress->setValue(0); _progress->setValue(0);
_urlStack->setCurrentIndex(PROGRESS_VIEW); _urlStack->setCurrentIndex(PROGRESS_VIEW);
} }
@ -193,7 +195,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
void on__web_urlChanged(const QUrl& url) { void on__web_urlChanged(const QUrl& url) {
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("expect urlChanged "+url.url()); appendCommand("expect urlChanged "+url.url());
} }
void on__web_selectionChanged() { void on__web_selectionChanged() {
_source->setPlainText(_web->hasSelection() _source->setPlainText(_web->hasSelection()
@ -203,7 +205,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
void on__web_loadFinished(bool ok) { void on__web_loadFinished(bool ok) {
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("expect loadFinished " appendCommand("expect loadFinished "
+QString(ok?"true":"false")); +QString(ok?"true":"false"));
_urlStack->setCurrentIndex(URL_VIEW); _urlStack->setCurrentIndex(URL_VIEW);
on__web_selectionChanged(); on__web_selectionChanged();
@ -222,7 +224,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
void uploadFile(QString filename) { void uploadFile(QString filename) {
enterText(true); enterText(true);
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("upload "+filename); appendCommand("upload "+filename);
} }
void unsupportedContent(QNetworkReply* reply) { void unsupportedContent(QNetworkReply* reply) {
if (!_record->isChecked()) return; if (!_record->isChecked()) return;
@ -245,10 +247,19 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
} }
void downloadRequested(const QNetworkRequest&) { void downloadRequested(const QNetworkRequest&) {
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("download2"); appendCommand("download2");
} }
void logging(QString txt) { void logging(const QString& txt) {
_log->appendPlainText(txt); _log->appendPlainText(txt);
QScrollBar *vb(_log->verticalScrollBar());
if (!vb) return;
vb->setValue(vb->maximum());
}
void appendCommand(const QString& txt) {
_testscript->appendPlainText(txt);
QScrollBar *vb(_testscript->verticalScrollBar());
if (!vb) return;
vb->setValue(vb->maximum());
} }
protected: protected:
void closeEvent(QCloseEvent* event) { void closeEvent(QCloseEvent* event) {
@ -301,16 +312,16 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
.match(selected)); .match(selected));
if (mooCombo.hasMatch()) { if (mooCombo.hasMatch()) {
// special treatment for moo tools combobox (e.g. used in joomla) // special treatment for moo tools combobox (e.g. used in joomla)
_testscript->appendPlainText("click "+mooCombo.captured(1)+">a"); appendCommand("click "+mooCombo.captured(1)+">a");
_testscript->appendPlainText("sleep 1"); appendCommand("sleep 1");
} else if (mooComboItem.hasMatch()) { } else if (mooComboItem.hasMatch()) {
// special treatment for item in moo tools combobox // special treatment for item in moo tools combobox
_testscript->appendPlainText appendCommand
("click li.active-result[data-option-array-index=\"" ("click li.active-result[data-option-array-index=\""
+element.attribute("data-option-array-index")+"\"]"); +element.attribute("data-option-array-index")+"\"]");
_testscript->appendPlainText("sleep 1"); appendCommand("sleep 1");
} else { } else {
_testscript->appendPlainText("click "+selected); appendCommand("click "+selected);
} }
} }
} break; } break;
@ -425,7 +436,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
} }
void store(const QString& selector, QString code) { void store(const QString& selector, QString code) {
if (_record->isChecked()) if (_record->isChecked())
_testscript->appendPlainText("do "+selector+"\n " appendCommand("do "+selector+"\n "
+code.replace("\n", "\\n")); +code.replace("\n", "\\n"));
} }
void execute(const QString& selector, const QString& code) { void execute(const QString& selector, const QString& code) {

Loading…
Cancel
Save