Skip to content

Commit

Permalink
Renaming the file keys
Browse files Browse the repository at this point in the history
  • Loading branch information
louib committed Sep 17, 2022
1 parent 4fa0d6e commit 664d715
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions tests/TestCli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,15 @@ void TestCli::testCreate()

void TestCli::testDatabaseEdit()
{
TemporaryFile keyFile;
keyFile.open();
keyFile.write(QString("keyFilePassword").toLatin1());
keyFile.close();
TemporaryFile firstKeyFile;
firstKeyFile.open();
firstKeyFile.write(QString("keyFilePassword").toLatin1());
firstKeyFile.close();

TemporaryFile newKeyFile;
newKeyFile.open();
newKeyFile.write(QString("newKeyFilePassword").toLatin1());
newKeyFile.close();
TemporaryFile secondKeyFile;
secondKeyFile.open();
secondKeyFile.write(QString("newKeyFilePassword").toLatin1());
secondKeyFile.close();

QScopedPointer<QTemporaryDir> testDir(new QTemporaryDir());

Expand Down Expand Up @@ -906,7 +906,7 @@ void TestCli::testDatabaseEdit()
QVERIFY(!db.isNull());

setInput("b");
execCmd(editCmd, {"db-edit", dbFilename, "--set-key-file", keyFile.fileName()});
execCmd(editCmd, {"db-edit", dbFilename, "--set-key-file", firstKeyFile.fileName()});
// Skipping the password prompt.
m_stderr->readLine();
QCOMPARE(m_stderr->readAll(), QByteArray(""));
Expand All @@ -915,43 +915,44 @@ void TestCli::testDatabaseEdit()
// Sanity check
db = readDatabase(dbFilename, "b");
QVERIFY(db.isNull());
db = readDatabase(dbFilename, "b", keyFile.fileName());
db = readDatabase(dbFilename, "b", firstKeyFile.fileName());
QVERIFY(!db.isNull());

setInput("b");
execCmd(editCmd, {"db-edit", dbFilename, "-k", keyFile.fileName(), "--set-key-file", newKeyFile.fileName()});
execCmd(editCmd,
{"db-edit", dbFilename, "-k", firstKeyFile.fileName(), "--set-key-file", secondKeyFile.fileName()});
QCOMPARE(m_stdout->readAll(), QByteArray("Successfully edited the database.\n"));

// Sanity check
db = readDatabase(dbFilename, "b", keyFile.fileName());
db = readDatabase(dbFilename, "b", firstKeyFile.fileName());
QVERIFY(db.isNull());
db = readDatabase(dbFilename, "b", newKeyFile.fileName());
db = readDatabase(dbFilename, "b", secondKeyFile.fileName());
QVERIFY(!db.isNull());

setInput("b");
execCmd(editCmd, {"db-edit", dbFilename, "-k", newKeyFile.fileName(), "--unset-password"});
execCmd(editCmd, {"db-edit", dbFilename, "-k", secondKeyFile.fileName(), "--unset-password"});
// Skipping the password prompt.
m_stderr->readLine();
QCOMPARE(m_stderr->readAll(), QByteArray(""));
QCOMPARE(m_stdout->readAll(), QByteArray("Successfully edited the database.\n"));

setInput({"b", "b"});
execCmd(editCmd, {"db-edit", dbFilename, "-k", newKeyFile.fileName(), "--no-password", "--set-password"});
execCmd(editCmd, {"db-edit", dbFilename, "-k", secondKeyFile.fileName(), "--no-password", "--set-password"});
// Skipping over the password setting prompts.
m_stderr->readLine();
m_stderr->readLine();
QCOMPARE(m_stderr->readAll(), QByteArray(""));
QCOMPARE(m_stdout->readAll(), QByteArray("Successfully edited the database.\n"));

setInput("b");
execCmd(editCmd, {"db-edit", dbFilename, "-k", newKeyFile.fileName(), "--unset-key-file"});
execCmd(editCmd, {"db-edit", dbFilename, "-k", secondKeyFile.fileName(), "--unset-key-file"});
// Skipping the password prompt.
m_stderr->readLine();
QCOMPARE(m_stderr->readAll(), QByteArray(""));
QCOMPARE(m_stdout->readAll(), QByteArray("Successfully edited the database.\n"));

// Sanity check
db = readDatabase(dbFilename, "b", keyFile.fileName());
db = readDatabase(dbFilename, "b", firstKeyFile.fileName());
QVERIFY(db.isNull());
db = readDatabase(dbFilename, "b");
QVERIFY(!db.isNull());
Expand Down

0 comments on commit 664d715

Please sign in to comment.