test/src/engine_tests/SignOnlyTests.cc
author Krista Bennett <krista@pep-project.org>
Tue, 20 Nov 2018 15:43:19 +0100
branchsync
changeset 3142 a095aa1286eb
parent 3141 c931141752fe
child 3176 37b3ba0bcfe2
permissions -rw-r--r--
Signing and Verification on sign only appears to work (minimal test)
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@3141
     8
krista@3141
     9
#include "pEpEngine.h"
krista@3141
    10
krista@3141
    11
#include "test_util.h"
krista@3141
    12
#include "EngineTestIndividualSuite.h"
krista@3141
    13
#include "SignOnlyTests.h"
krista@3141
    14
krista@3141
    15
using namespace std;
krista@3141
    16
krista@3141
    17
SignOnlyTests::SignOnlyTests(string suitename, string test_home_dir) :
krista@3141
    18
    EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir) {
krista@3141
    19
    add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("SignOnlyTests::check_sign_only"),
krista@3141
    20
                                                                      static_cast<Func>(&SignOnlyTests::check_sign_only)));
krista@3141
    21
}
krista@3141
    22
krista@3141
    23
void SignOnlyTests::check_sign_only() {
krista@3141
    24
    slurp_and_import_key(session, "test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
krista@3141
    25
    slurp_and_import_key(session, "test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");    
krista@3141
    26
    const char* alice_fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
krista@3141
    27
    string msg_text = "Grrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr! I mean, yo. Greetings to Meesti.\n - Alice";
krista@3141
    28
    char* signed_text = NULL;
krista@3141
    29
    size_t signed_text_size = 0;
krista@3142
    30
krista@3142
    31
    stringlist_t* keylist = NULL;
krista@3141
    32
    
krista@3141
    33
    PEP_STATUS status = sign_only(session, msg_text.c_str(), msg_text.size(), alice_fpr, &signed_text, &signed_text_size);
krista@3141
    34
    TEST_ASSERT(status == PEP_STATUS_OK);
krista@3141
    35
    cout << signed_text << endl;
krista@3141
    36
        
krista@3142
    37
    status = verify_text(session, msg_text.c_str(), msg_text.size(),
krista@3142
    38
                         signed_text, signed_text_size, &keylist);
krista@3142
    39
    TEST_ASSERT(status == PEP_VERIFIED);
krista@3142
    40
    TEST_ASSERT(keylist);
krista@3142
    41
    TEST_ASSERT(keylist->value);
krista@3142
    42
    TEST_ASSERT(strcmp(keylist->value, alice_fpr) == 0);
krista@3142
    43
    
krista@3142
    44
    // FIXME: free stuff
krista@3142
    45
    
krista@3141
    46
    TEST_ASSERT(true);
krista@3141
    47
}