Completed export key tests. Runs under gpg, broken under sequoia sync
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Thu, 02 May 2019 08:44:50 +0200
branchsync
changeset 3599603f364d3649
parent 3598 a37e451d4fce
child 3600 07d9a2af323f
Completed export key tests. Runs under gpg, broken under sequoia
test/include/ExportKeyTests.h
test/src/engine_tests/ExportKeyTests.cc
     1.1 --- a/test/include/ExportKeyTests.h	Thu May 02 08:28:05 2019 +0200
     1.2 +++ b/test/include/ExportKeyTests.h	Thu May 02 08:44:50 2019 +0200
     1.3 @@ -14,6 +14,8 @@
     1.4          ExportKeyTests(string test_suite, string test_home_dir);
     1.5      private:
     1.6          void check_export_key_no_key();
     1.7 +        void check_export_key_pubkey();
     1.8 +        void check_export_key_secret_key();
     1.9          void check_export_key_no_secret_key();
    1.10  };
    1.11  
     2.1 --- a/test/src/engine_tests/ExportKeyTests.cc	Thu May 02 08:28:05 2019 +0200
     2.2 +++ b/test/src/engine_tests/ExportKeyTests.cc	Thu May 02 08:44:50 2019 +0200
     2.3 @@ -19,6 +19,10 @@
     2.4      EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
     2.5      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExportKeyTests::check_export_key_no_key"),
     2.6                                                                        static_cast<Func>(&ExportKeyTests::check_export_key_no_key)));
     2.7 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExportKeyTests::check_export_key_pubkey"),
     2.8 +                                                                      static_cast<Func>(&ExportKeyTests::check_export_key_pubkey)));
     2.9 +    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExportKeyTests::check_export_key_no_secret_key"),
    2.10 +                                                                      static_cast<Func>(&ExportKeyTests::check_export_key_no_secret_key)));
    2.11      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExportKeyTests::check_export_key_no_secret_key"),
    2.12                                                                        static_cast<Func>(&ExportKeyTests::check_export_key_no_secret_key)));
    2.13  }
    2.14 @@ -40,6 +44,60 @@
    2.15      TEST_ASSERT(true);
    2.16  }
    2.17  
    2.18 +void ExportKeyTests::check_export_key_pubkey() {
    2.19 +    // Own pub key
    2.20 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"),
    2.21 +                    "Unable to import test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
    2.22 +
    2.23 +    char* keydata = NULL;
    2.24 +    size_t keysize = 0;
    2.25 +    stringlist_t* keylist = NULL;
    2.26 +    PEP_STATUS status = find_keys(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &keylist);
    2.27 +    TEST_ASSERT(keylist && keylist->value);
    2.28 +    TEST_ASSERT(strcmp(keylist->value, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39") == 0);
    2.29 +
    2.30 +    status = export_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", 
    2.31 +                                   &keydata, &keysize);
    2.32 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.33 +    TEST_ASSERT(keydata);
    2.34 +    TEST_ASSERT(keysize > 0);
    2.35 +    
    2.36 +    free(keydata);
    2.37 +    keydata = NULL;
    2.38 +}
    2.39 +
    2.40 +void ExportKeyTests::check_export_key_secret_key() {
    2.41 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"),
    2.42 +                    "Unable to import test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
    2.43 +    TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc"),
    2.44 +                    "Unable to import test_keys/priv/pep-test-bob-0xC9C2EE39_priv.asc");
    2.45 +    char* keydata = NULL;
    2.46 +    size_t keysize = 0;
    2.47 +    stringlist_t* keylist = NULL;
    2.48 +    PEP_STATUS status = find_keys(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &keylist);
    2.49 +    TEST_ASSERT(keylist && keylist->value);
    2.50 +    TEST_ASSERT(strcmp(keylist->value, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39") == 0);
    2.51 +    free_stringlist(keylist);
    2.52 +    keylist = NULL;
    2.53 +    
    2.54 +    bool has_private = false;
    2.55 +    contains_priv_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", &has_private);
    2.56 +    TEST_ASSERT_MSG(has_private, "Secret key not found.")
    2.57 +    
    2.58 +    status = export_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", 
    2.59 +                                   &keydata, &keysize);
    2.60 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.61 +    free(keydata);
    2.62 +    keydata = NULL;
    2.63 +    keysize = 0;
    2.64 +    status = export_secret_key(session, "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39", 
    2.65 +                                   &keydata, &keysize);
    2.66 +    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    2.67 +    free(keydata);
    2.68 +    TEST_ASSERT(true);
    2.69 +}
    2.70 +
    2.71 +
    2.72  void ExportKeyTests::check_export_key_no_secret_key() {
    2.73      // Own pub key
    2.74      TEST_ASSERT_MSG(slurp_and_import_key(session, "test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc"),