aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAleksi Lindeman <0xdec05eba@gmail.com>2018-04-14 19:45:15 +0200
committerAleksi Lindeman <0xdec05eba@gmail.com>2018-04-14 19:45:24 +0200
commit6e4d46f8cf911b82a10e8cd25b65fcc421bbc712 (patch)
tree3d6ee838990389d920df934e20aea1700052ce74 /tests
parent9c22be3516d5067b98b06271e2f3545713ff6099 (diff)
Store database storage to files, also loading
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp43
1 files changed, 36 insertions, 7 deletions
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 <vector>
#include <chrono>
#include <thread>
@@ -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<string>("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<string>("a7b30ec8ab92de60e551b26bb8f78d315697f84dd7f5549a143477e095ec934f", hash.toString());
+ string hashHex = hash.toString();
+ assertEquals<string>("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)
{