From 537ffafefd8a3276b51dbde07267a2c8bf398469 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Mon, 20 Sep 2010 00:16:30 +0200 Subject: [PATCH] Add unit test TestKeePass2Reader. --- src/format/KeePass2Reader.cpp | 1 + src/keys/PasswordKey.cpp | 9 ++++++ src/keys/PasswordKey.h | 2 ++ tests/CMakeLists.txt | 3 ++ tests/NonAscii.kdbx | Bin 0 -> 2574 bytes tests/TestKeePass2Reader.cpp | 55 ++++++++++++++++++++++++++++++++++ 6 files changed, 70 insertions(+) create mode 100644 tests/NonAscii.kdbx create mode 100644 tests/TestKeePass2Reader.cpp diff --git a/src/format/KeePass2Reader.cpp b/src/format/KeePass2Reader.cpp index 23d99fb35..d38b433e7 100644 --- a/src/format/KeePass2Reader.cpp +++ b/src/format/KeePass2Reader.cpp @@ -74,6 +74,7 @@ Database* KeePass2Reader::readDatabase(QIODevice* device, const CompositeKey& ke if (realStart != m_streamStartBytes) { raiseError("4"); + return 0; } HashedBlockStream hashedStream(&cipherStream); diff --git a/src/keys/PasswordKey.cpp b/src/keys/PasswordKey.cpp index b48e9186a..ce216c216 100644 --- a/src/keys/PasswordKey.cpp +++ b/src/keys/PasswordKey.cpp @@ -19,6 +19,15 @@ #include "crypto/CryptoHash.h" +PasswordKey::PasswordKey() +{ +} + +PasswordKey::PasswordKey(const QString& password) +{ + setPassword(password); +} + QByteArray PasswordKey::rawKey() const { return m_key; diff --git a/src/keys/PasswordKey.h b/src/keys/PasswordKey.h index 259f1c825..6d32d560e 100644 --- a/src/keys/PasswordKey.h +++ b/src/keys/PasswordKey.h @@ -25,6 +25,8 @@ class PasswordKey : public Key { public: + PasswordKey(); + PasswordKey(const QString& password); QByteArray rawKey() const; void setPassword(const QString& password); PasswordKey* clone() const; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cbcdaf38a..41b1e6476 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -71,6 +71,9 @@ target_link_libraries( testgroup keepassx_core ${QT_QTCORE_LIBRARY} ${QT_QTGUI_L add_unit_test( testkeepass2xmlreader TestKeePass2XmlReader.cpp ) target_link_libraries( testkeepass2xmlreader keepassx_core ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} ${LIBGCRYPT_LIBS} ) +add_unit_test( testkeepass2reader TestKeePass2Reader.cpp ) +target_link_libraries( testkeepass2reader keepassx_core ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} ${LIBGCRYPT_LIBS} ) + add_unit_test( testgroupmodel TestGroupModel.cpp modeltest.cpp ) target_link_libraries( testgroupmodel keepassx_core ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} ${LIBGCRYPT_LIBS} ) diff --git a/tests/NonAscii.kdbx b/tests/NonAscii.kdbx new file mode 100644 index 0000000000000000000000000000000000000000..d4e4ec547a9333194007156559cd3d9aafccf6ea GIT binary patch literal 2574 zcmV+p3i0&=*`k_f`%AR|00IC45CAd3^5(yBLr}h01tDtuTK@wC0000000bZa|Kr8h zX|Q596W)}WtzS5?3b|Y&e-8UCo-`Ld{E;-51t0*PCyNwm775nD?6>LwE9gNl^21Ya z){ol?y_q7H(3iOe2mo*w00000000LN0PT~m(7FsPrr4D{?V!mg3kVgr7VVF&8`iU2_OJ{0#z-(9X8yO4Q zu{$%5IJ5-{1ONg60000401XNa3Wc%}cHUq#MM%a?1z(=^-s6OsPs+jpgbSmeu%|Vq z1vsQSkV4d4F#%X4TZYoV6}>f>DUN?iW; zkP-9k>??uxP+4Qt((o@<3$5 zi2{8G1lcTjYUXLOTjl_U`y(-4dn3F!Uv8N5hy@4oL--}UMpZ_Sx{^x^SE6zrO3yI? zTyQG?tY)LR^sUHCu?l5q_XEhz-x$}O`i9ezm!vU%=H7`>4z|^Dlb2pG&ri$7-h+oxyK&Y3 zT>exs1p&qn>TaS>^p?90GIVqgLKm!gi*z%XP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b38 z{na&T)tb!GGDnu27hiBm0_d4X`uC$7Q0O^Oj!)iiel9_klm1!`h?9%{$<&#w6{pkyY@n}N#Og=>iA z_Li_3Z~i-WHUtAa`$N0p*~ay-HAaJAjUopAAX8pHs}y-QJHI^9Kmibq?lE%`uWX|g~)WbS=V>#RlhISb1I_4JPrE}y$0a&TI)K}C!7LammnDeN?9TL;X7=G_K$&+{mm k2>`b}#NqfP)W(l-(v=Um`Bp*l-roQDfJ + * + * 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 . + */ + +#include + +#include "config-keepassx-tests.h" +#include "core/Database.h" +#include "core/Metadata.h" +#include "crypto/Crypto.h" +#include "format/KeePass2Reader.h" +#include "keys/PasswordKey.h" + +class TestKeePass2Reader : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase(); + void testNonAscii(); +}; + +void TestKeePass2Reader::initTestCase() +{ + Crypto::init(); +} + +void TestKeePass2Reader::testNonAscii() +{ + QString filename = QString(KEEPASSX_TEST_DIR).append("/NonAscii.kdbx"); + CompositeKey key; + key.addKey(PasswordKey(QString::fromUtf8("\xce\x94\xc3\xb6\xd8\xb6"))); + KeePass2Reader* reader = new KeePass2Reader(); + Database* db = reader->readDatabase(filename, key); + QVERIFY(db); + QVERIFY(!reader->error()); + QCOMPARE(db->metadata()->name(), QString("NonAsciiTest")); +} + +QTEST_MAIN(TestKeePass2Reader); + +#include "TestKeePass2Reader.moc"