mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
Add GUI test - testing the NewKey dialog
This commit is contained in:
parent
1599409b4f
commit
e3791e2609
@ -67,8 +67,12 @@ file(GLOB UI_FILES ${CMAKE_AUTOUIC_SEARCH_PATHS}/*.ui)
|
||||
configure_file(local.h.in local.h)
|
||||
|
||||
##### Libraries and executables
|
||||
add_executable(${CMAKE_PROJECT_NAME} img/imgres.qrc ${UI_FILES} ${PROJECT_BINARY_DIR}/local.h)
|
||||
add_library(xcalib STATIC)
|
||||
add_executable(${CMAKE_PROJECT_NAME} img/imgres.qrc lib/main.cpp
|
||||
${UI_FILES} ${PROJECT_BINARY_DIR}/local.h)
|
||||
add_executable(xcadoc ${PROJECT_BINARY_DIR}/local.h)
|
||||
add_executable(testxca img/imgres.qrc ${PROJECT_SOURCE_DIR}/lib/test_main.cpp
|
||||
${UI_FILES} ${PROJECT_BINARY_DIR}/local.h)
|
||||
|
||||
include_directories(${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR})
|
||||
|
||||
@ -105,16 +109,16 @@ if (NOT OPENSSL_ROOT_DIR)
|
||||
get_filename_component(OPENSSL_ROOT_DIR ${OPENSSL_INCLUDE_DIR} DIRECTORY)
|
||||
endif()
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
target_link_libraries(xcalib
|
||||
OpenSSL::Crypto
|
||||
${QT}::Widgets ${QT}::Core ${QT}::Sql ${QT}::Help
|
||||
${ASAN_LIB}
|
||||
)
|
||||
target_link_libraries(xcadoc
|
||||
OpenSSL::Crypto
|
||||
${QT}::Widgets ${QT}::Core ${QT}::Sql ${QT}::Help
|
||||
${ASAN_LIB}
|
||||
OpenSSL::Crypto ${QT}::Core ${ASAN_LIB}
|
||||
)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} ${ASAN_LIB} xcalib)
|
||||
target_link_libraries(testxca ${ASAN_LIB} ${QT}::Test xcalib)
|
||||
|
||||
if (APPLE)
|
||||
|
||||
@ -123,6 +127,9 @@ if (APPLE)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY}
|
||||
)
|
||||
target_link_libraries(testxca
|
||||
${IOKIT_LIBRARY} ${COREFOUNDATION_LIBRARY}
|
||||
)
|
||||
set(CMAKE_MACOSX_BUNDLE ON)
|
||||
|
||||
# Avoid bin/ sub-directory in DMG
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
list(APPEND xcadoc_sources arguments.cpp arguments.h xcadoc.cpp)
|
||||
|
||||
list(APPEND xca_sources
|
||||
list(APPEND xcalib_sources
|
||||
BioByteArray.cpp dbhistory.cpp pki_key.cpp
|
||||
BioByteArray.h dbhistory.h pki_key.h
|
||||
Passwd.cpp entropy.cpp pki_lookup.h
|
||||
@ -13,8 +13,8 @@ asn1int.h headerlist.h pki_pkcs7.cpp
|
||||
asn1time.cpp ipvalidator.h pki_pkcs7.h
|
||||
asn1time.h load_obj.cpp pki_scard.cpp
|
||||
base.h load_obj.h pki_scard.h
|
||||
builtin_curves.cpp main.cpp pki_temp.cpp
|
||||
builtin_curves.h main.h pki_temp.h
|
||||
builtin_curves.cpp pki_temp.cpp
|
||||
builtin_curves.h pki_temp.h
|
||||
database_model.cpp oid.cpp pki_x509.cpp
|
||||
database_model.h oid.h pki_x509.h
|
||||
db_base.cpp opensc-pkcs11.h pki_x509req.cpp
|
||||
@ -47,7 +47,7 @@ macro(ExpandSources target)
|
||||
target_sources(${target} PRIVATE ${${target}_sources})
|
||||
endmacro()
|
||||
|
||||
ExpandSources(xca)
|
||||
ExpandSources(xcalib)
|
||||
ExpandSources(xcadoc)
|
||||
|
||||
macro(Test name)
|
||||
|
||||
@ -8,7 +8,6 @@
|
||||
|
||||
#include "db_crl.h"
|
||||
#include "db_x509.h"
|
||||
#include "main.h"
|
||||
#include "exception.h"
|
||||
#include "database_model.h"
|
||||
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
#include "pki_scard.h"
|
||||
#include "pki_x509super.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "exception.h"
|
||||
#include "pkcs11.h"
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
#include "ui_MainWindow.h"
|
||||
#include "widgets/XcaApplication.h"
|
||||
#include "func.h"
|
||||
#include "main.h"
|
||||
#include "entropy.h"
|
||||
#include "settings.h"
|
||||
#include "pki_multi.h"
|
||||
@ -33,7 +32,6 @@
|
||||
#include <QTextStream>
|
||||
|
||||
char segv_data[1024];
|
||||
MainWindow *mainwin = NULL;
|
||||
|
||||
#if defined(Q_OS_WIN32)
|
||||
static LONG CALLBACK w32_segfault(LPEXCEPTION_POINTERS e)
|
||||
|
||||
22
lib/main.h
22
lib/main.h
@ -1,22 +0,0 @@
|
||||
/* vi: set sw=4 ts=4:
|
||||
*
|
||||
* Copyright (C) 2001 - 2015 Christian Hohnstaedt.
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
class pki_multi;
|
||||
|
||||
class MainWindow;
|
||||
extern MainWindow *mainwin;
|
||||
|
||||
extern char segv_data[1024];
|
||||
|
||||
pki_multi *probeAnything(const QString &, int *ret = nullptr);
|
||||
int exportIndex(const QString &fname, bool hierarchy);
|
||||
#endif
|
||||
139
lib/test_main.cpp
Normal file
139
lib/test_main.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/* vi: set sw=4 ts=4:
|
||||
*
|
||||
* Copyright (C) 2023 Christian Hohnstaedt.
|
||||
*
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QTest>
|
||||
#include <QString>
|
||||
#include <QThread>
|
||||
#include <QApplication>
|
||||
|
||||
#include "widgets/MainWindow.h"
|
||||
#include "ui_MainWindow.h"
|
||||
#include "widgets/NewKey.h"
|
||||
#include "ui_NewKey.h"
|
||||
#include "entropy.h"
|
||||
#include "pki_evp.h"
|
||||
#include "debug_info.h"
|
||||
|
||||
char segv_data[1024];
|
||||
|
||||
class test_main: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Entropy *entropy {};
|
||||
|
||||
void openDB();
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
void newKey();
|
||||
};
|
||||
|
||||
void test_main::initTestCase()
|
||||
{
|
||||
debug_info::init();
|
||||
|
||||
entropy = new Entropy;
|
||||
|
||||
Settings.clear();
|
||||
initOIDs();
|
||||
|
||||
mainwin = new MainWindow();
|
||||
mainwin->show();
|
||||
}
|
||||
|
||||
void test_main::cleanupTestCase()
|
||||
{
|
||||
Database.close();
|
||||
delete entropy;
|
||||
delete mainwin;
|
||||
pki_export::free_elements();
|
||||
}
|
||||
|
||||
void test_main::openDB()
|
||||
{
|
||||
pki_evp::passwd = "pass";
|
||||
QString salt = Entropy::makeSalt();
|
||||
pki_evp::passHash = pki_evp::sha512passwT(pki_evp::passwd, salt);
|
||||
Settings["pwhash"] = pki_evp::passHash;
|
||||
Database.open("testdb.xdb");
|
||||
}
|
||||
|
||||
void test_main::newKey()
|
||||
{
|
||||
/* RSA 3012 bit key - Remember as default */
|
||||
NewKey *dlg = new NewKey(mainwin, "Alfons");
|
||||
dlg->show();
|
||||
Q_ASSERT(QTest::qWaitForWindowActive(dlg));
|
||||
dlg->keyLength->setEditText("3012 bit");
|
||||
QCOMPARE(dlg->rememberDefault->isChecked(), false);
|
||||
dlg->rememberDefault->setChecked(true);
|
||||
dlg->accept();
|
||||
keyjob job = dlg->getKeyJob();
|
||||
QCOMPARE(job.ktype.name, "RSA");
|
||||
QCOMPARE(job.size, 3012);
|
||||
delete dlg;
|
||||
|
||||
/* Remembered RSA:3012 key. Change to EC:secp521r1 */
|
||||
dlg = new NewKey(mainwin, "Erwin");
|
||||
dlg->show();
|
||||
Q_ASSERT(QTest::qWaitForWindowActive(dlg));
|
||||
QCOMPARE(dlg->rememberDefault->isChecked(), false);
|
||||
QCOMPARE(job.toString(), dlg->getKeyJob().toString());
|
||||
/* Curve box visible after selecting EC Kex */
|
||||
QCOMPARE(dlg->curveBox->isVisible(),false);
|
||||
QCOMPARE(dlg->curveLabel->isVisible(),false);
|
||||
dlg->keyType->setCurrentIndex(2);
|
||||
QCOMPARE(dlg->curveBox->isVisible(),true);
|
||||
QCOMPARE(dlg->curveLabel->isVisible(),true);
|
||||
dlg->curveBox->setCurrentIndex(2);
|
||||
QCOMPARE(dlg->getKeyJob().toString(), "EC:secp521r1");
|
||||
/* Select Edwards Curve */
|
||||
dlg->keyType->setCurrentIndex(3);
|
||||
QCOMPARE(dlg->getKeyJob().toString(), "ED25519");
|
||||
/* Neither key size nor curve is visible */
|
||||
QCOMPARE(dlg->curveBox->isVisible(),false);
|
||||
QCOMPARE(dlg->curveLabel->isVisible(),false);
|
||||
QCOMPARE(dlg->keyLength->isVisible(),false);
|
||||
QCOMPARE(dlg->keySizeLabel->isVisible(),false);
|
||||
/* Back to EC and previously set curve is set */
|
||||
dlg->keyType->setCurrentIndex(2);
|
||||
QCOMPARE(dlg->getKeyJob().toString(), "EC:secp521r1");
|
||||
dlg->accept();
|
||||
delete dlg;
|
||||
|
||||
/* Open dialog again and RSA:3012 is remembered */
|
||||
dlg = new NewKey(mainwin, "Otto");
|
||||
dlg->show();
|
||||
Q_ASSERT(QTest::qWaitForWindowActive(dlg));
|
||||
QCOMPARE(dlg->rememberDefault->isChecked(), false);
|
||||
QCOMPARE(job.toString(), dlg->getKeyJob().toString());
|
||||
QCOMPARE(dlg->curveBox->isVisible(),false);
|
||||
QCOMPARE(dlg->curveLabel->isVisible(),false);
|
||||
/* Select EC and remeber as default */
|
||||
dlg->keyType->setCurrentIndex(2);
|
||||
dlg->curveBox->setCurrentIndex(2);
|
||||
|
||||
QCOMPARE(dlg->curveBox->isVisible(),true);
|
||||
QCOMPARE(dlg->curveLabel->isVisible(),true);
|
||||
QCOMPARE(dlg->getKeyJob().toString(), "EC:secp521r1");
|
||||
dlg->rememberDefault->setChecked(true);
|
||||
dlg->accept();
|
||||
delete dlg;
|
||||
|
||||
/* Now "EC:secp521r1" is remembered as default */
|
||||
dlg = new NewKey(mainwin, "Heini");
|
||||
dlg->show();
|
||||
Q_ASSERT(QTest::qWaitForWindowActive(dlg));
|
||||
QCOMPARE(dlg->getKeyJob().toString(), "EC:secp521r1");
|
||||
QCOMPARE(dlg->rememberDefault->isChecked(), false);
|
||||
}
|
||||
|
||||
QTEST_MAIN(test_main)
|
||||
#include "test_main.moc"
|
||||
@ -30,4 +30,4 @@ pkcs12EncBox.cpp XcaDetail.cpp
|
||||
)
|
||||
|
||||
list(TRANSFORM xca_sources PREPEND ${PROJECT_SOURCE_DIR}/widgets/)
|
||||
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${xca_sources})
|
||||
target_sources(xcalib PRIVATE ${xca_sources})
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "lib/main.h"
|
||||
#include "lib/pki_evp.h"
|
||||
#include "lib/pki_scard.h"
|
||||
|
||||
|
||||
@ -44,7 +44,8 @@
|
||||
#include "Help.h"
|
||||
#include "OidResolver.h"
|
||||
|
||||
OidResolver *MainWindow::resolver = NULL;
|
||||
OidResolver *MainWindow::resolver;
|
||||
MainWindow *mainwin;
|
||||
|
||||
void MainWindow::enableTokenMenu(bool enable)
|
||||
{
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
|
||||
#include "lib/oid.h"
|
||||
#include "lib/Passwd.h"
|
||||
#include "lib/main.h"
|
||||
#include "lib/database_model.h"
|
||||
#include "lib/dbhistory.h"
|
||||
#include "lib/dhgen.h"
|
||||
@ -31,6 +30,8 @@ class QProgressBar;
|
||||
class DHgen;
|
||||
class Help;
|
||||
|
||||
extern MainWindow *mainwin;
|
||||
|
||||
class tipMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#define __XCAPROGRESSGUI_H
|
||||
|
||||
#include "lib/base.h"
|
||||
#include "lib/main.h"
|
||||
#include "lib/XcaProgress.h"
|
||||
|
||||
#include <QProgressBar>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user