mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
fix tests, make better output for debugging failing tests
This commit is contained in:
parent
f9e360ec3f
commit
5c411c5cb1
@ -179,8 +179,8 @@ Poco::AutoPtr<Passphrase> Passphrase::create(const Poco::UInt16 wordIndices[PHRA
|
||||
return new Passphrase(clearPassphrase, wordSource);
|
||||
}
|
||||
|
||||
Poco::AutoPtr<Passphrase> Passphrase::generate(const Mnemonic* wordSource)
|
||||
{
|
||||
Poco::AutoPtr<Passphrase> Passphrase::generate(const Mnemonic* wordSource)
|
||||
{
|
||||
auto em = ErrorManager::getInstance();
|
||||
auto mm = MemoryManager::getInstance();
|
||||
auto word_indices = mm->getFreeMemory(PHRASE_WORD_COUNT * sizeof(Poco::UInt16));
|
||||
@ -266,7 +266,7 @@ bool Passphrase::createWordIndices()
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//DHASH key = DRMakeStringHash(passphrase);
|
||||
size_t pass_phrase_size = mPassphraseString.size();
|
||||
|
||||
@ -352,9 +352,9 @@ const Mnemonic* Passphrase::detectMnemonic(const std::string& passphrase, const
|
||||
|
||||
if (keyPair) {
|
||||
user_public_key_hex = DataTypeConverter::pubkeyToHex(keyPair->getPublicKey());
|
||||
printf("user public key hex: %s\n", user_public_key_hex.data());
|
||||
//printf("user public key hex: %s\n", user_public_key_hex.data());
|
||||
}
|
||||
|
||||
std::string last_word_not_found = "";
|
||||
for (int i = 0; i < ServerConfig::Mnemonic_Types::MNEMONIC_MAX; i++) {
|
||||
Mnemonic& m = ServerConfig::g_Mnemonic_WordLists[i];
|
||||
bool existAll = true;
|
||||
@ -362,6 +362,8 @@ const Mnemonic* Passphrase::detectMnemonic(const std::string& passphrase, const
|
||||
if (*it == "\0" || *it == "" || it->size() < 3) continue;
|
||||
if (!m.isWordExist(*it)) {
|
||||
existAll = false;
|
||||
//printf("couldn't find word: %s\n", (*it).data());
|
||||
last_word_not_found = (*it);
|
||||
// leave inner for-loop
|
||||
break;
|
||||
}
|
||||
@ -373,7 +375,7 @@ const Mnemonic* Passphrase::detectMnemonic(const std::string& passphrase, const
|
||||
auto key_pair = KeyPairEd25519::create(test_passphrase);
|
||||
if (key_pair) {
|
||||
std::string current_key_pair = DataTypeConverter::pubkeyToHex(key_pair->getPublicKey());
|
||||
printf("public key hex to compare: %s\n", current_key_pair.data());
|
||||
//printf("public key hex to compare: %s\n", current_key_pair.data());
|
||||
|
||||
if (*key_pair != *keyPair) {
|
||||
delete key_pair;
|
||||
@ -387,5 +389,6 @@ const Mnemonic* Passphrase::detectMnemonic(const std::string& passphrase, const
|
||||
return &ServerConfig::g_Mnemonic_WordLists[i];
|
||||
}
|
||||
}
|
||||
printf("last word not found: %s\n", last_word_not_found.data());
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,18 +66,18 @@ namespace ServerConfig {
|
||||
HederaNetworkType g_HederaNetworkType = HEDERA_TESTNET;
|
||||
Poco::Timespan g_HederaDefaultTimeout;
|
||||
|
||||
#ifdef __linux__
|
||||
#include <stdio.h>
|
||||
#ifdef __linux__
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif //#ifdef __linux__
|
||||
#endif //#ifdef __linux__
|
||||
|
||||
std::string getHostIpString()
|
||||
{
|
||||
#ifdef __linux__
|
||||
#ifdef __linux__
|
||||
struct ifaddrs * ifAddrStruct = NULL;
|
||||
struct ifaddrs * ifa = NULL;
|
||||
void * tmpAddrPtr = NULL;
|
||||
@ -107,7 +107,7 @@ namespace ServerConfig {
|
||||
}
|
||||
if (ifAddrStruct != NULL) freeifaddrs(ifAddrStruct);
|
||||
return ipAddressString;
|
||||
#else //__linux__
|
||||
#else //__linux__
|
||||
std::string ipAddressString = "";
|
||||
auto host = Poco::Net::DNS::thisHost();
|
||||
for (auto it = host.addresses().begin(); it != host.addresses().end(); it++) {
|
||||
@ -126,10 +126,10 @@ namespace ServerConfig {
|
||||
//break;
|
||||
}
|
||||
return ipAddressString;
|
||||
#endif // __linux__
|
||||
#endif // __linux__
|
||||
}
|
||||
|
||||
bool replaceZeroIPWithLocalhostIP(std::string& url)
|
||||
bool replaceZeroIPWithLocalhostIP(std::string& url)
|
||||
{
|
||||
auto pos = url.find("0.0.0.0", 0);
|
||||
if (pos != std::string::npos) {
|
||||
@ -138,7 +138,7 @@ namespace ServerConfig {
|
||||
url.replace(pos, 7, ipAddressString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//printf("ipaddress: %s\n", ipAddress.data());
|
||||
|
||||
return true;
|
||||
@ -171,7 +171,21 @@ namespace ServerConfig {
|
||||
return HEDERA_CONSENSUS_FORMAT_BINARY;
|
||||
}
|
||||
|
||||
|
||||
const char* mnemonicTypeToString(Mnemonic_Types type)
|
||||
{
|
||||
/*
|
||||
MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER,
|
||||
MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER_FIXED_CASES,
|
||||
MNEMONIC_BIP0039_SORTED_ORDER
|
||||
*/
|
||||
switch(type) {
|
||||
case MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER: return "german random order";
|
||||
case MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER_FIXED_CASES: return "german random order fixed cases";
|
||||
case MNEMONIC_BIP0039_SORTED_ORDER: return "BIP 0039 sorted";
|
||||
}
|
||||
return "<unknown>";
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool loadMnemonicWordLists()
|
||||
@ -227,7 +241,7 @@ namespace ServerConfig {
|
||||
g_ServerCryptoKey = new ObfusArray(realBinSize, key);
|
||||
g_ServerKeySeed = new ObfusArray(9*8);
|
||||
Poco::Int64 i1 = randombytes_random();
|
||||
Poco::Int64 i2 = randombytes_random();
|
||||
Poco::Int64 i2 = randombytes_random();
|
||||
g_ServerKeySeed->put(0, i1 | (i2 << 8));
|
||||
|
||||
//g_ServerAdminPublic = cfg.getString("crypto.server_admin_public");
|
||||
@ -245,7 +259,7 @@ namespace ServerConfig {
|
||||
replaceZeroIPWithLocalhostIP(g_php_serverPath);
|
||||
g_php_serverHost = cfg.getString("phpServer.host", "");
|
||||
replaceZeroIPWithLocalhostIP(g_php_serverHost);
|
||||
//g_ServerSetupType
|
||||
//g_ServerSetupType
|
||||
auto serverSetupTypeString = cfg.getString("ServerSetupType", "");
|
||||
g_ServerSetupType = getServerSetupTypeFromString(serverSetupTypeString);
|
||||
|
||||
@ -284,7 +298,7 @@ namespace ServerConfig {
|
||||
if (cfg.getInt("unsecure.allow_all_passwords", 0) == 1) {
|
||||
g_AllowUnsecureFlags = (AllowUnsecure)(g_AllowUnsecureFlags | UNSECURE_ALLOW_ALL_PASSWORDS);
|
||||
}
|
||||
|
||||
|
||||
g_HederaDefaultTimeout = cfg.getInt("hedera.default_timeout", 5);
|
||||
|
||||
g_gRPCRelayServerFullURL = cfg.getString("grpc.server", "");
|
||||
@ -338,8 +352,8 @@ namespace ServerConfig {
|
||||
try {
|
||||
#ifdef POCO_NETSSL_WIN
|
||||
g_SSL_CLient_Context = new Context(Context::CLIENT_USE, "cacert.pem", Context::VERIFY_RELAXED, Context::OPT_DEFAULTS);
|
||||
#else
|
||||
|
||||
#else
|
||||
|
||||
g_SSL_CLient_Context = new Context(Context::CLIENT_USE, "", "", Poco::Path::config() + "grd_login/cacert.pem", Context::VERIFY_RELAXED, 9, true, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
|
||||
#endif
|
||||
} catch(Poco::Exception& ex) {
|
||||
@ -391,7 +405,7 @@ namespace ServerConfig {
|
||||
Poco::LocalDateTime now;
|
||||
|
||||
std::string dateTimeStr = Poco::DateTimeFormatter::format(now, Poco::DateTimeFormat::ISO8601_FORMAT);
|
||||
file << dateTimeStr << std::endl;
|
||||
file << dateTimeStr << std::endl;
|
||||
|
||||
for (std::string line; std::getline(datas, line); ) {
|
||||
file << line << std::endl;
|
||||
@ -400,4 +414,4 @@ namespace ServerConfig {
|
||||
file.close();
|
||||
mutex.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ namespace ServerConfig {
|
||||
HEDERA_UNKNOWN
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern Mnemonic g_Mnemonic_WordLists[MNEMONIC_MAX];
|
||||
@ -101,7 +101,8 @@ namespace ServerConfig {
|
||||
bool initServerCrypto(const Poco::Util::LayeredConfiguration& cfg);
|
||||
bool initEMailAccount(const Poco::Util::LayeredConfiguration& cfg);
|
||||
bool initSSLClientContext();
|
||||
|
||||
|
||||
const char* mnemonicTypeToString(Mnemonic_Types type);
|
||||
|
||||
void writeToFile(std::istream& datas, std::string fileName);
|
||||
|
||||
@ -109,4 +110,4 @@ namespace ServerConfig {
|
||||
};
|
||||
|
||||
|
||||
#endif //__GRADIDO_LOGIN_SERVER_SERVER_CONFIG__
|
||||
#endif //__GRADIDO_LOGIN_SERVER_SERVER_CONFIG__
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
#include "TestHash.h"
|
||||
#include "../lib/DRHash.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
TestHash::TestHash()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TestHash::~TestHash()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int TestHash::init()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestHash::test()
|
||||
{
|
||||
std::string testEmails[] = {
|
||||
"a","b", "c", "d", "aa", "ab",
|
||||
"@", ".d", "gmx", "@gmx", "@gmx.de",
|
||||
"***REMOVED***",
|
||||
"***REMOVED***",
|
||||
"coin-info5@gradido.net",
|
||||
"coin-info6@gradido.net",
|
||||
"coin-info8@gradido.net",
|
||||
"coin-info9@gradido.net",
|
||||
"coin-info10@gradido.net",
|
||||
"coin-info11@gradido.net",
|
||||
"coin-info12@gradido.net"
|
||||
};
|
||||
printf("hashes: \n");
|
||||
for (int i = 0; i < 20; i++) {
|
||||
DHASH id = DRMakeStringHash(testEmails[i].data(), testEmails[i].size());
|
||||
//printf("%s: %lu\n", testEmails[i].data(), id);
|
||||
//"***REMOVED***" => 1211212
|
||||
printf("\"%s\" => %lu,\n", testEmails[i].data(), id);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
#ifndef __GRADIDO_LOGIN_SERVER_TEST_HASH_
|
||||
#define __GRADIDO_LOGIN_SERVER_TEST_HASH_
|
||||
|
||||
#include "Test.h"
|
||||
|
||||
class TestHash : public Test
|
||||
{
|
||||
public:
|
||||
TestHash();
|
||||
~TestHash();
|
||||
//! \return 0 if init okay, else return != 0
|
||||
int init();
|
||||
|
||||
//! \return 0 if okay, else return != 0
|
||||
int test();
|
||||
const char* getName() { return "TestHash"; };
|
||||
};
|
||||
|
||||
#endif //__GRADIDO_LOGIN_SERVER_TEST_HASH_
|
||||
@ -2,7 +2,6 @@
|
||||
|
||||
#include "../../Crypto/SecretKeyCryptography.h"
|
||||
|
||||
#include "../../lib/Profiler.h"
|
||||
#include "../../lib/DataTypeConverter.h"
|
||||
|
||||
#include "../ServerConfig.h"
|
||||
@ -16,9 +15,8 @@ TEST_F(TestAuthenticatedEncryption, encryptDecryptTest) {
|
||||
EXPECT_FALSE(authenticated_encryption.hasKey());
|
||||
EXPECT_EQ(authenticated_encryption.getKeyHashed(), 0);
|
||||
|
||||
Profiler time_used;
|
||||
EXPECT_EQ(authenticated_encryption.createKey("dariofrodo@gmx.de", "r3an7d_spassw"), SecretKeyCryptography::AUTH_ENCRYPT_OK);
|
||||
printf("create key duration: %s\n", time_used.string().data());
|
||||
EXPECT_EQ(authenticated_encryption.createKey("max.musterman@gmail.com", "r3an7d_spassw"), SecretKeyCryptography::AUTH_CREATE_ENCRYPTION_KEY_SUCCEED);
|
||||
//printf("create key duration: %s\n", time_used.string().data());
|
||||
|
||||
EXPECT_TRUE(authenticated_encryption.hasKey());
|
||||
|
||||
@ -28,15 +26,14 @@ TEST_F(TestAuthenticatedEncryption, encryptDecryptTest) {
|
||||
MemoryBin* encrypted_message = nullptr;
|
||||
memcpy(*test_message_bin, test_message.data(), test_message.size());
|
||||
|
||||
time_used.reset();
|
||||
EXPECT_EQ(authenticated_encryption.encrypt(test_message_bin, &encrypted_message), SecretKeyCryptography::AUTH_ENCRYPT_OK);
|
||||
printf("encrypt message duration: %s\n", time_used.string().data());
|
||||
//printf("encrypt message duration: %s\n", time_used.string().data());
|
||||
|
||||
MemoryBin* decrypted_message = nullptr;
|
||||
time_used.reset();
|
||||
EXPECT_EQ(authenticated_encryption.decrypt(encrypted_message, &decrypted_message), SecretKeyCryptography::AUTH_DECRYPT_OK);
|
||||
printf("decrypt message duration: %s\n", time_used.string().data());
|
||||
//printf("decrypt message duration: %s\n", time_used.string().data());
|
||||
|
||||
EXPECT_EQ(std::string((const char*)*decrypted_message, decrypted_message->size()), test_message);
|
||||
mm->releaseMemory(decrypted_message);
|
||||
// */
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ void PassphraseTest::SetUp()
|
||||
wordIndices3
|
||||
));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST_F(PassphraseTest, detectMnemonic) {
|
||||
@ -95,7 +95,7 @@ TEST_F(PassphraseTest, detectMnemonic) {
|
||||
if (ServerConfig::MNEMONIC_GRADIDO_BOOK_GERMAN_RANDOM_ORDER_FIXED_CASES == type) continue;
|
||||
EXPECT_EQ(Passphrase::detectMnemonic(testDataSet.passphrases[type]), &ServerConfig::g_Mnemonic_WordLists[type]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
EXPECT_FALSE(Passphrase::detectMnemonic("Dies ist eine ungültige Passphrase"));
|
||||
}
|
||||
@ -110,6 +110,11 @@ TEST_F(PassphraseTest, detectMnemonicWithPubkey) {
|
||||
auto key_pair = new KeyPairEd25519(*pubkeyBin);
|
||||
for (int i = 0; i < ServerConfig::MNEMONIC_MAX; i++) {
|
||||
ServerConfig::Mnemonic_Types type = (ServerConfig::Mnemonic_Types)i;
|
||||
auto mnemonic_type = Passphrase::detectMnemonic(testDataSet.passphrases[type], key_pair);
|
||||
if(nullptr == mnemonic_type) {
|
||||
printf("no match for passphrase: %s\n", testDataSet.passphrases[type].data());
|
||||
printf("type: %s\n", ServerConfig::mnemonicTypeToString(type));
|
||||
}
|
||||
EXPECT_EQ(Passphrase::detectMnemonic(testDataSet.passphrases[type], key_pair), &ServerConfig::g_Mnemonic_WordLists[type]);
|
||||
}
|
||||
}
|
||||
@ -162,19 +167,19 @@ TEST_F(PassphraseTest, createAndTransform) {
|
||||
auto test_data_set = *it;
|
||||
auto mnemonic = &ServerConfig::g_Mnemonic_WordLists[test_data_set.mnemonicType];
|
||||
auto tr = Passphrase::create(test_data_set.wordIndices, mnemonic);
|
||||
|
||||
|
||||
auto word_indices = tr->getWordIndices();
|
||||
|
||||
|
||||
for (int i = 0; i < PHRASE_WORD_COUNT; i++) {
|
||||
EXPECT_EQ(word_indices[i], test_data_set.wordIndices[i]);
|
||||
}
|
||||
auto key_pair_ed25519 = KeyPairEd25519::create(tr);
|
||||
//KeyPair key_pair;
|
||||
//KeyPair key_pair;
|
||||
//key_pair.generateFromPassphrase(test_data_set.passphrases[test_data_set.mnemonicType].data(), mnemonic);
|
||||
EXPECT_EQ(DataTypeConverter::pubkeyToHex(key_pair_ed25519->getPublicKey()), test_data_set.pubkeyHex);
|
||||
//EXPECT_EQ(key_pair.getPubkeyHex(), test_data_set.pubkeyHex);
|
||||
|
||||
//auto key_pair_old
|
||||
//auto key_pair_old
|
||||
delete key_pair_ed25519;
|
||||
ASSERT_FALSE(tr.isNull());
|
||||
EXPECT_TRUE(tr->checkIfValid());
|
||||
|
||||
@ -16,7 +16,6 @@ std::list<Test*> gTests;
|
||||
void fillTests()
|
||||
{
|
||||
gTests.push_back(new TestTasks());
|
||||
gTests.push_back(new TestHash());
|
||||
gTests.push_back(new TestRegExp());
|
||||
gTests.push_back(new TestPassphrase());
|
||||
// gTests.push_back(new LoginTest());
|
||||
@ -73,14 +72,18 @@ int load() {
|
||||
auto conn = ConnectionManager::getInstance();
|
||||
//conn->setConnection()
|
||||
//printf("try connect login server mysql db\n");
|
||||
conn->setConnectionsFromConfig(*test_config, CONNECTION_MYSQL_LOGIN_SERVER);
|
||||
try {
|
||||
conn->setConnectionsFromConfig(*test_config, CONNECTION_MYSQL_LOGIN_SERVER);
|
||||
} catch(Poco::Exception& ex) {
|
||||
printf("Poco Exception by connecting to db: %s\n", ex.displayText().data());
|
||||
}
|
||||
//printf("try connect php server mysql \n");
|
||||
conn->setConnectionsFromConfig(*test_config, CONNECTION_MYSQL_PHP_SERVER);
|
||||
//conn->setConnectionsFromConfig(*test_config, CONNECTION_MYSQL_PHP_SERVER);
|
||||
|
||||
Profiler timeUsed;
|
||||
|
||||
// clean up and fill db
|
||||
std::string tables[] = {
|
||||
std::string tables[] = {
|
||||
"hedera_accounts",
|
||||
"hedera_ids",
|
||||
"crypto_keys",
|
||||
@ -95,8 +98,8 @@ int load() {
|
||||
}
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
|
||||
|
||||
|
||||
fillTests();
|
||||
for (std::list<Test*>::iterator it = gTests.begin(); it != gTests.end(); it++)
|
||||
{
|
||||
@ -125,13 +128,13 @@ void ende()
|
||||
if (*it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
gTests.clear();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (load() < 0) {
|
||||
printf("early exit\n");
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
|
||||
#include "TestTasks.h"
|
||||
#include "TestHash.h"
|
||||
#include "TestRegExp.h"
|
||||
#include "crypto/TestPassphrase.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user