added to URIAddressTest
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 03 Jun 2020 15:56:40 +0200
changeset 4727a31cfcc2c098
parent 4725 93fc1da88f49
child 4728 feacfba6a106
child 4729 3df9a2a67597
added to URIAddressTest
test/src/URIAddressTest.cc
     1.1 --- a/test/src/URIAddressTest.cc	Fri May 29 15:07:01 2020 +0200
     1.2 +++ b/test/src/URIAddressTest.cc	Wed Jun 03 15:56:40 2020 +0200
     1.3 @@ -273,3 +273,99 @@
     1.4      
     1.5      // We don't check for anything here??? FIXME! WTF!
     1.6  }
     1.7 +
     1.8 +TEST_F(URIAddressTest, check_uri_address_tofu_1) {
     1.9 +    const char* sys_a_addr = "payto://BIC/SYSTEMA";
    1.10 +    const char* sys_b_addr = "payto://BIC/SYSTEMB";
    1.11 +    const char* sys_a_fpr = "4334D6DB751A8CA2B4944075462AFDB6DA3FB4B9";
    1.12 +    const char* sys_b_fpr = "F5199E0B0AC4059572DAD8EA76B63B2954139F26";
    1.13 +    
    1.14 +    slurp_and_import_key(session, "test_keys/priv/BIC_SYSTEMA_0xDA3FB4B9_priv.asc");
    1.15 +    slurp_and_import_key(session, "test_keys/pub/BIC_SYSTEMA_0xDA3FB4B9_pub.asc");
    1.16 +    slurp_and_import_key(session, "test_keys/pub/BIC_SYSTEMB_0x54139F26_pub.asc");
    1.17 +
    1.18 +    pEp_identity* me = new_identity(sys_a_addr, NULL, PEP_OWN_USERID, sys_a_addr);
    1.19 +    PEP_STATUS status = set_own_key(session, me, sys_a_fpr);
    1.20 +    ASSERT_EQ(status , PEP_STATUS_OK);
    1.21 +
    1.22 +    status = myself(session, me);
    1.23 +    ASSERT_EQ(status , PEP_STATUS_OK);
    1.24 +    ASSERT_TRUE(me->fpr && me->fpr[0] != '\0');
    1.25 +
    1.26 +    pEp_identity* you = new_identity(sys_b_addr, NULL, "SYSTEM_B", NULL);
    1.27 +
    1.28 +/*
    1.29 +    stringlist_t* keylist = NULL;
    1.30 +    status = update_identity(session, you);
    1.31 +    ASSERT_EQ(status , PEP_STATUS_OK);
    1.32 +    ASSERT_TRUE(you->fpr && you->fpr[0] != '\0');
    1.33 +*/
    1.34 +    message* msg = new_message(PEP_dir_outgoing);
    1.35 +
    1.36 +    msg->from = me;
    1.37 +    msg->to = new_identity_list(you);
    1.38 +    msg->shortmsg = strdup("Smurfs");
    1.39 +    msg->longmsg = strdup("Are delicious?");
    1.40 +
    1.41 +    message* enc_msg = NULL;
    1.42 +    
    1.43 +    // We are doing key election here on purpose.
    1.44 +    status = encrypt_message(session, msg, NULL, &enc_msg, PEP_enc_PGP_MIME, 0);
    1.45 +    ASSERT_EQ(status, PEP_STATUS_OK);
    1.46 +
    1.47 +    char* outmsg = NULL;
    1.48 +    mime_encode_message(enc_msg, false, &outmsg, false);
    1.49 +    output_stream << outmsg << endl;
    1.50 +    
    1.51 +    if (false) {
    1.52 +        ofstream outfile;
    1.53 +        outfile.open("test_mails/system_a_to_b_755_part_1.eml");
    1.54 +        outfile << outmsg;    
    1.55 +        outfile.close();    
    1.56 +    }
    1.57 +    free(outmsg);
    1.58 +    free_message(msg);
    1.59 +    free_message(enc_msg);
    1.60 +}
    1.61 +
    1.62 +TEST_F(URIAddressTest, check_uri_address_tofu_2) {
    1.63 +    const char* sys_a_addr = "payto://BIC/SYSTEMA";
    1.64 +    const char* sys_b_addr = "payto://BIC/SYSTEMB";
    1.65 +    const char* sys_a_fpr = "4334D6DB751A8CA2B4944075462AFDB6DA3FB4B9";
    1.66 +    const char* sys_b_fpr = "F5199E0B0AC4059572DAD8EA76B63B2954139F26";
    1.67 +    
    1.68 +    slurp_and_import_key(session, "test_keys/pub/BIC_SYSTEMB_0x54139F26_pub.asc");
    1.69 +    slurp_and_import_key(session, "test_keys/priv/BIC_SYSTEMB_0x54139F26_priv.asc");
    1.70 +    slurp_and_import_key(session, "test_keys/pub/BIC_SYSTEMA_0xDA3FB4B9_pub.asc");
    1.71 +
    1.72 +    pEp_identity* me = new_identity(sys_b_addr, NULL, PEP_OWN_USERID, sys_b_addr);
    1.73 +    PEP_STATUS status = set_own_key(session, me, sys_b_fpr);
    1.74 +    ASSERT_EQ(status , PEP_STATUS_OK);
    1.75 +
    1.76 +    status = myself(session, me);
    1.77 +    ASSERT_EQ(status , PEP_STATUS_OK);
    1.78 +    ASSERT_TRUE(me->fpr && me->fpr[0] != '\0');  
    1.79 +    
    1.80 +    pEp_identity* you = new_identity(sys_b_addr, NULL, "SYSTEM_B", NULL);
    1.81 +    status = update_identity(session, you);
    1.82 +        
    1.83 +    string msg_txt = slurp("test_mails/system_a_to_b_755_part_1.eml");
    1.84 +    message* msg = NULL;
    1.85 +    
    1.86 +    mime_decode_message(msg_txt.c_str(), msg_txt.size(), &msg, NULL);
    1.87 +
    1.88 +    message* dec_msg = NULL;
    1.89 +    stringlist_t* keylist = NULL;
    1.90 +    PEP_rating rating;
    1.91 +    PEP_decrypt_flags_t flags = 0;
    1.92 +
    1.93 +    status = decrypt_message(session, msg, &dec_msg, &keylist, &rating, &flags); 
    1.94 +
    1.95 +    ASSERT_EQ(status, PEP_STATUS_OK);
    1.96 +    ASSERT_NE(dec_msg, nullptr);
    1.97 +    ASSERT_NE(dec_msg->from, nullptr);
    1.98 +    ASSERT_NE(dec_msg->to, nullptr);
    1.99 +    ASSERT_NE(dec_msg->to->ident, nullptr);
   1.100 +    ASSERT_STREQ(dec_msg->from->address, "payto://BIC/SYSTEMA");
   1.101 +    ASSERT_STREQ(dec_msg->to->ident->address, "payto://BIC/SYSTEMB");    
   1.102 +}