ENGINE-757: added some test material ENGINE-757
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Mon, 15 Jun 2020 20:29:37 +0200
branchENGINE-757
changeset 4741cddfaf522e7a
parent 4736 94beaee71f5c
child 4742 fc606be2e563
ENGINE-757: added some test material
test/src/PassphraseTest.cc
test/test_keys/alice-no-passwords.pgp
test/test_keys/bob-primary-with-password-bob-subkey-without.pgp
test/test_keys/carol-subkeys-password-carol.pgp
test/test_keys/david-encryption-subkey-password-encrypt-signing-subkey-password-sign.pgp
test/test_keys/erwin-primary-encrypted-erwin-subkey-unencrypted.pgp
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/src/PassphraseTest.cc	Mon Jun 15 20:29:37 2020 +0200
     1.3 @@ -0,0 +1,357 @@
     1.4 +#include <stdlib.h>
     1.5 +#include <string>
     1.6 +#include <cstring>
     1.7 +
     1.8 +#include "pEpEngine.h"
     1.9 +#include "test_util.h"
    1.10 +#include "TestConstants.h"
    1.11 +#include "Engine.h"
    1.12 +
    1.13 +#include <gtest/gtest.h>
    1.14 +
    1.15 +
    1.16 +namespace {
    1.17 +
    1.18 +	//The fixture for PassphraseTest
    1.19 +    class PassphraseTest : public ::testing::Test {
    1.20 +        public:
    1.21 +            Engine* engine;
    1.22 +            PEP_SESSION session;
    1.23 +
    1.24 +        protected:
    1.25 +            // You can remove any or all of the following functions if its body
    1.26 +            // is empty.
    1.27 +            PassphraseTest() {
    1.28 +                // You can do set-up work for each test here.
    1.29 +                test_suite_name = ::testing::UnitTest::GetInstance()->current_test_info()->GTEST_SUITE_SYM();
    1.30 +                test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name();
    1.31 +                test_path = get_main_test_home_dir() + "/" + test_suite_name + "/" + test_name;
    1.32 +            }
    1.33 +
    1.34 +            ~PassphraseTest() override {
    1.35 +                // You can do clean-up work that doesn't throw exceptions here.
    1.36 +            }
    1.37 +
    1.38 +            // If the constructor and destructor are not enough for setting up
    1.39 +            // and cleaning up each test, you can define the following methods:
    1.40 +
    1.41 +            void SetUp() override {
    1.42 +                // Code here will be called immediately after the constructor (right
    1.43 +                // before each test).
    1.44 +
    1.45 +                // Leave this empty if there are no files to copy to the home directory path
    1.46 +                std::vector<std::pair<std::string, std::string>> init_files = std::vector<std::pair<std::string, std::string>>();
    1.47 +
    1.48 +                // Get a new test Engine.
    1.49 +                engine = new Engine(test_path);
    1.50 +                ASSERT_NE(engine, nullptr);
    1.51 +
    1.52 +                // Ok, let's initialize test directories etc.
    1.53 +                engine->prep(NULL, NULL, init_files);
    1.54 +
    1.55 +                // Ok, try to start this bugger.
    1.56 +                engine->start();
    1.57 +                ASSERT_NE(engine->session, nullptr);
    1.58 +                session = engine->session;
    1.59 +
    1.60 +                // Engine is up. Keep on truckin'
    1.61 +            }
    1.62 +
    1.63 +            void TearDown() override {
    1.64 +                // Code here will be called immediately after each test (right
    1.65 +                // before the destructor).
    1.66 +                engine->shut_down();
    1.67 +                delete engine;
    1.68 +                engine = NULL;
    1.69 +                session = NULL;
    1.70 +            }
    1.71 +            
    1.72 +            const char* alice_filename = "test_keys/alice-no-passwords.pgp";
    1.73 +            const char* bob_filename = "test_keys/bob-primary-with-password-bob-subkey-without.pgp";
    1.74 +            const char* carol_filename = "test_keys/carol-subkeys-password-carol.pgp";
    1.75 +            const char* david_filename = "test_keys/david-encryption-subkey-password-encrypt-signing-subkey-password-sign.pgp";
    1.76 +            const char* erwin_filename = "test_keys/erwin-primary-encrypted-erwin-subkey-unencrypted.pgp";
    1.77 +            const char* alice_fpr = "03AF88F728B8E9AADA7F370BD41801C62A649B9F";
    1.78 +            const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
    1.79 +            const char* carol_fpr = "A5B3473EA7CBB5DF7A4F595A8883DC4BCD8BAC06";
    1.80 +            const char* david_fpr = "7F72E4B27C6161455CD9C50FE7A05D7BF3FF4E19";
    1.81 +            const char* erwin_fpr = "A34048189F0067DF0006FB28CBD7CFBCC0FA7F97";
    1.82 +            
    1.83 +        private:
    1.84 +            const char* test_suite_name;
    1.85 +            const char* test_name;
    1.86 +            string test_path;
    1.87 +            // Objects declared here can be used by all tests in the PassphraseTest suite.
    1.88 +
    1.89 +    };
    1.90 +
    1.91 +}  // namespace
    1.92 +
    1.93 +
    1.94 +TEST_F(PassphraseTest, check_alice_no_passphrase_nopass_import) {
    1.95 +    ASSERT_TRUE(slurp_and_import_key(session, alice_filename));
    1.96 +    stringlist_t* found_key = NULL;
    1.97 +    PEP_STATUS status = find_keys(session, alice_fpr, &found_key);
    1.98 +    ASSERT_EQ(status, PEP_STATUS_OK);
    1.99 +    ASSERT_NE(found_key, nullptr);
   1.100 +    ASSERT_NE(found_key->value, nullptr);
   1.101 +    ASSERT_STREQ(found_key->value, alice_fpr);
   1.102 +    ASSERT_EQ(found_key->next, nullptr);
   1.103 +    free_stringlist(found_key);
   1.104 +}
   1.105 +
   1.106 +TEST_F(PassphraseTest, check_bob_primary_pass_subkey_no_passphrase_nopass_import) {
   1.107 +    ASSERT_TRUE(slurp_and_import_key(session, bob_filename));
   1.108 +    stringlist_t* found_key = NULL;
   1.109 +    PEP_STATUS status = find_keys(session, bob_fpr, &found_key);
   1.110 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.111 +    ASSERT_NE(found_key, nullptr);
   1.112 +    ASSERT_NE(found_key->value, nullptr);
   1.113 +    ASSERT_STREQ(found_key->value, bob_fpr);
   1.114 +    ASSERT_EQ(found_key->next, nullptr);
   1.115 +    free_stringlist(found_key);
   1.116 +}
   1.117 +
   1.118 +TEST_F(PassphraseTest, check_carol_primary_unenc_subkeys_passphrase_nopass_import) {
   1.119 +    ASSERT_TRUE(slurp_and_import_key(session, carol_filename));
   1.120 +    stringlist_t* found_key = NULL;
   1.121 +    PEP_STATUS status = find_keys(session, carol_fpr, &found_key);
   1.122 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.123 +    ASSERT_NE(found_key, nullptr);
   1.124 +    ASSERT_NE(found_key->value, nullptr);
   1.125 +    ASSERT_STREQ(found_key->value, carol_fpr);
   1.126 +    ASSERT_EQ(found_key->next, nullptr);
   1.127 +    free_stringlist(found_key);
   1.128 +}
   1.129 +
   1.130 +TEST_F(PassphraseTest, check_david_primary_unenc_sign_and_encrypt_diff_pass_two_sign_unencrypted_nopass_import) {
   1.131 +    ASSERT_TRUE(slurp_and_import_key(session, david_filename));
   1.132 +    stringlist_t* found_key = NULL;
   1.133 +    PEP_STATUS status = find_keys(session, david_fpr, &found_key);
   1.134 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.135 +    ASSERT_NE(found_key, nullptr);
   1.136 +    ASSERT_NE(found_key->value, nullptr);
   1.137 +    ASSERT_STREQ(found_key->value, david_fpr);
   1.138 +    ASSERT_EQ(found_key->next, nullptr);
   1.139 +    free_stringlist(found_key);
   1.140 +}
   1.141 +
   1.142 +TEST_F(PassphraseTest, check_erwin_primary_enc_subkey_encrypted_plus_unenc_sign_nopass_import) {
   1.143 +    ASSERT_TRUE(slurp_and_import_key(session, erwin_filename));
   1.144 +    stringlist_t* found_key = NULL;
   1.145 +    PEP_STATUS status = find_keys(session, erwin_fpr, &found_key);
   1.146 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.147 +    ASSERT_NE(found_key, nullptr);
   1.148 +    ASSERT_NE(found_key->value, nullptr);
   1.149 +    ASSERT_STREQ(found_key->value, erwin_fpr);
   1.150 +    ASSERT_EQ(found_key->next, nullptr);
   1.151 +    free_stringlist(found_key);
   1.152 +}
   1.153 +
   1.154 +TEST_F(PassphraseTest, check_alice_no_passphrase_nopass_sign) {
   1.155 +    ASSERT_TRUE(slurp_and_import_key(session, alice_filename));
   1.156 +    stringlist_t* found_key = NULL;
   1.157 +    PEP_STATUS status = find_keys(session, alice_fpr, &found_key);
   1.158 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.159 +    ASSERT_NE(found_key, nullptr);
   1.160 +    ASSERT_NE(found_key->value, nullptr);
   1.161 +    ASSERT_STREQ(found_key->value, alice_fpr);
   1.162 +    ASSERT_EQ(found_key->next, nullptr);
   1.163 +    
   1.164 +    const char* my_fpr = alice_fpr;
   1.165 +    const char* my_name = "Alice Malice";
   1.166 +    const char* my_address = "alice_malice@darthmama.cool";
   1.167 +    pEp_identity* my_ident = new_identity(my_address, my_fpr, PEP_OWN_USERID, my_name);
   1.168 +    status = set_own_key(session, my_ident, my_fpr);
   1.169 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.170 +    
   1.171 +    const char* to_fpr = alice_fpr;
   1.172 +    const char* to_name = "Alice Malice";
   1.173 +    const char* to_address = "alice_malice@darthmama.cool";
   1.174 +    pEp_identity* to_ident = new_identity(to_address, to_fpr, PEP_OWN_USERID, to_name);
   1.175 +    status = set_identity(session, to_ident);
   1.176 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.177 +    
   1.178 +    message* msg = new_message(PEP_dir_outgoing);
   1.179 +    msg->from = my_ident;
   1.180 +    msg->to = new_identity_list(to_ident);
   1.181 +    msg->shortmsg = strdup("This is an exciting message from Alice!");
   1.182 +    msg->longmsg = strdup("Not\nVery\nExciting\n");   
   1.183 +    
   1.184 +    message* enc_msg = NULL;
   1.185 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   1.186 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.187 +    ASSERT_NE(enc_msg, nullptr);
   1.188 +    
   1.189 +    free_message(msg);
   1.190 +    free_message(enc_msg);
   1.191 +    free_stringlist(found_key);
   1.192 +}
   1.193 +
   1.194 +TEST_F(PassphraseTest, check_bob_primary_pass_subkey_no_passphrase_nopass_sign) {
   1.195 +    ASSERT_TRUE(slurp_and_import_key(session, bob_filename));
   1.196 +    stringlist_t* found_key = NULL;
   1.197 +    PEP_STATUS status = find_keys(session, bob_fpr, &found_key);
   1.198 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.199 +    ASSERT_NE(found_key, nullptr);
   1.200 +    ASSERT_NE(found_key->value, nullptr);
   1.201 +    ASSERT_STREQ(found_key->value, bob_fpr);
   1.202 +    ASSERT_EQ(found_key->next, nullptr);
   1.203 +
   1.204 +    const char* my_fpr = bob_fpr;
   1.205 +    const char* my_name = "Bob Mob";
   1.206 +    const char* my_address = "bob_mob@darthmama.cool";
   1.207 +    pEp_identity* my_ident = new_identity(my_address, my_fpr, PEP_OWN_USERID, my_name);
   1.208 +    status = set_own_key(session, my_ident, my_fpr);
   1.209 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.210 +    
   1.211 +    // Set up "to"
   1.212 +    ASSERT_TRUE(slurp_and_import_key(session, alice_filename));    
   1.213 +    const char* to_fpr = alice_fpr;
   1.214 +    const char* to_name = "Alice Malice";
   1.215 +    const char* to_address = "alice_malice@darthmama.cool";
   1.216 +    pEp_identity* to_ident = new_identity(to_address, to_fpr, PEP_OWN_USERID, to_name);
   1.217 +    status = set_identity(session, to_ident);
   1.218 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.219 +    
   1.220 +    message* msg = new_message(PEP_dir_outgoing);   
   1.221 +    msg->from = my_ident;
   1.222 +    msg->to = new_identity_list(to_ident);
   1.223 +    msg->shortmsg = strdup("This is an exciting message from Bob!");
   1.224 +    msg->longmsg = strdup("Not\nVery\nExciting\n");   
   1.225 +    
   1.226 +    message* enc_msg = NULL;
   1.227 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   1.228 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.229 +    ASSERT_NE(enc_msg, nullptr);
   1.230 +    
   1.231 +    free_message(msg);
   1.232 +    free_message(enc_msg);
   1.233 +    free_stringlist(found_key);
   1.234 +}
   1.235 +
   1.236 +TEST_F(PassphraseTest, check_carol_primary_unenc_subkeys_passphrase_nopass_sign) {
   1.237 +    ASSERT_TRUE(slurp_and_import_key(session, carol_filename));
   1.238 +    stringlist_t* found_key = NULL;
   1.239 +    PEP_STATUS status = find_keys(session, carol_fpr, &found_key);
   1.240 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.241 +    ASSERT_NE(found_key, nullptr);
   1.242 +    ASSERT_NE(found_key->value, nullptr);
   1.243 +    ASSERT_STREQ(found_key->value, carol_fpr);
   1.244 +    ASSERT_EQ(found_key->next, nullptr);
   1.245 +    
   1.246 +    const char* my_fpr = carol_fpr;
   1.247 +    const char* my_name = "Carol Peril";
   1.248 +    const char* my_address = "carol_peril@darthmama.cool";
   1.249 +    pEp_identity* my_ident = new_identity(my_address, my_fpr, PEP_OWN_USERID, my_name);
   1.250 +    status = set_own_key(session, my_ident, my_fpr);
   1.251 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.252 +    
   1.253 +    // Set up "to"
   1.254 +    ASSERT_TRUE(slurp_and_import_key(session, alice_filename));    
   1.255 +    const char* to_fpr = alice_fpr;
   1.256 +    const char* to_name = "Alice Malice";
   1.257 +    const char* to_address = "alice_malice@darthmama.cool";
   1.258 +    pEp_identity* to_ident = new_identity(to_address, to_fpr, PEP_OWN_USERID, to_name);
   1.259 +    status = set_identity(session, to_ident);
   1.260 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.261 +    
   1.262 +    message* msg = new_message(PEP_dir_outgoing);        
   1.263 +    msg->from = my_ident;
   1.264 +    msg->to = new_identity_list(to_ident);
   1.265 +    msg->shortmsg = strdup("This is an exciting message from Carol!");
   1.266 +    msg->longmsg = strdup("Not\nVery\nExciting\n");   
   1.267 +    
   1.268 +    message* enc_msg = NULL;
   1.269 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   1.270 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.271 +    ASSERT_NE(enc_msg, nullptr);
   1.272 +    
   1.273 +    free_message(msg);
   1.274 +    free_message(enc_msg);    
   1.275 +    free_stringlist(found_key);
   1.276 +}
   1.277 +
   1.278 +TEST_F(PassphraseTest, check_david_primary_unenc_sign_and_encrypt_diff_pass_two_sign_unencrypted_nopass_sign) {
   1.279 +    ASSERT_TRUE(slurp_and_import_key(session, david_filename));
   1.280 +    stringlist_t* found_key = NULL;
   1.281 +    PEP_STATUS status = find_keys(session, david_fpr, &found_key);
   1.282 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.283 +    ASSERT_NE(found_key, nullptr);
   1.284 +    ASSERT_NE(found_key->value, nullptr);
   1.285 +    ASSERT_STREQ(found_key->value, david_fpr);
   1.286 +    ASSERT_EQ(found_key->next, nullptr);
   1.287 +    
   1.288 +    const char* my_fpr = david_fpr;
   1.289 +    const char* my_name = "Dave Rave";
   1.290 +    const char* my_address = "dave_rave@darthmama.cool";
   1.291 +    pEp_identity* my_ident = new_identity(my_address, my_fpr, PEP_OWN_USERID, my_name);
   1.292 +    status = set_own_key(session, my_ident, my_fpr);
   1.293 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.294 +
   1.295 +    // Set up "to"
   1.296 +    ASSERT_TRUE(slurp_and_import_key(session, alice_filename));    
   1.297 +    const char* to_fpr = alice_fpr;
   1.298 +    const char* to_name = "Alice Malice";
   1.299 +    const char* to_address = "alice_malice@darthmama.cool";
   1.300 +    pEp_identity* to_ident = new_identity(to_address, to_fpr, PEP_OWN_USERID, to_name);
   1.301 +    status = set_identity(session, to_ident);
   1.302 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.303 +    
   1.304 +    message* msg = new_message(PEP_dir_outgoing);        
   1.305 +    msg->from = my_ident;
   1.306 +    msg->to = new_identity_list(to_ident);
   1.307 +    msg->shortmsg = strdup("This is an exciting message from David!");
   1.308 +    msg->longmsg = strdup("Not\nVery\nExciting\n");   
   1.309 +    
   1.310 +    message* enc_msg = NULL;
   1.311 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   1.312 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.313 +    ASSERT_NE(enc_msg, nullptr);
   1.314 +    
   1.315 +    free_message(msg);
   1.316 +    free_message(enc_msg);        
   1.317 +    free_stringlist(found_key);
   1.318 +}
   1.319 +
   1.320 +TEST_F(PassphraseTest, check_erwin_primary_enc_subkey_encrypted_plus_unenc_sign_nopass_sign) {
   1.321 +    ASSERT_TRUE(slurp_and_import_key(session, erwin_filename));
   1.322 +    stringlist_t* found_key = NULL;
   1.323 +    PEP_STATUS status = find_keys(session, erwin_fpr, &found_key);
   1.324 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.325 +    ASSERT_NE(found_key, nullptr);
   1.326 +    ASSERT_NE(found_key->value, nullptr);
   1.327 +    ASSERT_STREQ(found_key->value, erwin_fpr);
   1.328 +    ASSERT_EQ(found_key->next, nullptr);
   1.329 +    
   1.330 +    const char* my_fpr = erwin_fpr;
   1.331 +    const char* my_name = "Irv Nerve";
   1.332 +    const char* my_address = "irv_nerve@darthmama.cool";
   1.333 +    pEp_identity* my_ident = new_identity(my_address, my_fpr, PEP_OWN_USERID, my_name);
   1.334 +    status = set_own_key(session, my_ident, my_fpr);
   1.335 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.336 +    
   1.337 +    // Set up "to"
   1.338 +    ASSERT_TRUE(slurp_and_import_key(session, alice_filename));    
   1.339 +    const char* to_fpr = alice_fpr;
   1.340 +    const char* to_name = "Alice Malice";
   1.341 +    const char* to_address = "alice_malice@darthmama.cool";
   1.342 +    pEp_identity* to_ident = new_identity(to_address, to_fpr, PEP_OWN_USERID, to_name);
   1.343 +    status = set_identity(session, to_ident);
   1.344 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.345 +    
   1.346 +    message* msg = new_message(PEP_dir_outgoing);    
   1.347 +    msg->from = my_ident;
   1.348 +    msg->to = new_identity_list(to_ident);
   1.349 +    msg->shortmsg = strdup("This is an exciting message from Erwin!");
   1.350 +    msg->longmsg = strdup("Not\nVery\nExciting\n");   
   1.351 +    
   1.352 +    message* enc_msg = NULL;
   1.353 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
   1.354 +    ASSERT_EQ(status, PEP_STATUS_OK);
   1.355 +    ASSERT_NE(enc_msg, nullptr);
   1.356 +    
   1.357 +    free_message(msg);
   1.358 +    free_message(enc_msg);            
   1.359 +    free_stringlist(found_key);
   1.360 +}
     2.1 Binary file test/test_keys/alice-no-passwords.pgp has changed
     3.1 Binary file test/test_keys/bob-primary-with-password-bob-subkey-without.pgp has changed
     4.1 Binary file test/test_keys/carol-subkeys-password-carol.pgp has changed
     5.1 Binary file test/test_keys/david-encryption-subkey-password-encrypt-signing-subkey-password-sign.pgp has changed
     6.1 Binary file test/test_keys/erwin-primary-encrypted-erwin-subkey-unencrypted.pgp has changed