Mercurial > trustbridge
annotate ui/tests/downloadertest.cpp @ 1342:dab626e44347
(issue172) Document polarssl 1.3.9 usage
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 28 Oct 2014 11:11:27 +0100 |
parents | 508c96e72f62 |
children |
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[] = { |
1088
508c96e72f62
(issue124) Switch server URL and remove some RELEASE_BUILD options
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1058
diff
changeset
|
152 TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256, |
999
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
153 0 |
daa9448b64f5
(issue90) Use certificate pinning and forced ciphersuites for curl
Andre Heinecke <andre.heinecke@intevation.de>
parents:
994
diff
changeset
|
154 }; |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
155 |
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
|
156 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
|
157 { |
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 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
|
159 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
|
160 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
|
161 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
|
162 QDateTime::fromString("2010", "YYYY"), |
1088
508c96e72f62
(issue124) Switch server URL and remove some RELEASE_BUILD options
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1058
diff
changeset
|
163 "/development/TrustBridge-development.exe", |
508c96e72f62
(issue124) Switch server URL and remove some RELEASE_BUILD options
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1058
diff
changeset
|
164 "/development/zertifikatsliste.txt"); |
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
|
165 |
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 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
|
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 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
|
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 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
|
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 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
|
173 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
|
174 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
|
175 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
|
176 } |
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 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
|
178 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
|
179 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
|
180 |
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 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
|
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 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
|
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 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
|
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 |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
188 void DownloaderTest::testNewSoftware() |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
189 { |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
190 QFile validCert(QString::fromLatin1(SOURCE_DIR) + |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
191 "/data/valid_ssl_bp.pem"); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
192 validCert.open(QIODevice::ReadOnly); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
193 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
194 Downloader* downloader = new Downloader(this, |
910
eaed02defe6a
More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
404
diff
changeset
|
195 QString::fromLatin1("https://127.0.0.1:44443"), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
196 validCert.readAll(), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
197 QDateTime::fromString("2010", "YYYY"), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
198 QDateTime::currentDateTime(), |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
199 "/" + garbageInfo.fileName(), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
200 "/list-valid.txt"); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
201 validCert.close(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
202 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
203 SETUP_SPY |
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 connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
206 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
207 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
208 downloader->start(); |
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 int waited = 0; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
211 while (newSoftwareAvailable.count() == 0 && |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
212 errors.count() == 0 && waited < 20) { |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
213 QTest::qWait(200); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
214 waited++; |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
215 } |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
216 QVERIFY(waited != 20); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
217 QVERIFY(newListAvailable.count() == 0); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
218 QVERIFY(newSoftwareAvailable.count() == 1); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
219 QVERIFY(errors.count() == 0); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
220 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
221 QList<QVariant> arguments = newSoftwareAvailable.takeFirst(); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
222 |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
223 QVERIFY(filesEqual(serverConfigDir.path() + "/" + garbageInfo.fileName(), |
55
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
224 arguments.at(0).toString())); |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
225 |
64200b011dfd
Add test for software download
Andre Heinecke <aheinecke@intevation.de>
parents:
52
diff
changeset
|
226 delete downloader; |
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 |
994
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
229 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
|
230 { |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
231 /* 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
|
232 * 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
|
233 * 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
|
234 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
|
235 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
|
236 QByteArray(), |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
237 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
|
238 QDateTime::fromString("2010", "YYYY"), |
1088
508c96e72f62
(issue124) Switch server URL and remove some RELEASE_BUILD options
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1058
diff
changeset
|
239 QString("/zertifikatsliste.txt"), |
508c96e72f62
(issue124) Switch server URL and remove some RELEASE_BUILD options
Andre Heinecke <andre.heinecke@intevation.de>
parents:
1058
diff
changeset
|
240 QString("/zertifikatsliste.txt")); |
994
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
241 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
242 SETUP_SPY |
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 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
|
245 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
|
246 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
247 downloader->start(); |
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 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
|
250 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
|
251 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
|
252 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
|
253 waited++; |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
254 } |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
255 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
|
256 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
|
257 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
|
258 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
|
259 |
8fb1b912fd8e
Add test using the default download server used by the software
Andre Heinecke <andre.heinecke@intevation.de>
parents:
990
diff
changeset
|
260 delete downloader; |
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 |
43 | 263 void DownloaderTest::testNewList() |
264 { | |
265 QFile validCert(QString::fromLatin1(SOURCE_DIR) + | |
266 "/data/valid_ssl_bp.pem"); | |
267 validCert.open(QIODevice::ReadOnly); | |
268 | |
269 Downloader* downloader = new Downloader(this, | |
910
eaed02defe6a
More SSLConnection refactoring. Fixes curl downloader.
Andre Heinecke <andre.heinecke@intevation.de>
parents:
404
diff
changeset
|
270 QString::fromLatin1("https://127.0.0.1:44443"), |
43 | 271 validCert.readAll(), |
272 QDateTime::currentDateTime(), // Last installed SW | |
273 QDateTime::fromString("2010", "YYYY"), | |
240
c05e126b0b9e
Fix downloadertest and factor out generating file input.
Andre Heinecke <aheinecke@intevation.de>
parents:
55
diff
changeset
|
274 "/" + garbageInfo.fileName(), |
46
d28e2624c1d5
Reset connection before the next request.
Andre Heinecke <aheinecke@intevation.de>
parents:
45
diff
changeset
|
275 "/list-valid.txt"); |
43 | 276 validCert.close(); |
277 | |
51
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
278 SETUP_SPY |
78633b2b580c
Add macro for common signal setup tasks
Andre Heinecke <aheinecke@intevation.de>
parents:
50
diff
changeset
|
279 |
45
c6125d73faf4
Move SSLConnection into it's own class
Andre Heinecke <aheinecke@intevation.de>
parents:
43
diff
changeset
|
280 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
|
281 this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); |
43 | 282 |
283 downloader->start(); | |
284 | |
285 int waited = 0; | |
286 while (newListAvailable.count() == 0 && | |
287 errors.count() == 0 && waited < 20) { | |
48
3f8c2d46ded6
Add test for no connection handling
Andre Heinecke <aheinecke@intevation.de>
parents:
47
diff
changeset
|
288 QTest::qWait(200); |
43 | 289 waited++; |
290 } | |
291 QVERIFY(waited != 20); | |
292 QVERIFY(newListAvailable.count() == 1); | |
293 QVERIFY(newSoftwareAvailable.count() == 0); | |
294 QVERIFY(errors.count() == 0); | |
47
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
295 |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
296 QList<QVariant> arguments = newListAvailable.takeFirst(); |
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 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
|
299 arguments.at(0).toString())); |
7e37c6033c81
Verify that the downloaded file matches the served one
Andre Heinecke <aheinecke@intevation.de>
parents:
46
diff
changeset
|
300 |
43 | 301 delete downloader; |
302 } | |
303 | |
304 void DownloaderTest::cleanupTestCase() { | |
305 if (serverProc.state() == QProcess::Running) { | |
306 serverProc.close(); | |
307 } | |
308 } | |
309 | |
1058
fe2c6666b462
(issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents:
999
diff
changeset
|
310 bool g_debug = true; |
fe2c6666b462
(issue46) Add debug option to trustbridge client application
Andre Heinecke <andre.heinecke@intevation.de>
parents:
999
diff
changeset
|
311 |
43 | 312 QTEST_GUILESS_MAIN (DownloaderTest); |
313 |