Tests for ENGINE-527 (checks on username)
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 20 Mar 2019 15:26:06 +0100
changeset 3351b9c0efacb652
parent 3350 1c117fa0df8e
child 3352 9f804c455d21
child 3402 2ed9ae4bb6e8
Tests for ENGINE-527 (checks on username)
test/include/NoOwnIdentWritesOnDecryptTests.h
test/src/engine_tests/NoOwnIdentWritesOnDecryptTests.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/include/NoOwnIdentWritesOnDecryptTests.h	Wed Mar 20 15:26:06 2019 +0100
     1.3 @@ -0,0 +1,25 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#ifndef NO_OWN_IDENT_WRITES_ON_DECRYPT_H
     1.8 +#define NO_OWN_IDENT_WRITES_ON_DECRYPT_H
     1.9 +
    1.10 +#include <string>
    1.11 +#include "EngineTestIndividualSuite.h"
    1.12 +#include "pEpEngine.h"
    1.13 +#include "message.h"
    1.14 +
    1.15 +using namespace std;
    1.16 +
    1.17 +class NoOwnIdentWritesOnDecryptTests : public EngineTestIndividualSuite {
    1.18 +    public:
    1.19 +        NoOwnIdentWritesOnDecryptTests(string test_suite, string test_home_dir);
    1.20 +        ~NoOwnIdentWritesOnDecryptTests();
    1.21 +        message* _to_decrypt;
    1.22 +    private:
    1.23 +        void check_no_own_ident_writes_on_decrypt();        
    1.24 +        void check_address_only_no_overwrite();
    1.25 +        void check_full_info_no_overwrite();
    1.26 +};
    1.27 +
    1.28 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/src/engine_tests/NoOwnIdentWritesOnDecryptTests.cc	Wed Mar 20 15:26:06 2019 +0100
     2.3 @@ -0,0 +1,168 @@
     2.4 +// This file is under GNU General Public License 3.0
     2.5 +// see LICENSE.txt
     2.6 +
     2.7 +#include <stdlib.h>
     2.8 +#include <string>
     2.9 +#include <cstring>
    2.10 +#include <cpptest.h>
    2.11 +
    2.12 +#include "pEpEngine.h"
    2.13 +#include "test_util.h"
    2.14 +
    2.15 +#include "EngineTestIndividualSuite.h"
    2.16 +#include "NoOwnIdentWritesOnDecryptTests.h"
    2.17 +
    2.18 +using namespace std;
    2.19 +
    2.20 +NoOwnIdentWritesOnDecryptTests::NoOwnIdentWritesOnDecryptTests(string suitename, string test_home_dir) :
    2.21 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    2.22 +    _to_decrypt = NULL;
    2.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NoOwnIdentWritesOnDecryptTests::check_no_own_ident_writes_on_decrypt"),
    2.24 +                                                                      static_cast<Func>(&NoOwnIdentWritesOnDecryptTests::check_no_own_ident_writes_on_decrypt)));
    2.25 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NoOwnIdentWritesOnDecryptTests::check_address_only_no_overwrite"),
    2.26 +                                                                      static_cast<Func>(&NoOwnIdentWritesOnDecryptTests::check_address_only_no_overwrite)));
    2.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("NoOwnIdentWritesOnDecryptTests::check_full_info_no_overwrite"),
    2.28 +                                                                      static_cast<Func>(&NoOwnIdentWritesOnDecryptTests::check_full_info_no_overwrite)));
    2.29 +}
    2.30 +
    2.31 +NoOwnIdentWritesOnDecryptTests::~NoOwnIdentWritesOnDecryptTests() {
    2.32 +    free_message(_to_decrypt);
    2.33 +}
    2.34 +
    2.35 +void NoOwnIdentWritesOnDecryptTests::check_no_own_ident_writes_on_decrypt() {
    2.36 +    // This is a weird case - it is NOT a test case, it's just abusing the environment to
    2.37 +    // set _to_decrypt without polluting test keyrings for later tests.
    2.38 +    message* msg = new_message(PEP_dir_outgoing);
    2.39 +    pEp_identity* sender = NULL;
    2.40 +    pEp_identity* me_recip = NULL;
    2.41 +    pEp_identity* other_recip = NULL;
    2.42 +    
    2.43 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));
    2.44 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc"));	
    2.45 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"));
    2.46 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc"));
    2.47 +    
    2.48 +    sender = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice");
    2.49 +    set_own_key(session, sender, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97");
    2.50 +    myself(session, sender);
    2.51 +    
    2.52 +    me_recip = new_identity("pep.test.bob@pep-project.org", NULL, "Bob_is_hot", "Hot Bob");
    2.53 +    other_recip = new_identity("pep-test-carol@pep-project.org", NULL, "Carol_loves_me", "Carol Loves Alice");
    2.54 +
    2.55 +    identity_list* to_list = new_identity_list(other_recip);
    2.56 +    identity_list_add(to_list, me_recip);
    2.57 +    
    2.58 +    msg->from = sender;
    2.59 +    msg->to = to_list;
    2.60 +    
    2.61 +    msg->shortmsg = strdup("just a message");
    2.62 +    msg->longmsg = strdup("a really dumb message");
    2.63 +    
    2.64 +    message* enc_msg = NULL;
    2.65 +    
    2.66 +    PEP_STATUS status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    2.67 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.68 +    free_message(msg);
    2.69 +    enc_msg->dir = PEP_dir_incoming;
    2.70 +    _to_decrypt = enc_msg;
    2.71 +    TEST_ASSERT(true);
    2.72 +}
    2.73 +
    2.74 +void NoOwnIdentWritesOnDecryptTests::check_address_only_no_overwrite() {
    2.75 +    TEST_ASSERT(_to_decrypt);
    2.76 +    message* copy = message_dup(_to_decrypt);
    2.77 +
    2.78 +    free_identity(copy->from);
    2.79 +    
    2.80 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));
    2.81 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"));
    2.82 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc"));
    2.83 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc"));
    2.84 +    
    2.85 +    const char* bob_name = "STOP MESSING WITH ME ALICE";
    2.86 +    const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
    2.87 +    pEp_identity* me = new_identity("pep.test.bob@pep-project.org", NULL, PEP_OWN_USERID, bob_name);
    2.88 +    PEP_STATUS status = set_own_key(session, me, bob_fpr);
    2.89 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.90 +    status = myself(session, me);
    2.91 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.92 +    free_identity(me);
    2.93 +    me = NULL;
    2.94 +    
    2.95 +    copy->from = new_identity("pep.test.alice@pep-project.org", NULL, NULL, NULL);
    2.96 +    pEp_identity* bob_ident = copy->to->next->ident;
    2.97 +    free(bob_ident->fpr);
    2.98 +    free(bob_ident->user_id);
    2.99 +    bob_ident->fpr = NULL;
   2.100 +    bob_ident->user_id = NULL;
   2.101 +    
   2.102 +    // yes, I know the test keeps the "old" user_id for carol, but it's irrelevant here/
   2.103 +
   2.104 +    message* dec_msg = NULL;
   2.105 +    stringlist_t* keylist = NULL;
   2.106 +    PEP_decrypt_flags_t flags = 0;
   2.107 +    PEP_rating rating = PEP_rating_undefined;
   2.108 +    
   2.109 +    status = decrypt_message(session, copy, &dec_msg, &keylist, &rating, &flags);    
   2.110 +    TEST_ASSERT(status == PEP_STATUS_OK);
   2.111 +    TEST_ASSERT(strcmp(dec_msg->to->next->ident->username, "Hot Bob") == 0);
   2.112 +    
   2.113 +    // Make sure Alice calling Bob hot doesn't infiltrate his DB
   2.114 +    status = get_identity(session, "pep.test.bob@pep-project.org", PEP_OWN_USERID, &me);
   2.115 +    TEST_ASSERT(status == PEP_STATUS_OK);
   2.116 +    TEST_ASSERT(me);
   2.117 +    TEST_ASSERT(strcmp(me->username, bob_name) == 0);
   2.118 +    TEST_ASSERT(strcmp(me->fpr, bob_fpr) == 0);
   2.119 +    free_identity(me);
   2.120 +    free_message(dec_msg);
   2.121 +    free_message(copy);
   2.122 +}
   2.123 +
   2.124 +void NoOwnIdentWritesOnDecryptTests::check_full_info_no_overwrite() {
   2.125 +    TEST_ASSERT(_to_decrypt);
   2.126 +    message* copy = message_dup(_to_decrypt);
   2.127 +
   2.128 +    free_identity(copy->from);
   2.129 +    
   2.130 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc"));
   2.131 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"));
   2.132 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc"));
   2.133 +    TEST_ASSERT(slurp_and_import_key(session, "test_keys/pub/pep-test-carol-0x42A85A42_pub.asc"));
   2.134 +    
   2.135 +    const char* bob_name = "STOP MESSING WITH ME ALICE";
   2.136 +    const char* bob_fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
   2.137 +    pEp_identity* me = new_identity("pep.test.bob@pep-project.org", NULL, PEP_OWN_USERID, bob_name);
   2.138 +    PEP_STATUS status = set_own_key(session, me, bob_fpr);
   2.139 +    TEST_ASSERT(status == PEP_STATUS_OK);
   2.140 +    status = myself(session, me);
   2.141 +    TEST_ASSERT(status == PEP_STATUS_OK);
   2.142 +    free_identity(me);
   2.143 +    me = NULL;
   2.144 +    
   2.145 +    copy->from = new_identity("pep.test.alice@pep-project.org", NULL, NULL, NULL);
   2.146 +    pEp_identity* bob_ident = copy->to->next->ident;
   2.147 +    free(bob_ident->user_id);
   2.148 +    bob_ident->user_id = strdup(PEP_OWN_USERID);
   2.149 +    bob_ident->me = true;
   2.150 +    
   2.151 +    // yes, I know the test keeps the "old" user_id for carol, but it's irrelevant here
   2.152 +    message* dec_msg = NULL;
   2.153 +    stringlist_t* keylist = NULL;
   2.154 +    PEP_decrypt_flags_t flags = 0;
   2.155 +    PEP_rating rating = PEP_rating_undefined;
   2.156 +    
   2.157 +    status = decrypt_message(session, copy, &dec_msg, &keylist, &rating, &flags);    
   2.158 +    TEST_ASSERT(status == PEP_STATUS_OK);
   2.159 +    TEST_ASSERT(strcmp(dec_msg->to->next->ident->username, "Hot Bob") == 0);
   2.160 +    
   2.161 +    // Make sure Alice calling Bob hot doesn't infiltrate his DB
   2.162 +    status = get_identity(session, "pep.test.bob@pep-project.org", PEP_OWN_USERID, &me);
   2.163 +    TEST_ASSERT(status == PEP_STATUS_OK);
   2.164 +    TEST_ASSERT(me);
   2.165 +    TEST_ASSERT(strcmp(me->username, bob_name) == 0);
   2.166 +    TEST_ASSERT(strcmp(me->fpr, bob_fpr) == 0);
   2.167 +    free_identity(me);
   2.168 +    free_message(dec_msg);
   2.169 +
   2.170 +    free_message(copy);
   2.171 +}