still more tests to write, but sufficient to push for the moment sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Tue, 30 Apr 2019 16:42:50 +0200
branchsync
changeset 35840a67843c0d27
parent 3583 3c796707c727
child 3585 0c76403338c8
still more tests to write, but sufficient to push for the moment
test/include/OwnKeysRetrieveTests.h
test/src/engine_tests/OwnKeysRetrieveTests.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/include/OwnKeysRetrieveTests.h	Tue Apr 30 16:42:50 2019 +0200
     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 OWN_KEYS_RETRIEVE_H
     1.8 +#define OWN_KEYS_RETRIEVE_H
     1.9 +
    1.10 +#include <string>
    1.11 +#include "EngineTestIndividualSuite.h"
    1.12 +
    1.13 +using namespace std;
    1.14 +
    1.15 +class OwnKeysRetrieveTests : public EngineTestIndividualSuite {
    1.16 +    public:
    1.17 +        OwnKeysRetrieveTests(string test_suite, string test_home_dir);
    1.18 +    private:
    1.19 +        void check_own_keys_retrieve_single_private();
    1.20 +        void check_own_keys_retrieve_single_private_single_pub();
    1.21 +        void check_own_keys_retrieve_multiple_private();
    1.22 +        void check_own_keys_retrieve_multiple_private_and_pub();
    1.23 +        void check_own_keys_retrieve_multi_pub_only();
    1.24 +        void check_own_keys_retrieve_no_own();
    1.25 +        void check_own_keys_retrieve_multi_idents_one_key();
    1.26 +        void check_own_keys_retrieve_multi_idents_one_priv_key_multi_pub();
    1.27 +};
    1.28 +#endif
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/src/engine_tests/OwnKeysRetrieveTests.cc	Tue Apr 30 16:42:50 2019 +0200
     2.3 @@ -0,0 +1,224 @@
     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 <cstring>
     2.9 +#include <string>
    2.10 +
    2.11 +#include <cpptest.h>
    2.12 +#include "test_util.h"
    2.13 +
    2.14 +#include "pEpEngine.h"
    2.15 +
    2.16 +#include "EngineTestIndividualSuite.h"
    2.17 +#include "OwnKeysRetrieveTests.h"
    2.18 +
    2.19 +using namespace std;
    2.20 +
    2.21 +OwnKeysRetrieveTests::OwnKeysRetrieveTests(string suitename, string test_home_dir) :
    2.22 +    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    2.23 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_single_private"),
    2.24 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_single_private)));
    2.25 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_single_private_single_pub"),
    2.26 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_single_private_single_pub)));
    2.27 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_multiple_private"),
    2.28 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_multiple_private)));
    2.29 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_multiple_private_and_pub"),
    2.30 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_multiple_private_and_pub)));
    2.31 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_multi_pub_only"),
    2.32 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_multi_pub_only)));
    2.33 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_no_own"),
    2.34 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_no_own)));
    2.35 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_multi_idents_one_key"),
    2.36 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_multi_idents_one_key)));
    2.37 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("OwnKeysRetrieveTests::check_own_keys_retrieve_multi_idents_one_priv_key_multi_pub"),
    2.38 +                                                                      static_cast<Func>(&OwnKeysRetrieveTests::check_own_keys_retrieve_multi_idents_one_priv_key_multi_pub)));
    2.39 +}
    2.40 +
    2.41 +void OwnKeysRetrieveTests::check_own_keys_retrieve_single_private() {
    2.42 +    // Setup own identity
    2.43 +    PEP_STATUS status = read_file_and_import_key(session,
    2.44 +                "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    2.45 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
    2.46 +    status = set_up_ident_from_scratch(session,
    2.47 +                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
    2.48 +                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
    2.49 +                PEP_OWN_USERID, "Alice in Wonderland", NULL, true
    2.50 +            );
    2.51 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.52 +
    2.53 +    // Ok, see if we get it back.
    2.54 +    stringlist_t* keylist = NULL;
    2.55 +    
    2.56 +    status = _own_keys_retrieve(session, &keylist, 0, true);
    2.57 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.58 +    TEST_ASSERT(keylist);
    2.59 +    TEST_ASSERT(keylist->value);
    2.60 +    TEST_ASSERT(!keylist->next);
    2.61 +
    2.62 +    TEST_ASSERT(strcmp(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
    2.63 +}
    2.64 +
    2.65 +void OwnKeysRetrieveTests::check_own_keys_retrieve_single_private_single_pub() {
    2.66 +    // Set up an own idea that only has a public key
    2.67 +    PEP_STATUS status = set_up_ident_from_scratch(session,
    2.68 +                "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc",
    2.69 +                "pep.test.bob@pep-project.org", NULL, PEP_OWN_USERID, "Bob's Burgers",
    2.70 +                NULL, false
    2.71 +            );
    2.72 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.73 +
    2.74 +    // Make it an own identity in the DB
    2.75 +    pEp_identity* me_bob = new_identity("pep.test.bob@pep-project.org", NULL, PEP_OWN_USERID, NULL);
    2.76 +    status = update_identity(session, me_bob);
    2.77 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.78 +    TEST_ASSERT(strcmp(me_bob->fpr, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39") == 0);
    2.79 +    status = trust_personal_key(session, me_bob);
    2.80 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.81 +    
    2.82 +    me_bob->me = true;
    2.83 +    status = set_identity(session, me_bob);
    2.84 +    free(me_bob);
    2.85 +    me_bob = NULL;
    2.86 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.87 +    status = get_identity(session, "pep.test.bob@pep-project.org", PEP_OWN_USERID, &me_bob);
    2.88 +    TEST_ASSERT(status == PEP_STATUS_OK);
    2.89 +    
    2.90 +    free(me_bob);
    2.91 +    me_bob = NULL;
    2.92 +    
    2.93 +    // Setup own identity
    2.94 +    status = read_file_and_import_key(session,
    2.95 +                "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    2.96 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
    2.97 +    status = set_up_ident_from_scratch(session,
    2.98 +                "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc",
    2.99 +                "pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", 
   2.100 +                PEP_OWN_USERID, "Alice in Wonderland", NULL, true
   2.101 +            );
   2.102 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.103 +
   2.104 +    // Ok, see if we get it back.
   2.105 +    stringlist_t* keylist = NULL;
   2.106 +    
   2.107 +    status = _own_keys_retrieve(session, &keylist, 0, true);
   2.108 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.109 +    TEST_ASSERT(keylist);
   2.110 +    TEST_ASSERT(keylist->value);
   2.111 +    TEST_ASSERT(!keylist->next);
   2.112 +
   2.113 +    TEST_ASSERT(strcmp(keylist->value, "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97") == 0);
   2.114 +}
   2.115 +
   2.116 +void OwnKeysRetrieveTests::check_own_keys_retrieve_multiple_private() {
   2.117 +    // Setup own identity
   2.118 +    PEP_STATUS status = read_file_and_import_key(session,
   2.119 +                "test_keys/pub/pep.test.alexander0-0x3B7302DB_pub.asc");
   2.120 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
   2.121 +    status = set_up_ident_from_scratch(session,
   2.122 +                "test_keys/priv/pep.test.alexander0-0x3B7302DB_priv.asc",
   2.123 +                "pep.test.xander@pep-project.org", "F4598A17D4690EB3B5B0F6A344F04E963B7302DB", 
   2.124 +                PEP_OWN_USERID, "Xander in Wonderland", NULL, true
   2.125 +            );
   2.126 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.127 +
   2.128 +    // Setup own identity
   2.129 +    status = read_file_and_import_key(session,
   2.130 +                "test_keys/pub/pep.test.alexander1-0x541260F6_pub.asc");
   2.131 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
   2.132 +    status = set_up_ident_from_scratch(session,
   2.133 +                "test_keys/priv/pep.test.alexander1-0x541260F6_priv.asc",
   2.134 +                "pep.test.xander@pep-project.org", "59AF4C51492283522F6904531C09730A541260F6", 
   2.135 +                PEP_OWN_USERID, "Xander2", NULL, true
   2.136 +            );
   2.137 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.138 +
   2.139 +    // Setup own identity
   2.140 +    status = read_file_and_import_key(session,
   2.141 +                "test_keys/pub/pep.test.alexander2-0xA6512F30_pub.asc");
   2.142 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
   2.143 +    status = set_up_ident_from_scratch(session,
   2.144 +                "test_keys/priv/pep.test.alexander2-0xA6512F30_priv.asc",
   2.145 +                "pep.test.xander.work@pep-project.org", "46A994F19077C05610870273C4B8AB0BA6512F30", 
   2.146 +                PEP_OWN_USERID, "Xander3", NULL, true
   2.147 +            );
   2.148 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.149 +
   2.150 +    // Setup own identity
   2.151 +    status = read_file_and_import_key(session,
   2.152 +                "test_keys/pub/pep.test.alexander3-0x724B3975_pub.asc");
   2.153 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
   2.154 +    status = set_up_ident_from_scratch(session,
   2.155 +                "test_keys/priv/pep.test.alexander3-0x724B3975_priv.asc",
   2.156 +                "pep.test.xander@pep-project.org", "5F7076BBD92E14EA49F0DF7C2CE49419724B3975", 
   2.157 +                PEP_OWN_USERID, "Xander4", NULL, true
   2.158 +            );
   2.159 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.160 +
   2.161 +    // Setup own identity
   2.162 +    status = read_file_and_import_key(session,
   2.163 +                "test_keys/pub/pep.test.alexander4-0x844B9DCF_pub.asc");
   2.164 +    TEST_ASSERT(status == PEP_KEY_IMPORTED);
   2.165 +    status = set_up_ident_from_scratch(session,
   2.166 +                "test_keys/priv/pep.test.alexander4-0x844B9DCF_priv.asc",
   2.167 +                "pep.test.xander.home@pep-project.org", "E95FFF95B8E2FDD4A12C3374395F1485844B9DCF", 
   2.168 +                PEP_OWN_USERID, "Xander in Wonderland Again", NULL, true
   2.169 +            );
   2.170 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.171 +    
   2.172 +    // Ok, see if we get it back.
   2.173 +    stringlist_t* keylist = NULL;
   2.174 +    
   2.175 +    status = _own_keys_retrieve(session, &keylist, 0, true);
   2.176 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
   2.177 +    TEST_ASSERT(keylist);
   2.178 +
   2.179 +    int fpr_count = 0;
   2.180 +
   2.181 +    const char* fpr_list[5];
   2.182 +    
   2.183 +    bool* found_list = (bool*)calloc(5, sizeof(bool));
   2.184 +    fpr_list[0] = "F4598A17D4690EB3B5B0F6A344F04E963B7302DB"; 
   2.185 +    fpr_list[1] = "59AF4C51492283522F6904531C09730A541260F6"; 
   2.186 +    fpr_list[2] = "46A994F19077C05610870273C4B8AB0BA6512F30"; 
   2.187 +    fpr_list[3] = "5F7076BBD92E14EA49F0DF7C2CE49419724B3975"; 
   2.188 +    fpr_list[4] = "E95FFF95B8E2FDD4A12C3374395F1485844B9DCF"; 
   2.189 +     
   2.190 +    for (stringlist_t* _kl = keylist; _kl; _kl = _kl->next) {
   2.191 +        TEST_ASSERT(_kl->value);
   2.192 +        fpr_count++;
   2.193 +        
   2.194 +        for (int j = 0; j < 5; j++) {
   2.195 +            if (strcmp(_kl->value, fpr_list[j]) == 0) {
   2.196 +                found_list[j] = true;
   2.197 +                break;
   2.198 +            }
   2.199 +        }
   2.200 +    }
   2.201 +    TEST_ASSERT_MSG(fpr_count == 5, "Returned keylist does not have the correct number of keys.");
   2.202 +    for (int j = 0; j < 5; j++) {
   2.203 +        TEST_ASSERT_MSG(found_list[j], (string(fpr_list[j]) + " was not found.").c_str());
   2.204 +    }    
   2.205 +    free(found_list);
   2.206 +    free_stringlist(keylist);
   2.207 +}
   2.208 +
   2.209 +void OwnKeysRetrieveTests::check_own_keys_retrieve_multiple_private_and_pub() {
   2.210 +    TEST_ASSERT(true);
   2.211 +}
   2.212 +
   2.213 +void OwnKeysRetrieveTests::check_own_keys_retrieve_multi_pub_only() {
   2.214 +    TEST_ASSERT(true);
   2.215 +}
   2.216 +
   2.217 +void OwnKeysRetrieveTests::check_own_keys_retrieve_no_own() {
   2.218 +    TEST_ASSERT(true);
   2.219 +}
   2.220 +
   2.221 +void OwnKeysRetrieveTests::check_own_keys_retrieve_multi_idents_one_key() {
   2.222 +    TEST_ASSERT(true);
   2.223 +}
   2.224 +
   2.225 +void OwnKeysRetrieveTests::check_own_keys_retrieve_multi_idents_one_priv_key_multi_pub() {
   2.226 +    TEST_ASSERT(true);
   2.227 +}