ENGINE-398: expanded test, fixed mem error ENGINE-398
authorKrista Bennett <krista@pep-project.org>
Mon, 03 Sep 2018 08:36:48 +0200
branchENGINE-398
changeset 2920aa7662073dc0
parent 2919 9c310d0b45c2
child 2924 fea58c0a9fd8
ENGINE-398: expanded test, fixed mem error
src/message_api.c
test/Makefile
test/include/KeyResetMessageTests.h
test/src/engine_tests/KeyResetMessageTests.cc
     1.1 --- a/src/message_api.c	Sat Sep 01 17:25:56 2018 +0200
     1.2 +++ b/src/message_api.c	Mon Sep 03 08:36:48 2018 +0200
     1.3 @@ -1633,14 +1633,18 @@
     1.4                                                       revoke_fpr,
     1.5                                                       new_fpr);
     1.6  
     1.7 -        if (status != PEP_STATUS_OK)
     1.8 +        if (status != PEP_STATUS_OK) {
     1.9 +            free(reset_msg);
    1.10              goto pep_free;
    1.11 +        }
    1.12          
    1.13          // insert into queue
    1.14          status = send_cb(sync_obj, reset_msg);
    1.15  
    1.16 -        if (status != PEP_STATUS_OK)
    1.17 -            goto pep_free;
    1.18 +        if (status != PEP_STATUS_OK) {
    1.19 +            free(reset_msg);
    1.20 +            goto pep_free;            
    1.21 +        }
    1.22              
    1.23          // Put into notified DB
    1.24          status = set_reset_contact_notified(session, revoke_fpr, user_id);
    1.25 @@ -1650,7 +1654,6 @@
    1.26      
    1.27  pep_free:
    1.28      free_identity_list(recent_contacts);
    1.29 -    free_message(reset_msg);
    1.30      return status;
    1.31  }
    1.32  
     2.1 --- a/test/Makefile	Sat Sep 01 17:25:56 2018 +0200
     2.2 +++ b/test/Makefile	Mon Sep 03 08:36:48 2018 +0200
     2.3 @@ -48,7 +48,7 @@
     2.4  	LLDB_BIN=lldb
     2.5  endif
     2.6  
     2.7 -LDLIBS+= -lcpptest
     2.8 +LDLIBS+= -lcpptest -lefence
     2.9  
    2.10  
    2.11  # Create a list of the extra library paths for the loader. I do not assume that the engine (and its dependencies) are installed for testing.
     3.1 --- a/test/include/KeyResetMessageTests.h	Sat Sep 01 17:25:56 2018 +0200
     3.2 +++ b/test/include/KeyResetMessageTests.h	Mon Sep 03 08:36:48 2018 +0200
     3.3 @@ -21,6 +21,13 @@
     3.4          
     3.5          static constexpr const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
     3.6  
     3.7 +        static const string alice_user_id;
     3.8 +        static const string bob_user_id;    
     3.9 +        static const string carol_user_id;
    3.10 +        static const string dave_user_id;
    3.11 +        static const string erin_user_id;
    3.12 +        static const string fenris_user_id;
    3.13 +
    3.14      protected:
    3.15          void setup();
    3.16                  
    3.17 @@ -35,6 +42,7 @@
    3.18          
    3.19          void send_setup();
    3.20          void receive_setup();     
    3.21 +        
    3.22  };
    3.23  
    3.24  #endif
     4.1 --- a/test/src/engine_tests/KeyResetMessageTests.cc	Sat Sep 01 17:25:56 2018 +0200
     4.2 +++ b/test/src/engine_tests/KeyResetMessageTests.cc	Mon Sep 03 08:36:48 2018 +0200
     4.3 @@ -3,6 +3,8 @@
     4.4  
     4.5  #include <stdlib.h>
     4.6  #include <string>
     4.7 +#include <vector>
     4.8 +#include <unordered_map>
     4.9  #include <assert.h>
    4.10  
    4.11  #include "pEpEngine.h"
    4.12 @@ -14,8 +16,16 @@
    4.13  
    4.14  using namespace std;
    4.15  
    4.16 +const string KeyResetMessageTests::alice_user_id = PEP_OWN_USERID;
    4.17 +const string KeyResetMessageTests::bob_user_id = "BobId";    
    4.18 +const string KeyResetMessageTests::carol_user_id = "carolId";
    4.19 +const string KeyResetMessageTests::dave_user_id = "DaveId";
    4.20 +const string KeyResetMessageTests::erin_user_id = "ErinErinErin";
    4.21 +const string KeyResetMessageTests::fenris_user_id = "BadWolf";
    4.22 +
    4.23  KeyResetMessageTests::KeyResetMessageTests(string suitename, string test_home_dir) :
    4.24      EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    4.25 +        
    4.26      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_key_reset_message"),
    4.27                                                                        static_cast<Func>(&KeyResetMessageTests::check_key_reset_message)));
    4.28      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("KeyResetMessageTests::check_reset_key_and_notify"),
    4.29 @@ -51,41 +61,41 @@
    4.30      status = set_up_ident_from_scratch(session,
    4.31                  "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
    4.32                  "pep.test.alice@pep-project.org", alice_fpr, 
    4.33 -                PEP_OWN_USERID, "Alice in Wonderland", NULL, true
    4.34 +                alice_user_id.c_str(), "Alice in Wonderland", NULL, true
    4.35              );
    4.36      assert(status == PEP_STATUS_OK);
    4.37      
    4.38      status = set_up_ident_from_scratch(session,
    4.39                  "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc",
    4.40 -                "pep.test.bob@pep-project.org", NULL, "BobId", "Bob's Burgers",
    4.41 +                "pep.test.bob@pep-project.org", NULL, bob_user_id.c_str(), "Bob's Burgers",
    4.42                  NULL, false
    4.43              );
    4.44      assert(status == PEP_STATUS_OK);
    4.45              
    4.46      status = set_up_ident_from_scratch(session,
    4.47                  "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc",
    4.48 -                "pep-test-carol@pep-project.org", NULL, "carolId", "Carol Burnett",
    4.49 +                "pep-test-carol@pep-project.org", NULL, carol_user_id.c_str(), "Carol Burnett",
    4.50                  NULL, false
    4.51              );
    4.52      assert(status == PEP_STATUS_OK);
    4.53      
    4.54      status = set_up_ident_from_scratch(session,
    4.55                  "test_keys/pub/pep-test-dave-0xBB5BCCF6_pub.asc",
    4.56 -                "pep-test-dave@pep-project.org", NULL, "DaveId", 
    4.57 +                "pep-test-dave@pep-project.org", NULL, dave_user_id.c_str(), 
    4.58                  "David Hasselhoff (Germans Love Me)", NULL, false
    4.59              );
    4.60      assert(status == PEP_STATUS_OK);
    4.61  
    4.62      status = set_up_ident_from_scratch(session,
    4.63                  "test_keys/pub/pep-test-erin-0x9F8D7CBA_pub.asc",
    4.64 -                "pep-test-erin@pep-project.org", NULL, "ErinErinErin", 
    4.65 +                "pep-test-erin@pep-project.org", NULL, erin_user_id.c_str(), 
    4.66                  "Éirinn go Brách", NULL, false
    4.67              );
    4.68      assert(status == PEP_STATUS_OK);
    4.69  
    4.70      status = set_up_ident_from_scratch(session,
    4.71                  "test_keys/pub/pep.test.fenris-0x4F3D2900_pub.asc",
    4.72 -                "pep.test.fenris@thisstilldoesntwork.lu", NULL, "BadWolf", 
    4.73 +                "pep.test.fenris@thisstilldoesntwork.lu", NULL, fenris_user_id.c_str(), 
    4.74                  "Fenris Leto Hawke", NULL, false
    4.75              );
    4.76      assert(status == PEP_STATUS_OK);
    4.77 @@ -140,7 +150,7 @@
    4.78      // If this all worked, we should have a list of recent guys in our DB which, when we reset Alice's 
    4.79      // key, will get sent some nice key reset messages.
    4.80      // But... we need to have one look like an older message. So. Time to mess with the DB.
    4.81 -    // Dave is our victim. Because friend called Dave, who is actually a nice dude, but it amuses me.
    4.82 +    // Dave is our victim. Because I have a friend called Dave, who is actually a nice dude, but it amuses me.
    4.83      // (Note: said friend is NOT David Hasselhoff. To my knowledge. Hi Dave!)
    4.84      //
    4.85      // update identity
    4.86 @@ -161,6 +171,37 @@
    4.87      TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    4.88      TEST_ASSERT(m_queue.size() > 0);
    4.89      
    4.90 +    unordered_map<string, bool> hashmap;
    4.91 +    hashmap[alice_user_id] = false;
    4.92 +    hashmap[bob_user_id] = false;
    4.93 +    hashmap[carol_user_id] = false;
    4.94 +    hashmap[dave_user_id] = false;
    4.95 +    hashmap[erin_user_id] = false;
    4.96 +    hashmap[fenris_user_id] = false;
    4.97 +    
    4.98 +    for (vector<message*>::iterator it = m_queue.begin(); it != m_queue.end(); it++) {
    4.99 +        message* curr_sent_msg = *it;
   4.100 +        TEST_ASSERT(curr_sent_msg);
   4.101 +        TEST_ASSERT(curr_sent_msg->to);
   4.102 +        TEST_ASSERT(curr_sent_msg->to->ident);
   4.103 +        TEST_ASSERT(!(curr_sent_msg->to->next));
   4.104 +        pEp_identity* to = curr_sent_msg->to->ident;
   4.105 +        TEST_ASSERT(to);
   4.106 +        TEST_ASSERT(to->user_id);
   4.107 +        
   4.108 +        unordered_map<string, bool>::iterator jt = hashmap.find(to->user_id);
   4.109 +        
   4.110 +        TEST_ASSERT(jt != hashmap.end());
   4.111 +        hashmap[jt->first] = true;        
   4.112 +    }
   4.113 +    
   4.114 +    TEST_ASSERT(hashmap[alice_user_id] == false);
   4.115 +    TEST_ASSERT(hashmap[bob_user_id] == true);
   4.116 +    TEST_ASSERT(hashmap[carol_user_id] == true);
   4.117 +    TEST_ASSERT(hashmap[dave_user_id] == false);
   4.118 +    TEST_ASSERT(hashmap[erin_user_id] == true);
   4.119 +    TEST_ASSERT(hashmap[fenris_user_id] == true);
   4.120 +    
   4.121      TEST_ASSERT(true);
   4.122  }
   4.123