aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-05-14 03:07:43 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-05-14 03:07:46 +0200
commit1fe14e8fcfbec25cb6b70df194a82ede4cc0a3e5 (patch)
tree06e5fee96df9f9205e729bb2a3a9976f7de15ab1 /tests
parent87a425d8461b084407cfe5aa11ca2832033b4453 (diff)
Remove user/group classes, user public key/group id directly to database instead
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index 6e1a72f..0174384 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -2,7 +2,6 @@
#include "../include/odhtdb/Log.hpp"
#include "../include/odhtdb/Database.hpp"
#include "../include/odhtdb/Group.hpp"
-#include "../include/odhtdb/LocalUser.hpp"
#include "../include/odhtdb/Encryption.hpp"
#include "../include/odhtdb/Hash.hpp"
#include "../include/odhtdb/hex2bin.hpp"
@@ -49,19 +48,19 @@ void testHash()
Log::debug("hash of 'odhtdb' is: a7b30ec8ab92de60e551b26bb8f78d315697f84dd7f5549a143477e095ec934f");
}
-void testSignData(LocalUser *localUser)
+void testSignData(const Signature::KeyPair &localUserKeyPair)
{
- std::string publicKeyStr = localUser->getPublicKey().toString();
+ std::string publicKeyStr = localUserKeyPair.getPublicKey().toString();
Log::debug("Local user public key: %s", publicKeyStr.c_str());
- std::string privateKeyStr = localUser->getPrivateKey().toString();
+ std::string privateKeyStr = localUserKeyPair.getPrivateKey().toString();
Log::debug("Local user private key: %s", privateKeyStr.c_str());
string expectedUnsignedData = "hello, world!";
- string signedData = localUser->getPrivateKey().sign(DataView((void*)expectedUnsignedData.data(), expectedUnsignedData.size()));
+ string signedData = localUserKeyPair.getPrivateKey().sign(DataView((void*)expectedUnsignedData.data(), expectedUnsignedData.size()));
assertEquals(SIGNED_HASH_SIZE + expectedUnsignedData.size(), signedData.size());
- string unsignedData = localUser->getPublicKey().unsign(DataView((void*)signedData.data(), signedData.size()));
+ string unsignedData = localUserKeyPair.getPublicKey().unsign(DataView((void*)signedData.data(), signedData.size()));
assertEquals(expectedUnsignedData, unsignedData);
try
@@ -180,8 +179,8 @@ int main()
DatabaseNode databaseNode;
{
- LocalUser *localUser = LocalUser::create(Signature::KeyPair(), nullptr);
- testSignData(localUser);
+ Signature::KeyPair localUserKeyPair;
+ testSignData(localUserKeyPair);
// TODO: Setup local bootstrap node for tests
Database database("bootstrap.ring.cx", 4222, storagePath, callbackFuncs);
@@ -189,11 +188,10 @@ int main()
auto databaseCreateResponse = database.create();
databaseNode = { databaseCreateResponse->getNodeEncryptionKey(), databaseCreateResponse->getRequestHash() };
- auto adminUser = (LocalUser*)databaseCreateResponse->getNodeAdminUser();
- database.addData(databaseNode, adminUser, DataView{ (void*)"hello, world!", 13 });
- database.addUser(databaseNode, adminUser, localUser->getPublicKey(), adminUser->getGroups()[0]);
- localUser->addToGroup(adminUser->getGroups()[0]);
- database.addData(databaseNode, localUser, DataView{ (void*)"hello, aaald!", 13 });
+ auto adminUserKey = databaseCreateResponse->getNodeAdminKeyPair();
+ database.addData(databaseNode, *adminUserKey, DataView{ (void*)"hello, world!", 13 });
+ database.addUser(databaseNode, *adminUserKey, localUserKeyPair.getPublicKey(), databaseCreateResponse->getNodeAdminGroupId()->getView());
+ database.addData(databaseNode, localUserKeyPair, DataView{ (void*)"hello, aaald!", 13 });
database.seed(databaseNode);
this_thread::sleep_for(chrono::seconds(3));