aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-19 05:05:28 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:46 +0200
commitf1fca53a784b2a1d40d20059073b54ed4c49565e (patch)
treec0bfa0ff2abae8da5d6c04ae1b496a3d465e49ab
parent11c80ea37da9abae92337eeadbc9f5edca5a1498 (diff)
Fix password salt not stored, generating a new salt everytime
-rw-r--r--src/DatabaseStorage.cpp1
-rw-r--r--tests/main.cpp43
2 files changed, 44 insertions, 0 deletions
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
index 14b74e8..de9d0df 100644
--- a/src/DatabaseStorage.cpp
+++ b/src/DatabaseStorage.cpp
@@ -158,6 +158,7 @@ namespace odhtdb
metadataSerializer.add(STORAGE_VERSION);
randombytes_buf(passwordSalt, PASSWORD_SALT_LEN);
metadataSerializer.add(passwordSalt, PASSWORD_SALT_LEN);
+ fileOverwrite(metadataFilePath, { metadataSerializer.getBuffer().data(), metadataSerializer.getBuffer().size() });
}
catch(sibs::DeserializeException &e)
{
diff --git a/tests/main.cpp b/tests/main.cpp
index 1541d2a..988309c 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -377,6 +377,48 @@ static void __attribute__((optimize("O0"))) testMemoryLeak()
}
}
+static void testStoreAccount()
+{
+ boost::filesystem::path storagePath("/tmp/odhtdb");
+ boost::filesystem::remove_all(storagePath);
+ boost::filesystem::create_directory(storagePath);
+
+ auto createNodeCallback = [](const DatabaseCreateNodeRequest &request)
+ {
+ Log::debug("Create node callback");
+ };
+
+ auto addNodeCallback = [](const DatabaseAddNodeRequest &request)
+ {
+ Log::debug("Add node callback");
+ };
+
+ auto addUserCallback = [](const DatabaseAddUserRequest &request)
+ {
+ Log::debug("Add user callback");
+ };
+
+ {
+ DatabaseCallbackFuncs callbackFuncs { createNodeCallback, addNodeCallback, addUserCallback };
+ Database database("127.0.0.1", PORT, storagePath, callbackFuncs);
+
+ std::string username = "username";
+ std::string password = "password";
+
+ database.storeUserWithoutNodes(username, password);
+ database.getStoredNodeUserInfoDecrypted(username, password);
+ }
+ {
+ DatabaseCallbackFuncs callbackFuncs { createNodeCallback, addNodeCallback, addUserCallback };
+ Database database("127.0.0.1", PORT, storagePath, callbackFuncs);
+
+ std::string username = "username";
+ std::string password = "password";
+
+ database.getStoredNodeUserInfoDecrypted(username, password);
+ }
+}
+
struct Test
{
function<void()> testFunc;
@@ -394,6 +436,7 @@ int main(int argc, char **argv)
testByName["two_local_nodes"] = { testTwoLocalNodes, false };
testByName["memory_usage"] = { testMemoryUsage, true };
testByName["test_memory_leak"] = { testMemoryLeak, true };
+ testByName["store_account"] = { testStoreAccount, false };
const char *testName = "all";
if(argc > 1)