test/src/engine_tests/SignOnlyTests.cc
author Krista Bennett <krista@pep-project.org>
Mon, 10 Dec 2018 18:08:41 +0100
branchsync
changeset 3176 37b3ba0bcfe2
parent 3142 a095aa1286eb
child 3276 c0b3430f1f1d
child 3292 673b8c6da681
permissions -rw-r--r--
ENGINE-485: Finally, the nightmare that is NetPGP sign-only (detached sigs) is over. (Or is it?)
krista@3141
     1
// This file is under GNU General Public License 3.0
krista@3141
     2
// see LICENSE.txt
krista@3141
     3
krista@3141
     4
#include <stdlib.h>
krista@3141
     5
#include <string>
krista@3142
     6
#include <cstring>
krista@3141
     7
#include <cpptest.h>
krista@3176
     8
#include <fstream>
krista@3141
     9
krista@3141
    10
#include "pEpEngine.h"
krista@3141
    11
krista@3141
    12
#include "test_util.h"
krista@3141
    13
#include "EngineTestIndividualSuite.h"
krista@3141
    14
#include "SignOnlyTests.h"
krista@3141
    15
krista@3141
    16
using namespace std;
krista@3141
    17
krista@3141
    18
SignOnlyTests::SignOnlyTests(string suitename, string test_home_dir) :
krista@3141
    19
    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
krista@3141
    20
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SignOnlyTests::check_sign_only"),
krista@3141
    21
                                                                      static_cast<Func>(&SignOnlyTests::check_sign_only)));
krista@3141
    22
}
krista@3141
    23
krista@3141
    24
void SignOnlyTests::check_sign_only() {
krista@3141
    25
    slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
krista@3141
    26
    slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
krista@3141
    27
    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
krista@3141
    28
    string msg_text = "Grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr! I mean, yo. Greetings to Meesti.\n - Alice";
krista@3176
    29
    ofstream test_file;
krista@3176
    30
    test_file.open("signed_text.txt");
krista@3176
    31
    test_file << msg_text;
krista@3176
    32
    test_file.close();
krista@3141
    33
    char* signed_text = NULL;
krista@3141
    34
    size_t signed_text_size = 0;
krista@3142
    35
krista@3142
    36
    stringlist_t* keylist = NULL;
krista@3141
    37
    
krista@3141
    38
    PEP_STATUS status = sign_only(session, msg_text.c_str(), msg_text.size(), alice_fpr, &signed_text, &signed_text_size);
krista@3176
    39
    TEST_ASSERT_MSG(status == PEP_STATUS_OK, tl_status_string(status));
krista@3141
    40
    cout << signed_text << endl;
krista@3176
    41
    test_file.open("signature.txt");
krista@3176
    42
    test_file << signed_text;
krista@3176
    43
    test_file.close();
krista@3141
    44
        
krista@3142
    45
    status = verify_text(session, msg_text.c_str(), msg_text.size(),
krista@3142
    46
                         signed_text, signed_text_size, &keylist);
krista@3176
    47
krista@3176
    48
#ifndef USE_NETPGP                         
krista@3176
    49
    TEST_ASSERT_MSG(status == PEP_VERIFIED, tl_status_string(status));
krista@3176
    50
#else    
krista@3176
    51
    TEST_ASSERT_MSG(status == PEP_VERIFIED_AND_TRUSTED, tl_status_string(status));
krista@3176
    52
#endif
krista@3142
    53
    TEST_ASSERT(keylist);
krista@3142
    54
    TEST_ASSERT(keylist->value);
krista@3142
    55
    TEST_ASSERT(strcmp(keylist->value, alice_fpr) == 0);
krista@3142
    56
    
krista@3142
    57
    // FIXME: free stuff
krista@3142
    58
    
krista@3141
    59
    TEST_ASSERT(true);
krista@3141
    60
}