ENGINE-473: added tests ENGINE-473
authorKrista Bennett <krista@pep-project.org>
Fri, 19 Oct 2018 11:33:45 +0200
branchENGINE-473
changeset 3072a02a5b80c92a
parent 3071 aae2e2a9ad63
child 3092 389d6b6c204c
ENGINE-473: added tests
test/include/CheckRenewedExpiredKeyTrustStatusTests.h
test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/include/CheckRenewedExpiredKeyTrustStatusTests.h	Fri Oct 19 11:33:45 2018 +0200
     1.3 @@ -0,0 +1,22 @@
     1.4 +// This file is under GNU General Public License 3.0
     1.5 +// see LICENSE.txt
     1.6 +
     1.7 +#ifndef CHECK_RENEWED_EXPIRED_KEY_TRUST_STATUS_H
     1.8 +#define CHECK_RENEWED_EXPIRED_KEY_TRUST_STATUS_H
     1.9 +
    1.10 +#include <string>
    1.11 +#include "EngineTestIndividualSuite.h"
    1.12 +
    1.13 +using namespace std;
    1.14 +
    1.15 +class CheckRenewedExpiredKeyTrustStatusTests : public EngineTestIndividualSuite {
    1.16 +    public:
    1.17 +        CheckRenewedExpiredKeyTrustStatusTests(string test_suite, string test_home_dir);
    1.18 +    private:
    1.19 +        void check_renewed_expired_key_trust_status();
    1.20 +        void check_renewed_expired_key_trust_status_trusted_user();
    1.21 +        void check_renewed_expired_key_trust_status_pEp_user();
    1.22 +        void check_renewed_expired_key_trust_status_trusted_pEp_user();        
    1.23 +};
    1.24 +
    1.25 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/src/engine_tests/CheckRenewedExpiredKeyTrustStatusTests.cc	Fri Oct 19 11:33:45 2018 +0200
     2.3 @@ -0,0 +1,289 @@
     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 +
    2.11 +#include "pEpEngine.h"
    2.12 +
    2.13 +#include <cpptest.h>
    2.14 +#include "test_util.h"
    2.15 +#include "EngineTestIndividualSuite.h"
    2.16 +#include "CheckRenewedExpiredKeyTrustStatusTests.h"
    2.17 +
    2.18 +using namespace std;
    2.19 +
    2.20 +CheckRenewedExpiredKeyTrustStatusTests::CheckRenewedExpiredKeyTrustStatusTests(string suitename, string test_home_dir) :
    2.21 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    2.22 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status"),
    2.23 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status)));
    2.24 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user"),
    2.25 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user)));
    2.26 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user"),
    2.27 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user)));
    2.28 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user"),
    2.29 +                                                                      static_cast<Func>(&CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user)));                                                                  
    2.30 +}
    2.31 +
    2.32 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status() {
    2.33 +    bool ok = false;
    2.34 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    2.35 +    TEST_ASSERT(ok);    
    2.36 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
    2.37 +    TEST_ASSERT(ok);
    2.38 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
    2.39 +    TEST_ASSERT(ok);
    2.40 +
    2.41 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    2.42 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
    2.43 +
    2.44 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
    2.45 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    2.46 +
    2.47 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
    2.48 +    // the expired key:
    2.49 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
    2.50 +    
    2.51 +    char* decrypted_msg = NULL;
    2.52 +    stringlist_t* keylist_used = nullptr;
    2.53 +    char* modified_src = NULL;
    2.54 +    
    2.55 +    PEP_rating rating;
    2.56 +    PEP_decrypt_flags_t flags = 0;
    2.57 +     
    2.58 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
    2.59 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
    2.60 +
    2.61 +    free(decrypted_msg);
    2.62 +    decrypted_msg = NULL;
    2.63 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
    2.64 +    TEST_ASSERT(ok);    
    2.65 +
    2.66 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
    2.67 +    message* msg2 = new_message(PEP_dir_outgoing);    
    2.68 +
    2.69 +    msg2->from = alice_from;
    2.70 +    msg2->to = new_identity_list(expired_inquisitor);
    2.71 +    msg2->shortmsg = strdup("Blah!");
    2.72 +    msg2->longmsg = strdup("Blahblahblah!");
    2.73 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    2.74 +
    2.75 +    status = outgoing_message_rating(session, msg2, &rating);
    2.76 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    2.77 +    TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
    2.78 +
    2.79 +    status = get_trust(session, expired_inquisitor);
    2.80 +    TEST_ASSERT_MSG(expired_inquisitor->comm_type == PEP_ct_OpenPGP_unconfirmed, tl_ct_string(expired_inquisitor->comm_type));
    2.81 +    free_message(msg2);
    2.82 +}
    2.83 +
    2.84 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_user() {
    2.85 +    bool ok = false;
    2.86 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    2.87 +    TEST_ASSERT(ok);    
    2.88 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
    2.89 +    TEST_ASSERT(ok);
    2.90 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
    2.91 +    TEST_ASSERT(ok);
    2.92 +
    2.93 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
    2.94 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
    2.95 +
    2.96 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
    2.97 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
    2.98 +
    2.99 +    const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
   2.100 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "Skyhold", "Lady Claire Trevelyan");
   2.101 +    status = set_identity(session, expired_inquisitor);
   2.102 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.103 +    expired_inquisitor->comm_type = PEP_ct_OpenPGP; // confirmed 
   2.104 +    status = set_trust(session, expired_inquisitor);
   2.105 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.106 +    
   2.107 +    // Ok, now update_identity - we'll discover it's expired
   2.108 +    status = update_identity(session, expired_inquisitor);
   2.109 +    TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
   2.110 +    PEP_comm_type ct = expired_inquisitor->comm_type;    
   2.111 +    TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
   2.112 +    
   2.113 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   2.114 +    // the expired key:
   2.115 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   2.116 +    
   2.117 +    char* decrypted_msg = NULL;
   2.118 +    stringlist_t* keylist_used = nullptr;
   2.119 +    char* modified_src = NULL;
   2.120 +    
   2.121 +    PEP_rating rating;
   2.122 +    PEP_decrypt_flags_t flags = 0;
   2.123 +     
   2.124 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   2.125 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   2.126 +
   2.127 +    free(decrypted_msg);
   2.128 +    decrypted_msg = NULL;
   2.129 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   2.130 +    TEST_ASSERT(ok);    
   2.131 +
   2.132 +    pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   2.133 +    
   2.134 +    status = update_identity(session, expired_inquisitor1);
   2.135 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.136 +    status = get_trust(session, expired_inquisitor1);
   2.137 +    TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_OpenPGP, tl_ct_string(expired_inquisitor1->comm_type));
   2.138 +
   2.139 +    message* msg2 = new_message(PEP_dir_outgoing);    
   2.140 +
   2.141 +    msg2->from = alice_from;
   2.142 +    msg2->to = new_identity_list(expired_inquisitor1);
   2.143 +    msg2->shortmsg = strdup("Blah!");
   2.144 +    msg2->longmsg = strdup("Blahblahblah!");
   2.145 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   2.146 +
   2.147 +    status = outgoing_message_rating(session, msg2, &rating);
   2.148 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.149 +    TEST_ASSERT_MSG((rating >= PEP_rating_trusted), tl_rating_string(rating));    
   2.150 +
   2.151 +    free_message(msg2);
   2.152 +}
   2.153 +
   2.154 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_pEp_user() {
   2.155 +    bool ok = false;
   2.156 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   2.157 +    TEST_ASSERT(ok);    
   2.158 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   2.159 +    TEST_ASSERT(ok);
   2.160 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   2.161 +    TEST_ASSERT(ok);
   2.162 +
   2.163 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   2.164 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   2.165 +
   2.166 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   2.167 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.168 +
   2.169 +    const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
   2.170 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "Skyhold", "Lady Claire Trevelyan");
   2.171 +    status = set_identity(session, expired_inquisitor);
   2.172 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.173 +    expired_inquisitor->comm_type = PEP_ct_pEp_unconfirmed;  
   2.174 +    status = set_trust(session, expired_inquisitor);
   2.175 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.176 +    
   2.177 +    bool pEp_user = false;
   2.178 +    status = is_pep_user(session, expired_inquisitor, &pEp_user);
   2.179 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.180 +    TEST_ASSERT(pEp_user);
   2.181 +
   2.182 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   2.183 +    // the expired key:
   2.184 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   2.185 +
   2.186 +    char* decrypted_msg = NULL;
   2.187 +    stringlist_t* keylist_used = nullptr;
   2.188 +    char* modified_src = NULL;
   2.189 +
   2.190 +    PEP_rating rating;
   2.191 +    PEP_decrypt_flags_t flags = 0;
   2.192 +
   2.193 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   2.194 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   2.195 +
   2.196 +    free(decrypted_msg);
   2.197 +    decrypted_msg = NULL;
   2.198 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   2.199 +    TEST_ASSERT(ok);    
   2.200 +
   2.201 +    pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   2.202 +    message* msg2 = new_message(PEP_dir_outgoing);    
   2.203 +
   2.204 +    msg2->from = alice_from;
   2.205 +    msg2->to = new_identity_list(expired_inquisitor1);
   2.206 +    msg2->shortmsg = strdup("Blah!");
   2.207 +    msg2->longmsg = strdup("Blahblahblah!");
   2.208 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   2.209 +
   2.210 +    status = outgoing_message_rating(session, msg2, &rating);
   2.211 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.212 +    TEST_ASSERT_MSG((rating == PEP_rating_reliable), tl_rating_string(rating));    
   2.213 +
   2.214 +    status = get_trust(session, expired_inquisitor);
   2.215 +    TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_pEp_unconfirmed, tl_ct_string(expired_inquisitor1->comm_type));
   2.216 +    free_message(msg2);
   2.217 +}
   2.218 +
   2.219 +void CheckRenewedExpiredKeyTrustStatusTests::check_renewed_expired_key_trust_status_trusted_pEp_user() {
   2.220 +    bool ok = false;
   2.221 +    ok = slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
   2.222 +    TEST_ASSERT(ok);    
   2.223 +    ok = slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
   2.224 +    TEST_ASSERT(ok);
   2.225 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_full_expired.pub.asc");    
   2.226 +    TEST_ASSERT(ok);
   2.227 +
   2.228 +    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
   2.229 +    pEp_identity* alice_from = new_identity("pep.test.alice@pep-project.org", alice_fpr, PEP_OWN_USERID, "Alice Cooper");
   2.230 +
   2.231 +    PEP_STATUS status = set_own_key(session, alice_from, alice_fpr); 
   2.232 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.233 +
   2.234 +    const char* inquisitor_fpr = "8E8D2381AE066ABE1FEE509821BA977CA4728718";
   2.235 +    pEp_identity* expired_inquisitor = new_identity("inquisitor@darthmama.org", "8E8D2381AE066ABE1FEE509821BA977CA4728718", "Skyhold", "Lady Claire Trevelyan");
   2.236 +    status = set_identity(session, expired_inquisitor);
   2.237 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.238 +    expired_inquisitor->comm_type = PEP_ct_pEp; // confirmed 
   2.239 +    status = set_trust(session, expired_inquisitor);
   2.240 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.241 +
   2.242 +    bool pEp_user = false;
   2.243 +    status = is_pep_user(session, expired_inquisitor, &pEp_user);
   2.244 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.245 +    TEST_ASSERT(pEp_user);
   2.246 +    
   2.247 +    // Ok, now update_identity - we'll discover it's expired
   2.248 +    status = update_identity(session, expired_inquisitor);
   2.249 +    TEST_ASSERT_MSG((status == PEP_KEY_UNSUITABLE), tl_status_string(status));
   2.250 +    PEP_comm_type ct = expired_inquisitor->comm_type;    
   2.251 +    TEST_ASSERT_MSG(ct == PEP_ct_key_expired_but_confirmed, tl_ct_string(ct));
   2.252 +    
   2.253 +    // Ok, so I want to make sure we make an entry, so I'll try to decrypt the message WITH
   2.254 +    // the expired key:
   2.255 +    const string msg = slurp("test_mails/ENGINE-463-attempt-numero-dos.eml");
   2.256 +    
   2.257 +    char* decrypted_msg = NULL;
   2.258 +    stringlist_t* keylist_used = nullptr;
   2.259 +    char* modified_src = NULL;
   2.260 +    
   2.261 +    PEP_rating rating;
   2.262 +    PEP_decrypt_flags_t flags = 0;
   2.263 +     
   2.264 +    status = MIME_decrypt_message(session, msg.c_str(), msg.size(), &decrypted_msg, &keylist_used, &rating, &flags, &modified_src);
   2.265 +    TEST_ASSERT_MSG((status == PEP_DECRYPTED), tl_status_string(status));
   2.266 +
   2.267 +    free(decrypted_msg);
   2.268 +    decrypted_msg = NULL;
   2.269 +    ok = slurp_and_import_key(session, "test_keys/pub/inquisitor-0xA4728718_renewed_pub.asc");    
   2.270 +    TEST_ASSERT(ok);    
   2.271 +
   2.272 +    pEp_identity* expired_inquisitor1 = new_identity("inquisitor@darthmama.org", NULL, NULL, "Lady Claire Trevelyan");
   2.273 +    
   2.274 +    status = update_identity(session, expired_inquisitor1);
   2.275 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.276 +    status = get_trust(session, expired_inquisitor1);
   2.277 +    TEST_ASSERT_MSG(expired_inquisitor1->comm_type == PEP_ct_pEp, tl_ct_string(expired_inquisitor1->comm_type));
   2.278 +
   2.279 +    message* msg2 = new_message(PEP_dir_outgoing);    
   2.280 +
   2.281 +    msg2->from = alice_from;
   2.282 +    msg2->to = new_identity_list(expired_inquisitor1);
   2.283 +    msg2->shortmsg = strdup("Blah!");
   2.284 +    msg2->longmsg = strdup("Blahblahblah!");
   2.285 +    msg2->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
   2.286 +
   2.287 +    status = outgoing_message_rating(session, msg2, &rating);
   2.288 +    TEST_ASSERT_MSG((status == PEP_STATUS_OK), tl_status_string(status));
   2.289 +    TEST_ASSERT_MSG((rating >= PEP_rating_trusted), tl_rating_string(rating));    
   2.290 +
   2.291 +    free_message(msg2);
   2.292 +}