comparison ui/tests/certlistparsertest.cpp @ 351:ee59ab0eb7ff

Add test for Certificate::fromFile
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 10 Apr 2014 15:31:02 +0200
parents 6a7eb102716d
children f6ce186cebc2
comparison
equal deleted inserted replaced
350:8fb815b78742 351:ee59ab0eb7ff
141 QDir dataDir = QDir(SOURCE_DIR"/data/"); 141 QDir dataDir = QDir(SOURCE_DIR"/data/");
142 QString fileName = dataDir.absoluteFilePath(filename); 142 QString fileName = dataDir.absoluteFilePath(filename);
143 return new CertificateList(fileName.toLocal8Bit().data()); 143 return new CertificateList(fileName.toLocal8Bit().data());
144 } 144 }
145 145
146 void CertListTest::testCertificateFromFile()
147 {
148 QList<Certificate> result;
149
150 /* Real certificates in the wild */
151 result = Certificate::fromFileName(":/Intevation-Root-CA-2010.crt");
152 QVERIFY(result.size() == 1);
153 QVERIFY(result[0].isValid());
154 result = Certificate::fromFileName(":/Intevation-Root-CA-2010.der");
155 QVERIFY(result.size() == 1);
156 QVERIFY(result[0].isValid());
157
158 /* We can handle ECC keys */
159 result = Certificate::fromFileName(":/valid_ssl_bp.pem");
160 QVERIFY(result.size() == 1);
161 QVERIFY(result[0].isValid());
162
163 /* Basic stuff */
164 result = Certificate::fromFileName(":/valid_ssl_rsa.pem");
165 QVERIFY(result.size() == 1);
166 QVERIFY(result[0].isValid());
167
168 /* Multiple certs */
169 result = Certificate::fromFileName(":/import_test.pem");
170 QVERIFY(result.size() == 15);
171
172 QString lastCertB64;
173 foreach (const Certificate& cert, result) {
174 QVERIFY(cert.isValid());
175 /* Just to verify that it's not all the same */
176 QVERIFY(cert.base64Line() != lastCertB64);
177 lastCertB64 = cert.base64Line();
178 }
179
180 /* Some robustness */
181 QString fname = getRandomDataFile(MAX_LINE_LENGTH * MAX_LINES - 100);
182 result = Certificate::fromFileName(fname);
183 QVERIFY(QFile::remove(fname));
184 QVERIFY(result.isEmpty());
185 }
186
146 int main( int argc, char **argv ) 187 int main( int argc, char **argv )
147 { 188 {
148 CertListTest tc; 189 CertListTest tc;
149 return QTest::qExec( &tc, argc, argv ); 190 return QTest::qExec( &tc, argc, argv );
150 } 191 }

http://wald.intevation.org/projects/trustbridge/