File: importPEM.cpp

package info (click to toggle)
xca 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,328 kB
  • sloc: cpp: 30,584; sh: 341; xml: 74; makefile: 56; python: 34
file content (61 lines) | stat: -rw-r--r-- 1,404 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* vi: set sw=4 ts=4:
 *
 * Copyright (C) 2023 Christian Hohnstaedt.
 *
 * All rights reserved.
 */

#include <QTest>

#include "widgets/MainWindow.h"
#include "ui_MainWindow.h"
#include "widgets/ImportMulti.h"
#include "ui_ImportMulti.h"

#include "lib/pki_multi.h"

#include "main.h"

void test_main::importPEM()
{
	try {

	ign_openssl_error();
	openDB();
	dbstatus();
	pki_multi *pem = new pki_multi();

	pem->fromPEMbyteArray(pemdata["Inter CA 1"].toUtf8(), QString());
	pem->fromPEMbyteArray(pemdata["Root CA"].toUtf8(), QString());

	// Enter a wrong password and then abort
	pwdialog->setExpectations(QList<pw_expect*>{
		new pw_expect("wrongPassword", pw_ok),
	});
	QVERIFY_EXCEPTION_THROWN(pem->fromPEMbyteArray(
				pemdata["Inter CA 1 EncKey"].toUtf8(), QString()), errorEx);


	// Enter a wrong password and then the correct one
	pwdialog->setExpectations(QList<pw_expect*>{
		new pw_expect("BadPassword", pw_ok),
		new pw_expect("pass", pw_ok),
	});
	pem->fromPEMbyteArray(pemdata["Inter CA 1 Key"].toUtf8(), QString());

	QCOMPARE(pem->failed_files.count(), 0);
	ImportMulti *dlg = new ImportMulti(mainwin);
	dlg->addItem(pem);

	dlg->show();
	Q_ASSERT(QTest::qWaitForWindowActive(dlg));
	dlg->on_butOk_clicked();

	delete dlg;
	QList<pki_base*> allitems = Store.getAll<pki_base>();
	QCOMPARE(allitems.count() , 3);
	} catch (...) {
		QVERIFY2(false, "Exception thrown");
	}
	dbstatus();
}