diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-14 03:07:43 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 4241bcd4e14095e4340a0300e205f6fdc503f1d8 (patch) | |
tree | 609041efdeac4cd8836c3b0a8569ffdf956c4d5d /tests | |
parent | b995e79eaf3ac940547beb902c1e1da5c08308ec (diff) |
Remove user/group classes, user public key/group id directly to database instead
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 24 |
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)); |