test/src/engine_tests/ExpiredSubkeyTests.cc
author Krista Bennett <krista@pep-project.org>
Wed, 24 Oct 2018 18:02:32 +0200
changeset 3104 2b14c4d40d95
child 3276 c0b3430f1f1d
permissions -rw-r--r--
ENGINE-472 - subkey evaluation changed; we now look for the best valid sign and encrypt subkeys and report a comm_type based on the minimum of this. (note: sign and encrypt are still a monolith - that means pub keys with valid encrypt subkeys and invalid signing subkeys would still be rejected for encryption. This is a low priority fix.)
     1 // This file is under GNU General Public License 3.0
     2 // see LICENSE.txt
     3 
     4 #include <stdlib.h>
     5 #include <string>
     6 #include <cpptest.h>
     7 #include "test_util.h"
     8 
     9 #include "pEpEngine.h"
    10 
    11 #include "EngineTestIndividualSuite.h"
    12 #include "ExpiredSubkeyTests.h"
    13 
    14 using namespace std;
    15 
    16 ExpiredSubkeyTests::ExpiredSubkeyTests(string suitename, string test_home_dir) :
    17     EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
    18     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_and_main_key"),
    19                                                                       static_cast<Func>(&ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_and_main_key)));
    20     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_expired_main"),
    21                                                                       static_cast<Func>(&ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_expired_main)));                                                                      
    22     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::all_valid_with_leftover_expired_subkeys"),
    23                                                                       static_cast<Func>(&ExpiredSubkeyTests::all_valid_with_leftover_expired_subkeys)));                                                                                                                                            
    24     add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::no_valid_encryption_subkey"),
    25                                                                       static_cast<Func>(&ExpiredSubkeyTests::no_valid_encryption_subkey)));                                                                                                                                            
    26 }
    27 
    28 void ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_and_main_key() {
    29     slurp_and_import_key(session,"test_keys/pub/eb_0_valid_pub.asc");
    30     pEp_identity* expired_0 = new_identity("expired_in_bits_0@darthmama.org",
    31                                            NULL, NULL, "Expired 0");
    32     PEP_STATUS status = update_identity(session, expired_0);
    33     TEST_ASSERT(status == PEP_STATUS_OK);
    34     TEST_ASSERT(expired_0->fpr);
    35     PEP_rating rating;
    36     status = identity_rating(session, expired_0, &rating);
    37     TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    38     TEST_ASSERT(rating == PEP_rating_reliable);    
    39 }
    40 
    41 void ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_expired_main() {
    42     slurp_and_import_key(session,"test_keys/pub/master_key_test_sign_and_encrypt_added.asc");
    43     pEp_identity* expired_0 = new_identity("master_key_test@darthmama.org",
    44                                            NULL, NULL, "Master Key Test");
    45     PEP_STATUS status = update_identity(session, expired_0);
    46     TEST_ASSERT(status == PEP_STATUS_OK);
    47     TEST_ASSERT(expired_0->fpr);
    48     PEP_rating rating;
    49     status = identity_rating(session, expired_0, &rating);
    50     TEST_ASSERT_MSG(status == PEP_KEY_UNSUITABLE, tl_status_string(status));
    51     TEST_ASSERT(rating == PEP_rating_undefined);        
    52 }
    53 
    54 void ExpiredSubkeyTests::all_valid_with_leftover_expired_subkeys() {
    55     slurp_and_import_key(session,"test_keys/pub/master_key_test_certify_extended_pub.asc");
    56     pEp_identity* expired_0 = new_identity("master_key_test@darthmama.org",
    57                                            NULL, NULL, "Master Key Test");
    58     PEP_STATUS status = update_identity(session, expired_0);
    59     TEST_ASSERT(status == PEP_STATUS_OK);
    60     TEST_ASSERT(expired_0->fpr);
    61     PEP_rating rating;
    62     status = identity_rating(session, expired_0, &rating);
    63     TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
    64     TEST_ASSERT(rating == PEP_rating_reliable);        
    65 }
    66 
    67 void ExpiredSubkeyTests::no_valid_encryption_subkey() {
    68     slurp_and_import_key(session,"test_keys/pub/master_key_test_deleted_valid_enc_key_pub.asc");
    69     pEp_identity* expired_0 = new_identity("master_key_test@darthmama.org",
    70                                            NULL, NULL, "Master Key Test");
    71     PEP_STATUS status = update_identity(session, expired_0);
    72     TEST_ASSERT(status == PEP_STATUS_OK);
    73     TEST_ASSERT(expired_0->fpr);
    74     PEP_rating rating;
    75     status = identity_rating(session, expired_0, &rating);
    76     TEST_ASSERT_MSG(status == PEP_KEY_UNSUITABLE, tl_status_string(status));
    77     TEST_ASSERT_MSG(rating == PEP_rating_undefined, tl_rating_string(rating));        
    78 }
    79