From 414f2cafc6cf2fe141c011b0d63d447a9b983ac3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 14 Apr 2018 19:45:15 +0200 Subject: Store database storage to files, also loading --- tests/main.cpp | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/main.cpp b/tests/main.cpp index bd7d75c..d509972 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -5,6 +5,9 @@ #include "../include/odhtdb/LocalUser.hpp" #include "../include/odhtdb/Encryption.hpp" #include "../include/odhtdb/Hash.hpp" +#include "../include/odhtdb/hex2bin.hpp" +#include "../include/odhtdb/bin2hex.hpp" +#include "../include/odhtdb/DataView.hpp" #include #include #include @@ -13,10 +16,34 @@ using namespace std; using namespace chrono_literals; using namespace odhtdb; +void testBinHexConvert() +{ + DataView input { (void*)"hello", 5 }; + + string inputHex = bin2hex((const char*)input.data, input.size); + assertEquals("68656c6c6f", inputHex); + + string inputBin = hex2bin(inputHex.c_str(), inputHex.size()); + if(inputBin.size() != input.size) + { + string errMsg = "Expected input converted to hex and then back to binary size to be 5, was: "; + errMsg += to_string(inputBin.size()); + fail(errMsg); + } + + if(memcmp(input.data, inputBin.data(), input.size) != 0) + { + string errMsg = "Expected input converted to hex and then back to binary to be same as original input ('hello'), was: "; + errMsg += string(inputBin.c_str(), inputBin.size()); + fail(errMsg); + } +} + void testHash() { Hash hash("odhtdb", 6); - assertEquals("a7b30ec8ab92de60e551b26bb8f78d315697f84dd7f5549a143477e095ec934f", hash.toString()); + string hashHex = hash.toString(); + assertEquals("a7b30ec8ab92de60e551b26bb8f78d315697f84dd7f5549a143477e095ec934f", hashHex); Log::debug("hash of 'odhtdb' is: a7b30ec8ab92de60e551b26bb8f78d315697f84dd7f5549a143477e095ec934f"); } @@ -84,10 +111,12 @@ void testEncryption() int main() { Log::debug("Starting tests..."); - LocalUser *localUser = LocalUser::create(Signature::KeyPair(), "dec05eba", nullptr); - testSignData(localUser); - testEncryption(); + testBinHexConvert(); testHash(); + testEncryption(); + + LocalUser *localUser = LocalUser::create(Signature::KeyPair(), "dec05eba", nullptr, "secretPassword"); + testSignData(localUser); // TODO: Setup local bootstrap node for tests Database database("bootstrap.ring.cx", 4222, "storage"); @@ -107,16 +136,16 @@ int main() Log::debug("Add user callback"); }); - auto databaseCreateResponse = database.create("adminUserName", "latenight"); + auto databaseCreateResponse = database.create("adminUserName", "secretPassword", "latenight"); DatabaseNode databaseNode(databaseCreateResponse->getNodeEncryptionKey(), databaseCreateResponse->getRequestHash()); auto adminUser = (LocalUser*)databaseCreateResponse->getNodeAdminUser(); database.addData(databaseNode, adminUser, DataView{ (void*)"hello, world!", 13 }); - database.addUserToGroup(databaseNode, adminUser, localUser->getName(), localUser->getPublicKey(), adminUser->getGroups()[0]); + database.addUser(databaseNode, adminUser, localUser->getName(), localUser->getPublicKey(), adminUser->getGroups()[0]); localUser->addToGroup(adminUser->getGroups()[0]); database.addData(databaseNode, localUser, DataView{ (void*)"hello, aaald!", 13 }); database.commit(); - database.seed(databaseCreateResponse->getRequestHash(), databaseCreateResponse->getNodeEncryptionKey()); + database.seed(databaseNode); auto start = chrono::high_resolution_clock::now(); while(chrono::high_resolution_clock::now() - start < 3s) { -- cgit v1.2.3