Merge remote-tracking branch 'upstream/develop' into feature/import-csv-format

This commit is contained in:
seatedscribe
2017-03-16 21:25:38 +01:00
157 changed files with 2325 additions and 519 deletions

View File

@@ -100,6 +100,10 @@ set(testsupport_SOURCES modeltest.cpp FailDevice.cpp)
add_library(testsupport STATIC ${testsupport_SOURCES})
target_link_libraries(testsupport ${MHD_LIBRARIES} Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test)
if(YUBIKEY_FOUND)
set(TEST_LIBRARIES ${TEST_LIBRARIES} ${YUBIKEY_LIBRARIES})
endif()
add_unit_test(NAME testgroup SOURCES TestGroup.cpp
LIBS ${TEST_LIBRARIES})
@@ -169,6 +173,10 @@ add_unit_test(NAME testexporter SOURCES TestExporter.cpp
add_unit_test(NAME testcsvexporter SOURCES TestCsvExporter.cpp
LIBS ${TEST_LIBRARIES})
add_unit_test(NAME testykchallengeresponsekey
SOURCES TestYkChallengeResponseKey.cpp TestYkChallengeResponseKey.h
LIBS ${TEST_LIBRARIES})
if(WITH_GUI_TESTS)
add_subdirectory(gui)
endif(WITH_GUI_TESTS)

View File

@@ -31,7 +31,7 @@ class TestAutoType : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void init();
void cleanup();

View File

@@ -24,7 +24,7 @@ class TestCryptoHash : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void test();
};

View File

@@ -31,7 +31,7 @@ class TestCsvExporter : public QObject
public:
static const QString ExpectedHeaderLine;
private Q_SLOTS:
private slots:
void init();
void initTestCase();
void cleanup();

View File

@@ -29,7 +29,7 @@ class TestDeletedObjects : public QObject
private:
void createAndDelete(Database* db, int delObjectsSize);
private Q_SLOTS:
private slots:
void initTestCase();
void testDeletedObjectsFromFile();
void testDeletedObjectsFromNewDb();

View File

@@ -26,7 +26,7 @@ class TestEntry : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testHistoryItemDeletion();
void testCopyDataFrom();

View File

@@ -24,7 +24,7 @@ class TestEntryModel : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void test();
void testAttachmentsModel();

View File

@@ -28,7 +28,7 @@ class TestEntrySearcher : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void cleanupTestCase();

View File

@@ -25,7 +25,7 @@ class TestExporter : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testToDbExporter();
};

View File

@@ -25,7 +25,7 @@ class TestGroup : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testParenting();
void testSignals();

View File

@@ -131,7 +131,7 @@ void TestGroupModel::test()
QCOMPARE(spyMoved.count(), 3);
QVERIFY(index12.isValid());
QCOMPARE(model->data(index12).toString(), QString("group12"));
QCOMPARE(model->data(index12.child(0, 0)).toString(), QString("group121"));
QCOMPARE(model->data(index12.model()->index(0, 0, index12)).toString(), QString("group121"));
delete group12;
QCOMPARE(spyAboutToAdd.count(), 1);

View File

@@ -24,7 +24,7 @@ class TestGroupModel : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void test();
};

View File

@@ -24,7 +24,7 @@ class TestHashedBlockStream : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testWriteRead();
void testReset();

View File

@@ -27,7 +27,7 @@ class TestKeePass1Reader : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testBasic();
void testMasterKey();

View File

@@ -24,7 +24,7 @@ class TestKeePass2RandomStream : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void test();
};

View File

@@ -24,7 +24,7 @@ class TestKeePass2Reader : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testNonAscii();
void testCompressed();

View File

@@ -26,7 +26,7 @@ class TestKeePass2Writer : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testBasic();
void testProtectedAttributes();

View File

@@ -27,7 +27,7 @@ class TestKeePass2XmlReader : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testMetadata();
void testCustomIcons();

View File

@@ -24,7 +24,7 @@ class TestKeys : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testComposite();
void testCompositeKeyReadFromLine();

View File

@@ -24,7 +24,7 @@ class TestModified : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testSignals();
void testGroupSets();

View File

@@ -38,7 +38,7 @@ class TestRandom : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testUInt();
void testUIntRange();

View File

@@ -24,7 +24,7 @@ class TestSymmetricCipher : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testAes256CbcEncryption();
void testAes256CbcDecryption();

View File

@@ -26,7 +26,7 @@ class TestWildcardMatcher : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void testMatcher();
void testMatcher_data();

View File

