Mercurial > trustbridge
annotate ui/tests/downloadertest.cpp @ 1047:f148149c9b09
Added tag 0.9.1 for changeset e10bc7372545
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 04 Sep 2014 16:15:11 +0200 |
parents | daa9448b64f5 |
children | fe2c6666b462 |
rev | line source |
---|---|
404 | 1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=2) | |
5 * and comes with ABSOLUTELY NO WARRANTY! | |
6 * See LICENSE.txt for details. | |
7 */ | |
43 | 8 #include "downloadertest.h" |
9 #include "downloader.h" | |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
10 #include "common.h" |
43 | 11 |
990
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
12 #include <polarssl/ssl_ciphersuites.h> |
43 | 13 #include <QTextStream> |
14 #include <QFile> | |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
15 #include <QVariant> |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
16 #include <unistd.h> |
43 | 17 |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
18 #define MAX_WAIT 20 |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
19 |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
20 #define SETUP_SPY \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
21 QSignalSpy newListAvailable(downloader, \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
22 SIGNAL(newListAvailable(const QString&, const QDateTime&))); \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
23 QSignalSpy newSoftwareAvailable(downloader, \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
24 SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&))); \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
25 QSignalSpy errors(downloader, SIGNAL(error(const QString &, \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
26 SSLConnection::ErrorCode))); \ |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
27 |
43 | 28 void DownloaderTest::startServer(QString additionalOptions) |
29 { | |
30 QFile serverConfig(serverConfigDir.path() + "/" + "hiawatha.conf"); | |
31 QFile mimeConfig(serverConfigDir.path() + "/" + "mimetype.conf"); | |
32 if (serverProc.state() == QProcess::Running) { | |
33 serverProc.close(); | |
34 } | |
35 serverConfig.open(QIODevice::WriteOnly); | |
36 mimeConfig.open(QIODevice::WriteOnly); | |
37 mimeConfig.close(); /* just an empty file */ | |
38 | |
39 QTextStream configStream(&serverConfig); | |
40 configStream << | |
41 "Binding { " << endl << | |
42 "Port = 44443 " << endl << | |
43 "SSLcertFile = " << SOURCE_DIR << | |
44 "/data/valid_ssl_bp_priv.pem" << endl << | |
45 "Interface = 127.0.0.1" << endl << | |
46 "}" << endl << | |
47 "Hostname = 127.0.0.1" << endl << | |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
48 "WebsiteRoot = " << serverConfigDir.path() << endl; |
43 | 49 configStream.flush(); |
50 | |
51 serverConfig.close(); | |
52 serverProc.start(); | |
53 serverProc.waitForStarted(); | |
54 } | |
55 | |
56 void DownloaderTest::initTestCase() { | |
57 QStringList arguments; | |
58 serverProc.setProgram(HIAWATHA_EXECUTABLE); | |
59 arguments << "-d" << "-c" << serverConfigDir.path(); | |
60 serverProc.setArguments(arguments); | |
45
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
61 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode"); |
43 | 62 startServer(); |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
63 garbageInfo = QFileInfo(getRandomDataFile(2 * 1024, serverConfigDir.path())); |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
64 QVERIFY(QFile::copy(QString::fromLocal8Bit(SOURCE_DIR"/data/list-valid.txt"), |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
65 serverConfigDir.path() + "/" + "list-valid.txt")); |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
66 |
43 | 67 QTest::qWait(1000); /* Wait for the server to settle */ |
68 } | |
69 | |
45
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
70 void DownloaderTest::downloaderError(const QString &message, SSLConnection::ErrorCode error) |
43 | 71 { |
72 qDebug() << "Downloader Error: " << error << " Msg: " << message; | |
73 } | |
74 | |
47
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
75 bool filesEqual(QString filename1, QString filename2) |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
76 { |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
77 bool retval = false; |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
78 QFile file1(filename1); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
79 QFile file2(filename2); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
80 file1.open(QIODevice::ReadOnly); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
81 file2.open(QIODevice::ReadOnly); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
82 |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
83 retval = (file1.readAll() == file2.readAll()); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
84 file1.close(); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
85 file2.close(); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
86 return retval; |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
87 } |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
88 |
52
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
89 void DownloaderTest::testOtherCertificate() |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
90 { |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
91 QFile otherCert(QString::fromLatin1(SOURCE_DIR) + |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
92 "/data/valid_ssl_rsa.pem"); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
93 otherCert.open(QIODevice::ReadOnly); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
94 |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
95 QFileInfo fi(getRandomDataFile(200)); |
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
96 |
52
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
97 Downloader* downloader = new Downloader(this, |
910
eaed02defe6a
More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
404
diff
changeset
|
98 QString::fromLatin1("https://127.0.0.1:44443"), |
52
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
99 otherCert.readAll(), |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
100 QDateTime::currentDateTime(), // Last installed SW |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
101 QDateTime::fromString("2010", "YYYY"), |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
102 "/" + garbageInfo.fileName(), |
52
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
103 "/list-valid.txt"); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
104 otherCert.close(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
105 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
106 SETUP_SPY |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
107 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
108 downloader->start(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
109 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
110 int waited = 0; |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
111 while (errors.count() == 0 && waited < MAX_WAIT) { |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
112 QTest::qWait(200); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
113 waited++; |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
114 } |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
115 QVERIFY(waited != MAX_WAIT); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
116 QVERIFY(newListAvailable.count() == 0); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
117 QVERIFY(newSoftwareAvailable.count() == 0); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
118 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
119 QList<QVariant> arguments = errors.takeFirst(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
120 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
121 int error = arguments.at(1).toInt(); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
122 |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
123 QVERIFY(error == SSLConnection::InvalidCertificate); |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
124 } |
d73a2f0170d4
Add test for another certificate
Andre Heinecke <aheinecke@intevation.de>
parents:
51
diff
changeset
|
125 |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
126 void DownloaderTest::testNoConnection() |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
127 { |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
128 Downloader* downloader = new Downloader(this, |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
129 QString::fromLatin1("https://foobar.intevation.de")); |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
130 |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
131 SETUP_SPY |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
132 |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
133 downloader->start(); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
134 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
135 int waited = 0; |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
136 while (newListAvailable.count() == 0 && |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
137 errors.count() == 0 && waited < MAX_WAIT) { |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
138 QTest::qWait(200); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
139 waited++; |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
140 } |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
141 QVERIFY(waited != MAX_WAIT); |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
142 QVERIFY(newListAvailable.count() == 0); |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
143 QVERIFY(newSoftwareAvailable.count() == 0); |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
144 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
145 QList<QVariant> arguments = errors.takeFirst(); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
146 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
147 int error = arguments.at(1).toInt(); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
148 |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
149 QVERIFY(error == SSLConnection::NoConnection); |
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
150 } |
999
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
151 static int accept_ciphers[] = { |
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
152 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, |
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
153 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, |
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
154 TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384, |
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
155 0 |
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
156 }; |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
157 |
990
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
158 void DownloaderTest::testForcedCiphers() |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
159 { |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
160 Downloader* downloader = new Downloader(this, |
999
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
161 QString::fromLatin1(SERVER_URL), |
990
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
162 QByteArray(), /* Use default testing certificate */ |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
163 QDateTime::currentDateTime(), |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
164 QDateTime::fromString("2010", "YYYY"), |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
165 "/users/aheinecke/development/TrustBridge-development.exe", |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
166 "/users/aheinecke/development/zertifikatsliste.txt"); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
167 |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
168 downloader->setCiphersuites(accept_ciphers); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
169 |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
170 SETUP_SPY |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
171 |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
172 downloader->start(); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
173 |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
174 int waited = 0; |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
175 while (errors.count() == 0 && waited < MAX_WAIT) { |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
176 QTest::qWait(200); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
177 waited++; |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
178 } |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
179 QVERIFY(waited != MAX_WAIT); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
180 QVERIFY(newListAvailable.count() == 0); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
181 QVERIFY(newSoftwareAvailable.count() == 0); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
182 |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
183 QList<QVariant> arguments = errors.takeFirst(); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
184 |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
185 int error = arguments.at(1).toInt(); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
186 |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
187 QVERIFY(error == SSLConnection::SSLHandshakeFailed); |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
188 } |
2949f1842955
(issue90) Add possibility to force cipher suites in bare connection and test for this
Andre Heinecke <andre.heinecke@intevation.de>
parents:
910
diff
changeset
|
189 |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
190 void DownloaderTest::testNewSoftware() |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
191 { |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
192 QFile validCert(QString::fromLatin1(SOURCE_DIR) + |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
193 "/data/valid_ssl_bp.pem"); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
194 validCert.open(QIODevice::ReadOnly); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
195 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
196 Downloader* downloader = new Downloader(this, |
910
eaed02defe6a
More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
404
diff
changeset
|
197 QString::fromLatin1("https://127.0.0.1:44443"), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
198 validCert.readAll(), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
199 QDateTime::fromString("2010", "YYYY"), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
200 QDateTime::currentDateTime(), |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
201 "/" + garbageInfo.fileName(), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
202 "/list-valid.txt"); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
203 validCert.close(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
204 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
205 SETUP_SPY |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
206 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
207 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
208 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
209 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
210 downloader->start(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
211 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
212 int waited = 0; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
213 while (newSoftwareAvailable.count() == 0 && |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
214 errors.count() == 0 && waited < 20) { |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
215 QTest::qWait(200); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
216 waited++; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
217 } |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
218 QVERIFY(waited != 20); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
219 QVERIFY(newListAvailable.count() == 0); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
220 QVERIFY(newSoftwareAvailable.count() == 1); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
221 QVERIFY(errors.count() == 0); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
222 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
223 QList<QVariant> arguments = newSoftwareAvailable.takeFirst(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
224 |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
225 QVERIFY(filesEqual(serverConfigDir.path() + "/" + garbageInfo.fileName(), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
226 arguments.at(0).toString())); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
227 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
228 delete downloader; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
229 } |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
230 |
994
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
231 void DownloaderTest::testDefaultUrl() |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
232 { |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
233 /* This test might fail if SERVER_URL is configured differently |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
234 * and needs to be adapted once there is a public download server. |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
235 * This test also needs internet connectivity. */ |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
236 Downloader* downloader = new Downloader(this, |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
237 QString::fromLatin1(SERVER_URL), |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
238 QByteArray(), |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
239 QDateTime::currentDateTime(), // Last installed SW |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
240 QDateTime::fromString("2010", "YYYY"), |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
241 QString("/users/aheinecke/zertifikatsliste.txt"), |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
242 QString("/users/aheinecke/zertifikatsliste.txt")); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
243 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
244 SETUP_SPY |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
245 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
246 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
247 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
248 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
249 downloader->start(); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
250 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
251 int waited = 0; |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
252 while (newListAvailable.count() == 0 && |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
253 errors.count() == 0 && waited < 20) { |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
254 QTest::qWait(200); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
255 waited++; |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
256 } |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
257 QVERIFY(waited != 20); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
258 QVERIFY(newListAvailable.count() == 1); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
259 QVERIFY(newSoftwareAvailable.count() == 0); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
260 QVERIFY(errors.count() == 0); |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
261 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
262 delete downloader; |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
263 } |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
264 |
43 | 265 void DownloaderTest::testNewList() |
266 { | |
267 QFile validCert(QString::fromLatin1(SOURCE_DIR) + | |
268 "/data/valid_ssl_bp.pem"); | |
269 validCert.open(QIODevice::ReadOnly); | |
270 | |
271 Downloader* downloader = new Downloader(this, | |
910
eaed02defe6a
More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
404
diff
changeset
|
272 QString::fromLatin1("https://127.0.0.1:44443"), |
43 | 273 validCert.readAll(), |
274 QDateTime::currentDateTime(), // Last installed SW | |
275 QDateTime::fromString("2010", "YYYY"), | |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
276 "/" + garbageInfo.fileName(), |
46
d28e2624c1d5
Reset connection before the next request.
Andre Heinecke <aheinecke@intevation.de>
parents:
45
diff
changeset
|
277 "/list-valid.txt"); |
43 | 278 validCert.close(); |
279 | |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
280 SETUP_SPY |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
281 |
45
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
282 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), |
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
283 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
43 | 284 |
285 downloader->start(); | |
286 | |
287 int waited = 0; | |
288 while (newListAvailable.count() == 0 && | |
289 errors.count() == 0 && waited < 20) { | |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
290 QTest::qWait(200); |
43 | 291 waited++; |
292 } | |
293 QVERIFY(waited != 20); | |
294 QVERIFY(newListAvailable.count() == 1); | |
295 QVERIFY(newSoftwareAvailable.count() == 0); | |
296 QVERIFY(errors.count() == 0); | |
47
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
297 |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
298 QList<QVariant> arguments = newListAvailable.takeFirst(); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
299 |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
300 QVERIFY(filesEqual(QString::fromLatin1(SOURCE_DIR) + "/data/list-valid.txt", |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
301 arguments.at(0).toString())); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
302 |
43 | 303 delete downloader; |
304 } | |
305 | |
306 void DownloaderTest::cleanupTestCase() { | |
307 if (serverProc.state() == QProcess::Running) { | |
308 serverProc.close(); | |
309 } | |
310 } | |
311 | |
312 QTEST_GUILESS_MAIN (DownloaderTest); | |
313 |