Added test to ensure encrypted mails go out with X-pEp-Version from the engine
authorKrista Grothoff <krista@pep-project.org>
Tue, 15 Nov 2016 23:40:28 +0100
changeset 1400909966aa9d93
parent 1393 ee4bf9e19635
child 1402 bf7b1ad6f43a
child 1428 aefb57561f8e
Added test to ensure encrypted mails go out with X-pEp-Version from the engine
test/decorate_test.cc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/decorate_test.cc	Tue Nov 15 23:40:28 2016 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +#include <stdlib.h>
     1.5 +#include <string.h>
     1.6 +#include "platform.h"
     1.7 +#include <iostream>
     1.8 +#include <fstream>
     1.9 +#include <assert.h>
    1.10 +#include <sstream>
    1.11 +#include "mime.h"
    1.12 +#include "message_api.h"
    1.13 +
    1.14 +using namespace std;
    1.15 +
    1.16 +int main() {
    1.17 +    cout << "\n*** check that X-pEp-Version is added to decorated text ***\n\n";
    1.18 +
    1.19 +    PEP_SESSION session;
    1.20 +    
    1.21 +    cout << "calling init()\n";
    1.22 +    PEP_STATUS status1 = init(&session);
    1.23 +    assert(status1 == PEP_STATUS_OK);
    1.24 +    assert(session);
    1.25 +    cout << "init() completed.\n";
    1.26 +
    1.27 +    // message_api test code
    1.28 +
    1.29 +    cout << "creating message…\n";
    1.30 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", NULL, PEP_OWN_USERID, "Alice Test");
    1.31 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
    1.32 +    alice->me = true;
    1.33 +    identity_list* to_list = new_identity_list(bob); // to bob
    1.34 +    message* outgoing_message = new_message(PEP_dir_outgoing);
    1.35 +    assert(outgoing_message);
    1.36 +    outgoing_message->from = alice;
    1.37 +    outgoing_message->to = to_list;
    1.38 +    outgoing_message->shortmsg = strdup("Greetings, humans!");
    1.39 +    outgoing_message->attachments = new_bloblist(NULL, 0, "application/octet-stream", NULL);
    1.40 +    outgoing_message->longmsg = strdup("This is a dumb message.\nBut it's done.\n");
    1.41 +    assert(outgoing_message->longmsg);
    1.42 +    cout << "message created.\n";
    1.43 +
    1.44 +    char* encoded_text = nullptr;
    1.45 +
    1.46 +    message* encrypted_msg = nullptr;
    1.47 +    cout << "calling encrypt_message\n";
    1.48 +    PEP_STATUS status = encrypt_message (session, outgoing_message, NULL, &encrypted_msg, PEP_enc_PGP_MIME, 0);
    1.49 +    cout << "encrypt_message() returns " << std::hex << status << '.' << endl;
    1.50 +    assert(status == PEP_STATUS_OK);
    1.51 +    assert(encrypted_msg);
    1.52 +    cout << "message encrypted.\n";
    1.53 +    
    1.54 +    status = mime_encode_message(encrypted_msg, false, &encoded_text);
    1.55 +    assert(status == PEP_STATUS_OK);
    1.56 +    assert(encoded_text);
    1.57 +    
    1.58 +    bool contains_version = false;
    1.59 +    
    1.60 +    const char* version_str = "X-pEp-Version: ";
    1.61 +    size_t version_prefix_len = strlen(version_str);
    1.62 +    
    1.63 +    istringstream f(encoded_text);
    1.64 +    string enc_string;
    1.65 +    while (getline(f, enc_string)) {
    1.66 +        if (strncmp(enc_string.c_str(), version_str, version_prefix_len) == 0)
    1.67 +            contains_version = true;
    1.68 +    }
    1.69 +    assert(contains_version);
    1.70 +    
    1.71 +    if (contains_version)
    1.72 +        cout << "Version string in encrypted message, as it should be." << endl;
    1.73 +    
    1.74 +    cout << "freeing messages…\n";
    1.75 +    free_message(encrypted_msg);
    1.76 +    free_message(outgoing_message);
    1.77 +    cout << "done.\n";
    1.78 +
    1.79 +    cout << "calling release()\n";
    1.80 +    release(session);
    1.81 +    return 0;
    1.82 +}