@@ -0,0 +1,112 @@
/*
* Copyright (C) 2014 Kyle Manna <kyle@kylemanna.com>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TestYkChallengeResponseKey.h"
#include <QTest>
#include <QtConcurrentRun>
#include "crypto/Crypto.h"
#include "keys/YkChallengeResponseKey.h"
QTEST_GUILESS_MAIN(TestYubiKeyChalResp)
void TestYubiKeyChalResp::initTestCase()
{
m_detected = 0;
m_key = NULL;
// crypto subsystem needs to be initialized for YubiKey testing
QVERIFY(Crypto::init());
}
void TestYubiKeyChalResp::cleanupTestCase()
{
if (m_key)
delete m_key;
}
void TestYubiKeyChalResp::init()
{
bool result = YubiKey::instance()->init();
if (!result) {
QSKIP("Unable to connect to YubiKey", SkipAll);
}
}
void TestYubiKeyChalResp::detectDevices()
{
connect(YubiKey::instance(), SIGNAL(detected(int,bool)),
SLOT(ykDetected(int,bool)),
Qt::QueuedConnection);
QtConcurrent::run(YubiKey::instance(), &YubiKey::detect);
// need to wait for the hardware (that's hopefully plugged in)...
QTest::qWait(2000);
QVERIFY2(m_detected > 0, "Is a YubiKey attached?");
}
void TestYubiKeyChalResp::getSerial()
{
unsigned int serial;
QVERIFY(YubiKey::instance()->getSerial(serial));
}
void TestYubiKeyChalResp::keyGetName()
{
QVERIFY(m_key);
QVERIFY(m_key->getName().length() > 0);
}
void TestYubiKeyChalResp::keyIssueChallenge()
{
QVERIFY(m_key);
if (m_key->isBlocking()) {
/* Testing active mode in unit tests is unreasonable */
QSKIP("YubiKey not in passive mode", SkipSingle);
}
QByteArray ba("UnitTest");
QVERIFY(m_key->challenge(ba));
/* TODO Determine if it's reasonable to provide a fixed secret key for
* verification testing. Obviously simple technically, but annoying
* if devs need to re-program their yubikeys or have a spare test key
* for unit tests to past.
*
* Might be worth it for integrity verification though.
*/
}
void TestYubiKeyChalResp::ykDetected(int slot, bool blocking)
{
Q_UNUSED(blocking);
if (slot > 0)
m_detected++;
/* Key used for later testing */
if (!m_key)
m_key = new YkChallengeResponseKey(slot, blocking);
}
void TestYubiKeyChalResp::deinit()
{
QVERIFY(YubiKey::instance()->deinit());
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2014 Kyle Manna <kyle@kylemanna.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 or (at your option)
* version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_TESTYUBIKEYCHALRESP_H
#define KEEPASSX_TESTYUBIKEYCHALRESP_H
#include <QObject>
#include "keys/YkChallengeResponseKey.h"
class TestYubiKeyChalResp: public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void init();
/* Order is important!
* Need to init and detectDevices() before proceeding
*/
void detectDevices();
void getSerial();
void keyGetName();
void keyIssueChallenge();
void deinit();
/* Callback for detectDevices() */
void ykDetected(int slot, bool blocking);
private:
int m_detected;
YkChallengeResponseKey *m_key;
};
#endif // KEEPASSX_TESTYUBIKEYCHALRESP_H

View File

@@ -588,6 +588,50 @@ void TestGui::testCloneEntry()
QCOMPARE(entryClone->title(), entryOrg->title() + QString(" - Clone"));
}
void TestGui::testEntryPlaceholders()
{
QToolBar* toolBar = m_mainWindow->findChild<QToolBar*>("toolBar");
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");
// Find the new entry action
QAction* entryNewAction = m_mainWindow->findChild<QAction*>("actionEntryNew");
QVERIFY(entryNewAction->isEnabled());
// Find the button associated with the new entry action
QWidget* entryNewWidget = toolBar->widgetForAction(entryNewAction);
QVERIFY(entryNewWidget->isVisible());
QVERIFY(entryNewWidget->isEnabled());
// Click the new entry button and check that we enter edit mode
QTest::mouseClick(entryNewWidget, Qt::LeftButton);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::EditMode);
// Add entry "test" and confirm added
EditEntryWidget* editEntryWidget = m_dbWidget->findChild<EditEntryWidget*>("editEntryWidget");
QLineEdit* titleEdit = editEntryWidget->findChild<QLineEdit*>("titleEdit");
QTest::keyClicks(titleEdit, "test");
QLineEdit* usernameEdit = editEntryWidget->findChild<QLineEdit*>("usernameEdit");
QTest::keyClicks(usernameEdit, "john");
QLineEdit* urlEdit = editEntryWidget->findChild<QLineEdit*>("urlEdit");
QTest::keyClicks(urlEdit, "{TITLE}.{USERNAME}");
QDialogButtonBox* editEntryWidgetButtonBox = editEntryWidget->findChild<QDialogButtonBox*>("buttonBox");
QTest::mouseClick(editEntryWidgetButtonBox->button(QDialogButtonBox::Ok), Qt::LeftButton);
QCOMPARE(entryView->model()->rowCount(), 2);
QCOMPARE(m_dbWidget->currentMode(), DatabaseWidget::ViewMode);
QModelIndex item = entryView->model()->index(1, 1);
Entry* entry = entryView->entryFromIndex(item);
QCOMPARE(entry->title(), QString("test"));
QCOMPARE(entry->url(), QString("{TITLE}.{USERNAME}"));
// Test password copy
QClipboard *clipboard = QApplication::clipboard();
m_dbWidget->copyURL();
QTRY_COMPARE(clipboard->text(), QString("test.john"));
}
void TestGui::testDragAndDropEntry()
{
EntryView* entryView = m_dbWidget->findChild<EntryView*>("entryView");

View File

@@ -33,7 +33,7 @@ class TestGui : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void init();
void cleanup();
@@ -48,6 +48,7 @@ private Q_SLOTS:
void testSearch();
void testDeleteEntry();
void testCloneEntry();
void testEntryPlaceholders();
void testDragAndDropEntry();
void testDragAndDropGroup();
void testSaveAs();

View File

@@ -26,7 +26,7 @@ class TestGuiPixmaps : public QObject
{
Q_OBJECT
private Q_SLOTS:
private slots:
void initTestCase();
void testDatabaseIcons();
void testEntryIcons();

View File

@@ -46,7 +46,7 @@ class ModelTest : public QObject
public:
ModelTest( QAbstractItemModel *model, QObject *parent = 0 );
private Q_SLOTS:
private slots:
void nonDestructiveBasicTest();
void rowCount();
void columnCount();
@@ -55,7 +55,7 @@ private Q_SLOTS:
void parent();
void data();
protected Q_SLOTS:
protected slots:
void runAllTests();
void layoutAboutToBeChanged();
void layoutChanged();