pEpEngineTest now imports its own keys
authorKrista Bennett <krista@pep-project.org>
Mon, 25 Sep 2017 15:56:10 +0200
changeset 2101be4563366499
parent 2100 dbbcb9ef5aae
child 2102 471d84738b78
pEpEngineTest now imports its own keys
Makefile.conf
test/pEpEngineTest.cc
     1.1 --- a/Makefile.conf	Mon Sep 25 15:50:16 2017 +0200
     1.2 +++ b/Makefile.conf	Mon Sep 25 15:56:10 2017 +0200
     1.3 @@ -46,7 +46,7 @@
     1.4  # If empty, create a release build.
     1.5  # Otherwise, create a debug build.
     1.6  # This variable is ineffective in your override.conf file.
     1.7 -DEBUG=
     1.8 +DEBUG=YES
     1.9  
    1.10  # If empty, suppress compiler warnings.
    1.11  # Otherwise, print warnings.
     2.1 --- a/test/pEpEngineTest.cc	Mon Sep 25 15:50:16 2017 +0200
     2.2 +++ b/test/pEpEngineTest.cc	Mon Sep 25 15:56:10 2017 +0200
     2.3 @@ -9,15 +9,29 @@
     2.4  
     2.5  #include <assert.h>
     2.6  #include <string.h>
     2.7 +#include <sstream>
     2.8 +
     2.9  
    2.10  #include "../src/pEpEngine.h"
    2.11  #include "../src/keymanagement.h"
    2.12  
    2.13 -
    2.14  using namespace std;
    2.15  
    2.16  typedef std::string Buffer;
    2.17  
    2.18 +std::string slurp(const std::string& filename)
    2.19 +{
    2.20 +        std::ifstream input(filename.c_str());
    2.21 +        if(!input)
    2.22 +        {
    2.23 +                throw std::runtime_error("Cannot read file \"" + filename + "\"! ");
    2.24 +        }
    2.25 +
    2.26 +        std::stringstream sstr;
    2.27 +        sstr << input.rdbuf();
    2.28 +        return sstr.str();
    2.29 +}
    2.30 +
    2.31  // no C++11, yet? So do our own implementation:
    2.32  namespace{
    2.33      std::string to_string(unsigned long u)
    2.34 @@ -96,6 +110,35 @@
    2.35      cout << "dropping second session\n";
    2.36      release(second_session);
    2.37  
    2.38 +    cout << "Importing keys...";
    2.39 +    string pub_key = slurp("test_keys/pub/pep-test-alice-0x6FF00E97_pub.asc");
    2.40 +    string priv_key = slurp("test_keys/priv/pep-test-alice-0x6FF00E97_priv.asc");
    2.41 +
    2.42 +    PEP_STATUS statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
    2.43 +    PEP_STATUS statuspriv = import_key(session, priv_key.c_str(), priv_key.length(), NULL);
    2.44 +    assert(statuspub == PEP_STATUS_OK);
    2.45 +    assert(statuspriv == PEP_STATUS_OK);
    2.46 +
    2.47 +    pub_key = slurp("test_keys/pub/pep-test-john-0x70DCF575_pub.asc");
    2.48 +    priv_key = slurp("test_keys/priv/pep-test-john-0x70DCF575_priv.asc");
    2.49 +
    2.50 +    statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
    2.51 +    statuspriv = import_key(session, priv_key.c_str(), priv_key.length(), NULL);
    2.52 +    assert(statuspub == PEP_STATUS_OK);
    2.53 +    assert(statuspriv == PEP_STATUS_OK);
    2.54 +
    2.55 +    pub_key = slurp("test_keys/pub/pep-test-bob-0xC9C2EE39_pub.asc");
    2.56 +
    2.57 +    statuspub = import_key(session, pub_key.c_str(), pub_key.length(), NULL);
    2.58 +    assert(statuspub == PEP_STATUS_OK);
    2.59 +    assert(statuspriv == PEP_STATUS_OK);
    2.60 +
    2.61 +
    2.62 +    cout << "creating message…\n";
    2.63 +    pEp_identity* alice = new_identity("pep.test.alice@pep-project.org", "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97", PEP_OWN_USERID, "Alice Test");
    2.64 +    pEp_identity* bob = new_identity("pep.test.bob@pep-project.org", NULL, "42", "Bob Test");
    2.65 +
    2.66 +
    2.67      cout << "logging test\n";
    2.68      log_event(session, "log test", "pEp Engine Test", "This is a logging test sample.", "please ignore this line");
    2.69