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