Improve CSV export and import capability

* Fixes #3541
* CSV export now includes TOTP settings, Entry Icon (database icon number only), Modified Time, and Created Time.
* CSV import properly understands time in ISO 8601 format and Unix Timestamp.
* CSV import will set the TOTP settings and entry icon based on the chosen column.
This commit is contained in:
Jonathan White 2020-08-26 15:17:31 -04:00
parent f49f62d3be
commit f947c96462
7 changed files with 189 additions and 76 deletions

View file

@ -23,11 +23,13 @@
#include "crypto/Crypto.h"
#include "format/CsvExporter.h"
#include "totp/totp.h"
QTEST_GUILESS_MAIN(TestCsvExporter)
const QString TestCsvExporter::ExpectedHeaderLine =
QString("\"Group\",\"Title\",\"Username\",\"Password\",\"URL\",\"Notes\"\n");
QString("\"Group\",\"Title\",\"Username\",\"Password\",\"URL\",\"Notes\",\"TOTP\",\"Icon\",\"Last "
"Modified\",\"Created\"\n");
void TestCsvExporter::init()
{
@ -57,17 +59,23 @@ void TestCsvExporter::testExport()
entry->setPassword("Test Password");
entry->setUrl("http://test.url");
entry->setNotes("Test Notes");
entry->setTotp(Totp::createSettings("DFDF", Totp::DEFAULT_DIGITS, Totp::DEFAULT_STEP));
entry->setIcon(5);
QBuffer buffer;
QVERIFY(buffer.open(QIODevice::ReadWrite));
m_csvExporter->exportDatabase(&buffer, m_db);
auto exported = QString::fromUtf8(buffer.buffer());
QString expectedResult = QString()
.append(ExpectedHeaderLine)
.append("\"Passwords/Test Group Name\",\"Test Entry Title\",\"Test Username\",\"Test "
"Password\",\"http://test.url\",\"Test Notes\"\n");
"Password\",\"http://test.url\",\"Test Notes\"");
QCOMPARE(QString::fromUtf8(buffer.buffer().constData()), expectedResult);
QVERIFY(exported.startsWith(expectedResult));
exported.remove(expectedResult);
QVERIFY(exported.contains("otpauth://"));
QVERIFY(exported.contains(",\"5\","));
}
void TestCsvExporter::testEmptyDatabase()
@ -95,10 +103,9 @@ void TestCsvExporter::testNestedGroups()
QBuffer buffer;
QVERIFY(buffer.open(QIODevice::ReadWrite));
m_csvExporter->exportDatabase(&buffer, m_db);
QCOMPARE(
QString::fromUtf8(buffer.buffer().constData()),
auto exported = QString::fromUtf8(buffer.buffer());
QVERIFY(exported.startsWith(
QString()
.append(ExpectedHeaderLine)
.append("\"Passwords/Test Group Name/Test Sub Group Name\",\"Test Entry Title\",\"\",\"\",\"\",\"\"\n"));
.append("\"Passwords/Test Group Name/Test Sub Group Name\",\"Test Entry Title\",\"\",\"\",\"\",\"\"")));
}