Ok, doing better, but we still have a memory problem in the single default device case.
1.1 --- a/test/include/locked_queue.hh Sun Feb 24 22:41:22 2019 +0100
1.2 +++ b/test/include/locked_queue.hh Mon Feb 25 12:28:51 2019 +0100
1.3 @@ -58,4 +58,4 @@
1.4 return _q.empty();
1.5 }
1.6 };
1.7 -};
1.8 +}
2.1 --- a/test/include/pEpTestDevice.h Sun Feb 24 22:41:22 2019 +0100
2.2 +++ b/test/include/pEpTestDevice.h Mon Feb 25 12:28:51 2019 +0100
2.3 @@ -68,8 +68,8 @@
2.4 string mbox_dir;
2.5 utility::locked_queue<Sync_event_t*> q;
2.6
2.7 - static Sync_event_t* retrieve_next_sync_event(void *management, time_t threshold);
2.8 - static int notify_handshake(pEp_identity *me,
2.9 + static Sync_event_t* retrieve_next_sync_event(void *management, unsigned int threshold);
2.10 + static PEP_STATUS notify_handshake(pEp_identity *me,
2.11 pEp_identity *partner,
2.12 sync_handshake_signal signal);
2.13
2.14 @@ -81,11 +81,11 @@
2.15 // messageToSend_t device_messageToSend;
2.16 // inject_sync_event_t device_inject_sync_event;
2.17 map<string,string> address_to_mbox_map; // maybe string, vector<string>?
2.18 + vector<message*> send_queue;
2.19
2.20 protected:
2.21 string mbox_last_read;
2.22 vector<string> mail_to_read;
2.23 - vector<message*> send_queue;
2.24
2.25 // string current_test_name;
2.26
3.1 --- a/test/src/TestUtils.cc Sun Feb 24 22:41:22 2019 +0100
3.2 +++ b/test/src/TestUtils.cc Mon Feb 25 12:28:51 2019 +0100
3.3 @@ -158,12 +158,20 @@
3.4 return "PEP_INIT_NO_GPG_HOME";
3.5 case PEP_INIT_NETPGP_INIT_FAILED:
3.6 return "PEP_INIT_NETPGP_INIT_FAILED";
3.7 + case PEP_INIT_CANNOT_DETERMINE_GPG_VERSION:
3.8 + return "PEP_INIT_CANNOT_DETERMINE_GPG_VERSION";
3.9 + case PEP_INIT_UNSUPPORTED_GPG_VERSION:
3.10 + return "PEP_INIT_UNSUPPORTED_GPG_VERSION";
3.11 + case PEP_INIT_CANNOT_CONFIG_GPG_AGENT:
3.12 + return "PEP_INIT_CANNOT_CONFIG_GPG_AGENT";
3.13 case PEP_INIT_SQLITE3_WITHOUT_MUTEX:
3.14 return "PEP_INIT_SQLITE3_WITHOUT_MUTEX";
3.15 case PEP_INIT_CANNOT_OPEN_DB:
3.16 return "PEP_INIT_CANNOT_OPEN_DB";
3.17 case PEP_INIT_CANNOT_OPEN_SYSTEM_DB:
3.18 return "PEP_INIT_CANNOT_OPEN_SYSTEM_DB";
3.19 + case PEP_UNKNOWN_DB_ERROR:
3.20 + return "PEP_UNKNOWN_DB_ERROR";
3.21 case PEP_KEY_NOT_FOUND:
3.22 return "PEP_KEY_NOT_FOUND";
3.23 case PEP_KEY_HAS_AMBIG_NAME:
3.24 @@ -174,6 +182,18 @@
3.25 return "PEP_CANNOT_EXPORT_KEY";
3.26 case PEP_CANNOT_EDIT_KEY:
3.27 return "PEP_CANNOT_EDIT_KEY";
3.28 + case PEP_KEY_UNSUITABLE:
3.29 + return "PEP_KEY_UNSUITABLE";
3.30 + case PEP_MALFORMED_KEY_RESET_MSG:
3.31 + return "PEP_MALFORMED_KEY_RESET_MSG";
3.32 + case PEP_KEY_NOT_RESET:
3.33 + return "PEP_KEY_NOT_RESET";
3.34 + case PEP_KEY_IMPORTED:
3.35 + return "PEP_KEY_IMPORTED";
3.36 + case PEP_NO_KEY_IMPORTED:
3.37 + return "PEP_NO_KEY_IMPORTED";
3.38 + case PEP_KEY_IMPORT_STATUS_UNKNOWN:
3.39 + return "PEP_KEY_IMPORT_STATUS_UNKNOWN";
3.40 case PEP_CANNOT_FIND_IDENTITY:
3.41 return "PEP_CANNOT_FIND_IDENTITY";
3.42 case PEP_CANNOT_SET_PERSON:
3.43 @@ -184,6 +204,10 @@
3.44 return "PEP_CANNOT_SET_IDENTITY";
3.45 case PEP_CANNOT_SET_TRUST:
3.46 return "PEP_CANNOT_SET_TRUST";
3.47 + case PEP_CANNOT_FIND_PERSON:
3.48 + return "PEP_CANNOT_FIND_PERSON";
3.49 + case PEP_CANNOT_FIND_ALIAS:
3.50 + return "PEP_CANNOT_FIND_ALIAS";
3.51 case PEP_KEY_BLACKLISTED:
3.52 return "PEP_KEY_BLACKLISTED";
3.53 case PEP_UNENCRYPTED:
3.54 @@ -210,12 +234,16 @@
3.55 return "PEP_VERIFY_NO_KEY";
3.56 case PEP_VERIFIED_AND_TRUSTED:
3.57 return "PEP_VERIFIED_AND_TRUSTED";
3.58 + case PEP_CANNOT_REENCRYPT:
3.59 + return "PEP_CANNOT_REENCRYPT";
3.60 case PEP_CANNOT_DECRYPT_UNKNOWN:
3.61 return "PEP_CANNOT_DECRYPT_UNKNOWN";
3.62 case PEP_TRUSTWORD_NOT_FOUND:
3.63 return "PEP_TRUSTWORD_NOT_FOUND";
3.64 case PEP_TRUSTWORDS_FPR_WRONG_LENGTH:
3.65 return "PEP_TRUSTWORDS_FPR_WRONG_LENGTH";
3.66 + case PEP_TRUSTWORDS_DUPLICATE_FPR:
3.67 + return "PEP_TRUSTWORDS_DUPLICATE_FPR";
3.68 case PEP_CANNOT_CREATE_KEY:
3.69 return "PEP_CANNOT_CREATE_KEY";
3.70 case PEP_CANNOT_SEND_KEY:
3.71 @@ -234,6 +262,12 @@
3.72 return "PEP_SYNC_ILLEGAL_MESSAGE";
3.73 case PEP_SYNC_NO_INJECT_CALLBACK:
3.74 return "PEP_SYNC_NO_INJECT_CALLBACK";
3.75 + case PEP_SYNC_NO_CHANNEL:
3.76 + return "PEP_SYNC_NO_CHANNEL";
3.77 + case PEP_SYNC_CANNOT_ENCRYPT:
3.78 + return "PEP_SYNC_CANNOT_ENCRYPT";
3.79 + case PEP_SYNC_NO_MESSAGE_SEND_CALLBACK:
3.80 + return "PEP_SYNC_NO_MESSAGE_SEND_CALLBACK";
3.81 case PEP_CANNOT_INCREASE_SEQUENCE:
3.82 return "PEP_CANNOT_INCREASE_SEQUENCE";
3.83 case PEP_STATEMACHINE_ERROR:
3.84 @@ -250,6 +284,8 @@
3.85 return "PEP_STATEMACHINE_INVALID_ACTION";
3.86 case PEP_STATEMACHINE_INHIBITED_EVENT:
3.87 return "PEP_STATEMACHINE_INHIBITED_EVENT";
3.88 + case PEP_STATEMACHINE_CANNOT_SEND:
3.89 + return "PEP_STATEMACHINE_CANNOT_SEND";
3.90 case PEP_COMMIT_FAILED:
3.91 return "PEP_COMMIT_FAILED";
3.92 case PEP_MESSAGE_CONSUME:
3.93 @@ -267,9 +303,10 @@
3.94 case PEP_OUT_OF_MEMORY:
3.95 return "PEP_OUT_OF_MEMORY";
3.96 case PEP_UNKNOWN_ERROR:
3.97 - return "PEP_UNKNOWN_ERROR";
3.98 + return "PEP_UNKNOWN_ERROR";
3.99 + case PEP_VERSION_MISMATCH:
3.100 + return "PEP_VERSION_MISMATCH";
3.101 default:
3.102 -
3.103 return "PEP_STATUS_OMGWTFBBQ - This means you're using a status the test lib doesn't know about!";
3.104 }
3.105 }
4.1 --- a/test/src/engine_tests/KeyResetMessageTests.cc Sun Feb 24 22:41:22 2019 +0100
4.2 +++ b/test/src/engine_tests/KeyResetMessageTests.cc Mon Feb 25 12:28:51 2019 +0100
4.3 @@ -48,21 +48,21 @@
4.4 fake_this = this;
4.5 }
4.6
4.7 -PEP_STATUS KeyResetMessageTests::message_send_callback(message* msg) {
4.8 - fake_this->m_queue.push_back(msg);
4.9 - return PEP_STATUS_OK;
4.10 -}
4.11 +// PEP_STATUS KeyResetMessageTests::message_send_callback(message* msg) {
4.12 +// fake_this->device->send_queue.push_back(msg);
4.13 +// return PEP_STATUS_OK;
4.14 +// }
4.15
4.16 void KeyResetMessageTests::setup() {
4.17 EngineTestIndividualSuite::setup();
4.18 - m_queue.clear();
4.19 - device->device_messageToSend = &KeyResetMessageTests::message_send_callback;
4.20 - session->messageToSend = device->device_messageToSend;
4.21 +// device->send_queue.clear();
4.22 +// device->message_to_send = &KeyResetMessageTests::message_send_callback;
4.23 +// session->messageToSend = device->message_to_send;
4.24 }
4.25
4.26 void KeyResetMessageTests::tear_down() {
4.27 - device->device_messageToSend = NULL;
4.28 - session->messageToSend = NULL;
4.29 +// device->device_messageToSend = NULL;
4.30 +// session->messageToSend = NULL;
4.31 EngineTestIndividualSuite::tear_down();
4.32 }
4.33
4.34 @@ -176,8 +176,9 @@
4.35 outgoing_msg->to = send_idents;
4.36 outgoing_msg->shortmsg = strdup("Well isn't THIS a useless message...");
4.37 outgoing_msg->longmsg = strdup("Hi Mom...\n");
4.38 - // outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
4.39 - // that's illegal - VB.
4.40 + outgoing_msg->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
4.41 + // that's illegal - VB.
4.42 + // I got this from your tests, and IIRC, there was some reason you guys always put it in there. - KB
4.43 cout << "Message created.\n\n";
4.44 cout << "Encrypting message as MIME multipart…\n";
4.45 message* enc_outgoing_msg = nullptr;
4.46 @@ -210,7 +211,7 @@
4.47
4.48 status = key_reset(session, alice_fpr, from_ident);
4.49 TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
4.50 - TEST_ASSERT(m_queue.size() > 0);
4.51 + TEST_ASSERT(device->send_queue.size() > 0);
4.52 status = myself(session, from_ident);
4.53 string new_fpr = from_ident->fpr;
4.54 TEST_ASSERT_MSG((strcmp(alice_fpr, new_fpr.c_str()) != 0), new_fpr.c_str());
4.55 @@ -224,9 +225,9 @@
4.56 hashmap[fenris_user_id] = false;
4.57
4.58 // Number of messages we SHOULD be sending.
4.59 - TEST_ASSERT(m_queue.size() == 4);
4.60 + TEST_ASSERT(device->send_queue.size() == 4);
4.61
4.62 - for (vector<message*>::iterator it = m_queue.begin(); it != m_queue.end(); it++) {
4.63 + for (vector<message*>::iterator it = device->send_queue.begin(); it != device->send_queue.end(); it++) {
4.64 message* curr_sent_msg = *it;
4.65 TEST_ASSERT(curr_sent_msg);
4.66 TEST_ASSERT(curr_sent_msg->to);
4.67 @@ -256,7 +257,7 @@
4.68 }
4.69
4.70 // MESSAGE LIST NOW INVALID.
4.71 - m_queue.clear();
4.72 + device->send_queue.clear();
4.73
4.74 // Make sure we have messages only to desired recips
4.75 TEST_ASSERT(hashmap[alice_user_id] == false);
4.76 @@ -423,7 +424,7 @@
4.77
4.78 status = key_reset(session, alice_fpr, from_ident);
4.79 TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
4.80 - m_queue.clear();
4.81 + device->send_queue.clear();
4.82
4.83 string received_mail = slurp("test_files/398_gabrielle_to_alice.eml");
4.84 char* decrypted_msg = NULL;
4.85 @@ -433,7 +434,7 @@
4.86 PEP_decrypt_flags_t flags;
4.87 status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
4.88 &decrypted_msg, &keylist, &rating, &flags, &modified_src);
4.89 - TEST_ASSERT(m_queue.size() == 0);
4.90 + TEST_ASSERT(device->send_queue.size() == 0);
4.91 free(decrypted_msg);
4.92 free(modified_src);
4.93 free_stringlist(keylist);
4.94 @@ -487,8 +488,8 @@
4.95
4.96 status = key_reset(session, alice_fpr, from_ident);
4.97 TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
4.98 - TEST_ASSERT(m_queue.size() == 0);
4.99 - m_queue.clear();
4.100 + TEST_ASSERT(device->send_queue.size() == 0);
4.101 + device->send_queue.clear();
4.102
4.103 // Now we get mail from Gabi, who only has our old key AND has become
4.104 // a pEp user in the meantime...
4.105 @@ -501,8 +502,8 @@
4.106 status = MIME_decrypt_message(session, received_mail.c_str(), received_mail.size(),
4.107 &decrypted_msg, &keylist, &rating, &flags, &modified_src);
4.108
4.109 - TEST_ASSERT(m_queue.size() == 1);
4.110 - vector<message*>::iterator it = m_queue.begin();
4.111 + TEST_ASSERT(device->send_queue.size() == 1);
4.112 + vector<message*>::iterator it = device->send_queue.begin();
4.113 message* reset_msg = *it;
4.114 TEST_ASSERT(reset_msg);
4.115 TEST_ASSERT(reset_msg->from);
5.1 --- a/test/src/pEpTestDevice.cc Sun Feb 24 22:41:22 2019 +0100
5.2 +++ b/test/src/pEpTestDevice.cc Mon Feb 25 12:28:51 2019 +0100
5.3 @@ -27,8 +27,78 @@
5.4 #include "KeySync_fsm.h"
5.5 #include <chrono>
5.6
5.7 +// Static stuff
5.8 pEpTestDevice* pEpTestDevice::active = NULL;
5.9
5.10 +PEP_STATUS pEpTestDevice::message_to_send(struct _message* msg) {
5.11 + pEpTestDevice::active->add_message_to_send_queue(msg);
5.12 + return PEP_STATUS_OK;
5.13 +}
5.14 +
5.15 +PEP_STATUS pEpTestDevice::notify_handshake(pEp_identity* me,
5.16 + pEp_identity* partner,
5.17 + sync_handshake_signal signal) {
5.18 + //
5.19 + // switch(signal) {
5.20 + // case SYNC_NOTIFY_UNDEFINED:
5.21 + // case SYNC_NOTIFY_TIMEOUT:
5.22 + // case SYNC_NOTIFY_OVERTAKEN:
5.23 + // case SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED:
5.24 + // case SYNC_NOTIFY_ACCEPTED_GROUP_CREATED:
5.25 + // case SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED:
5.26 + // return SYNC_HANDSHAKE_CANCEL;
5.27 + //
5.28 + // // We don't simulate the handshake process here.
5.29 + // // If we need to, this is a TODO.
5.30 + // case SYNC_NOTIFY_INIT_ADD_OUR_DEVICE:
5.31 + // case SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE:
5.32 + // case SYNC_NOTIFY_INIT_FORM_GROUP:
5.33 + // case SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE:
5.34 + // return SYNC_HANDSHAKE_ACCEPTED;
5.35 + //
5.36 + // default:
5.37 + // return SYNC_HANDSHAKE_REJECTED;
5.38 + // }
5.39 + return PEP_STATUS_OK;
5.40 +}
5.41 +
5.42 +Sync_event_t* pEpTestDevice::retrieve_next_sync_event(void *management, unsigned int threshold)
5.43 +{
5.44 + time_t started = time(nullptr);
5.45 + bool timeout = false;
5.46 +
5.47 + while (active->q.empty()) {
5.48 + int i = 0;
5.49 + ++i;
5.50 + if (i > 10) {
5.51 + if (time(nullptr) > started + threshold) {
5.52 + timeout = true;
5.53 + break;
5.54 + }
5.55 + i = 0;
5.56 + }
5.57 + nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
5.58 + }
5.59 + if (timeout)
5.60 + return new_sync_timeout_event();
5.61 +
5.62 + return pEpTestDevice::active->q.pop_front();
5.63 +}
5.64 +
5.65 +int pEpTestDevice::inject_sync_event(Sync_event* ev, void* management) {
5.66 + Sync_event_t *_ev = ev;
5.67 + switch (_ev->fsm) {
5.68 + case Sync_PR_keysync:
5.69 +// cout << "injecting event " << KeySync_event_name(_ev->event) << "\n";
5.70 + break;
5.71 + default:
5.72 + throw std::runtime_error("Unknown state machine.");
5.73 + }
5.74 + pEpTestDevice::active->q.push_front(ev);
5.75 + return 0;
5.76 +}
5.77 +// End static stuff
5.78 +
5.79 pEpTestDevice::pEpTestDevice(string test_dir,
5.80 string my_name)
5.81 {
5.82 @@ -102,7 +172,7 @@
5.83 gpg_conf(true);
5.84 gpg_agent_conf(true);
5.85
5.86 - PEP_STATUS status = init(session, message_to_send, inject_sync_event);
5.87 + PEP_STATUS status = init(&session, message_to_send, inject_sync_event);
5.88 if (status != PEP_STATUS_OK)
5.89 throw std::runtime_error("init() exploded! Bad!");
5.90 status = register_sync_callbacks(session, (void*)(&(active->q)),
5.91 @@ -339,69 +409,4 @@
5.92 send_queue.push_back(msg);
5.93 }
5.94
5.95 -PEP_STATUS pEpTestDevice::message_to_send(struct _message* msg) {
5.96 - pEpTestDevice::active->add_message_to_send_queue(msg);
5.97 -}
5.98 -
5.99 -int pEpTestDevice::notify_handshake(pEp_identity* me,
5.100 - pEp_identity* partner,
5.101 - sync_handshake_signal signal) {
5.102 -
5.103 - switch(signal) {
5.104 - case SYNC_NOTIFY_UNDEFINED:
5.105 - case SYNC_NOTIFY_TIMEOUT:
5.106 - case SYNC_NOTIFY_OVERTAKEN:
5.107 - case SYNC_NOTIFY_ACCEPTED_DEVICE_ADDED:
5.108 - case SYNC_NOTIFY_ACCEPTED_GROUP_CREATED:
5.109 - case SYNC_NOTIFY_ACCEPTED_DEVICE_MOVED:
5.110 - return SYNC_HANDSHAKE_CANCEL;
5.111 -
5.112 - // We don't simulate the handshake process here.
5.113 - // If we need to, this is a TODO.
5.114 - case SYNC_NOTIFY_INIT_ADD_OUR_DEVICE:
5.115 - case SYNC_NOTIFY_INIT_ADD_OTHER_DEVICE:
5.116 - case SYNC_NOTIFY_INIT_FORM_GROUP:
5.117 - case SYNC_NOTIFY_INIT_MOVE_OUR_DEVICE:
5.118 - return SYNC_HANDSHAKE_ACCEPTED;
5.119 -
5.120 - default:
5.121 - return SYNC_HANDSHAKE_REJECTED;
5.122 - }
5.123 -}
5.124 -
5.125 -Sync_event_t* pEpTestDevice::retrieve_next_sync_event(void *management, time_t threshold)
5.126 -{
5.127 - time_t started = time(nullptr);
5.128 - bool timeout = false;
5.129
5.130 - while (active->q.empty()) {
5.131 - int i = 0;
5.132 - ++i;
5.133 - if (i > 10) {
5.134 - if (time(nullptr) > started + threshold) {
5.135 - timeout = true;
5.136 - break;
5.137 - }
5.138 - i = 0;
5.139 - }
5.140 - nanosleep((const struct timespec[]){{0, 100000000L}}, NULL);
5.141 - }
5.142 - if (timeout)
5.143 - return new_sync_timeout_event();
5.144 -
5.145 - return pEpTestDevice::active->q.pop_front();
5.146 -}
5.147 -
5.148 -int inject_sync_event(SYNC_EVENT ev, void* management) {
5.149 - Sync_event_t *_ev = ev;
5.150 - switch (_ev->fsm) {
5.151 - case Sync_PR_keysync:
5.152 -// cout << "injecting event " << KeySync_event_name(_ev->event) << "\n";
5.153 - break;
5.154 - default:
5.155 - throw std::runtime_error("Unknown state machine.");
5.156 - }
5.157 - pEpTestDevice::active->q.push_front(ev);
5.158 - return 0;
5.159 -}
5.160 -