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.)
krista@3104
     1
// This file is under GNU General Public License 3.0
krista@3104
     2
// see LICENSE.txt
krista@3104
     3
krista@3104
     4
#include <stdlib.h>
krista@3104
     5
#include <string>
krista@3104
     6
#include <cpptest.h>
krista@3104
     7
#include "test_util.h"
krista@3104
     8
krista@3104
     9
#include "pEpEngine.h"
krista@3104
    10
krista@3104
    11
#include "EngineTestIndividualSuite.h"
krista@3104
    12
#include "ExpiredSubkeyTests.h"
krista@3104
    13
krista@3104
    14
using namespace std;
krista@3104
    15
krista@3104
    16
ExpiredSubkeyTests::ExpiredSubkeyTests(string suitename, string test_home_dir) :
krista@3104
    17
    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
krista@3104
    18
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_and_main_key"),
krista@3104
    19
                                                                      static_cast<Func>(&ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_and_main_key)));
krista@3104
    20
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_expired_main"),
krista@3104
    21
                                                                      static_cast<Func>(&ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_expired_main)));                                                                      
krista@3104
    22
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::all_valid_with_leftover_expired_subkeys"),
krista@3104
    23
                                                                      static_cast<Func>(&ExpiredSubkeyTests::all_valid_with_leftover_expired_subkeys)));                                                                                                                                            
krista@3104
    24
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("ExpiredSubkeyTests::no_valid_encryption_subkey"),
krista@3104
    25
                                                                      static_cast<Func>(&ExpiredSubkeyTests::no_valid_encryption_subkey)));                                                                                                                                            
krista@3104
    26
}
krista@3104
    27
krista@3104
    28
void ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_and_main_key() {
krista@3104
    29
    slurp_and_import_key(session,"test_keys/pub/eb_0_valid_pub.asc");
krista@3104
    30
    pEp_identity* expired_0 = new_identity("expired_in_bits_0@darthmama.org",
krista@3104
    31
                                           NULL, NULL, "Expired 0");
krista@3104
    32
    PEP_STATUS status = update_identity(session, expired_0);
krista@3104
    33
    TEST_ASSERT(status == PEP_STATUS_OK);
krista@3104
    34
    TEST_ASSERT(expired_0->fpr);
krista@3104
    35
    PEP_rating rating;
krista@3104
    36
    status = identity_rating(session, expired_0, &rating);
krista@3104
    37
    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
krista@3104
    38
    TEST_ASSERT(rating == PEP_rating_reliable);    
krista@3104
    39
}
krista@3104
    40
krista@3104
    41
void ExpiredSubkeyTests::expired_subkey_with_valid_subkeys_expired_main() {
krista@3104
    42
    slurp_and_import_key(session,"test_keys/pub/master_key_test_sign_and_encrypt_added.asc");
krista@3104
    43
    pEp_identity* expired_0 = new_identity("master_key_test@darthmama.org",
krista@3104
    44
                                           NULL, NULL, "Master Key Test");
krista@3104
    45
    PEP_STATUS status = update_identity(session, expired_0);
krista@3104
    46
    TEST_ASSERT(status == PEP_STATUS_OK);
krista@3104
    47
    TEST_ASSERT(expired_0->fpr);
krista@3104
    48
    PEP_rating rating;
krista@3104
    49
    status = identity_rating(session, expired_0, &rating);
krista@3104
    50
    TEST_ASSERT_MSG(status == PEP_KEY_UNSUITABLE, tl_status_string(status));
krista@3104
    51
    TEST_ASSERT(rating == PEP_rating_undefined);        
krista@3104
    52
}
krista@3104
    53
krista@3104
    54
void ExpiredSubkeyTests::all_valid_with_leftover_expired_subkeys() {
krista@3104
    55
    slurp_and_import_key(session,"test_keys/pub/master_key_test_certify_extended_pub.asc");
krista@3104
    56
    pEp_identity* expired_0 = new_identity("master_key_test@darthmama.org",
krista@3104
    57
                                           NULL, NULL, "Master Key Test");
krista@3104
    58
    PEP_STATUS status = update_identity(session, expired_0);
krista@3104
    59
    TEST_ASSERT(status == PEP_STATUS_OK);
krista@3104
    60
    TEST_ASSERT(expired_0->fpr);
krista@3104
    61
    PEP_rating rating;
krista@3104
    62
    status = identity_rating(session, expired_0, &rating);
krista@3104
    63
    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
krista@3104
    64
    TEST_ASSERT(rating == PEP_rating_reliable);        
krista@3104
    65
}
krista@3104
    66
krista@3104
    67
void ExpiredSubkeyTests::no_valid_encryption_subkey() {
krista@3104
    68
    slurp_and_import_key(session,"test_keys/pub/master_key_test_deleted_valid_enc_key_pub.asc");
krista@3104
    69
    pEp_identity* expired_0 = new_identity("master_key_test@darthmama.org",
krista@3104
    70
                                           NULL, NULL, "Master Key Test");
krista@3104
    71
    PEP_STATUS status = update_identity(session, expired_0);
krista@3104
    72
    TEST_ASSERT(status == PEP_STATUS_OK);
krista@3104
    73
    TEST_ASSERT(expired_0->fpr);
krista@3104
    74
    PEP_rating rating;
krista@3104
    75
    status = identity_rating(session, expired_0, &rating);
krista@3104
    76
    TEST_ASSERT_MSG(status == PEP_KEY_UNSUITABLE, tl_status_string(status));
krista@3104
    77
    TEST_ASSERT_MSG(rating == PEP_rating_undefined, tl_rating_string(rating));        
krista@3104
    78
}
krista@3104
    79