From d8e5c76c364450179f12fa985d50b7e4bfb5aa78 Mon Sep 17 00:00:00 2001 From: dec05eba <0xdec05eba@gmail.com> Date: Tue, 15 May 2018 18:24:50 +0200 Subject: Add methods to store/retrieve encrypted user (using argon2 for hash) --- tests/main.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/main.cpp b/tests/main.cpp index 07e7131..d2e49f9 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -199,6 +199,28 @@ int main() assertEquals(1, createNodeCounter); assertEquals(2, addDataCounter); assertEquals(1, addUserCounter); + + string username = "dec05eba"; + string password = "secretPassword"; + database.storeUserPasswordEncrypted(*databaseNode.getRequestHash(), username, password, *adminUserKey); + try + { + database.storeUserPasswordEncrypted(*databaseNode.getRequestHash(), username, password, localUserKeyPair); + fail("Expected store user password to fail since we have already stored an user in the node"); + } + catch(SqlExecException &e) + { + Log::debug("Failed with sql exception as expected, since we already have an user in the node: %s", e.what()); + } + + auto nodeUserData = database.getStoredUserNodeDataDecrypted(username, password); + assertEquals((size_t)1, nodeUserData.size()); + if(nodeUserData[0].nodeHash != *databaseNode.getRequestHash()) + fail("Expected stored node hash to match node hash"); + if(nodeUserData[0].keyPair.getPublicKey() != adminUserKey->getPublicKey()) + fail("Expected stored public key to match admin user public key"); + if(nodeUserData[0].keyPair.getPrivateKey() != adminUserKey->getPrivateKey()) + fail("Expected stored private key to match admin user private key"); } Log::debug("Callback works when adding data while connected, now testing to reconnect and check if data remains..."); { -- cgit v1.2.3