Browse Source

adding test_leave_device_group

pull/1/head
Volker Birk 5 years ago
parent
commit
582f7135e7
  1. 46
      test/framework.cc
  2. 12
      test/framework.hh
  3. 84
      test/test_leave_device_group.cc

46
test/framework.cc

@ -14,6 +14,9 @@
#include <pEp/keymanagement.h> #include <pEp/keymanagement.h>
#include <pEp/mime.h> #include <pEp/mime.h>
#include <pEp/message_api.h>
#include <pEp/sync_codec.h>
#include <pEp/distribution_codec.h>
pEp::Test::Transport pEp::Test::transport; pEp::Test::Transport pEp::Test::transport;
std::string pEp::Test::path; std::string pEp::Test::path;
@ -87,7 +90,12 @@ namespace pEp {
return shared_ptr<::message>(msg, ::free_message); return shared_ptr<::message>(msg, ::free_message);
} }
Message make_message(string text) Identity make_identity(::pEp_identity *ident)
{
return shared_ptr<::pEp_identity>(ident , ::free_identity);
}
Message mime_parse(string text)
{ {
::message *msg; ::message *msg;
bool has_possible_pEp_msg; bool has_possible_pEp_msg;
@ -96,7 +104,7 @@ namespace pEp {
return make_message(msg); return make_message(msg);
} }
string make_string(Message msg) string mime_compose(Message msg)
{ {
char *mimetext; char *mimetext;
PEP_STATUS status = ::mime_encode_message(msg.get(), false, &mimetext, false); PEP_STATUS status = ::mime_encode_message(msg.get(), false, &mimetext, false);
@ -106,6 +114,40 @@ namespace pEp {
return text; return text;
} }
string make_pEp_msg(Message msg)
{
string text;
::message *_dst;
stringlist_t *keylist;
PEP_rating rating;
PEP_decrypt_flags_t flags = 0;
PEP_STATUS status = ::decrypt_message(session(), msg.get(), &_dst, &keylist, &rating, &flags);
throw_status(status);
Message dst = make_message(_dst);
for (auto a = _dst->attachments; a && a->value; a = a->next) {
if (string("application/pEp.sync") == a->mime_type) {
char *_text;
status = PER_to_XER_Sync_msg(a->value, a->size, &_text);
throw_status(status);
text += _text;
pEp_free(_text);
return text;
}
else if (string("application/pEp.distribution") == a->mime_type) {
char *_text;
status = PER_to_XER_Distribution_msg(a->value, a->size, &_text);
throw_status(status);
text += _text;
pEp_free(_text);
return text;
}
}
return text;
}
Message Transport::recv() Message Transport::recv()
{ {
mkdir(inbox_path.c_str(), 0770); mkdir(inbox_path.c_str(), 0770);

12
test/framework.hh

@ -19,16 +19,24 @@ namespace pEp {
void import_key_from_file(string filename); void import_key_from_file(string filename);
using Message = shared_ptr<::message>; using Message = shared_ptr<::message>;
using Identity= shared_ptr<::pEp_identity>;
// use this instead of constructor to auto assign ::free_message as // use this instead of constructor to auto assign ::free_message as
// deleter // deleter
Message make_message(::message *msg); Message make_message(::message *msg);
// use this instead of constructor to auto assign ::free_identity as
// deleter
Identity make_identity(::pEp_identity *ident);
// MIME parser // MIME parser
Message make_message(string text); Message mime_parse(string text);
// MIME composer // MIME composer
string make_string(Message msg); string mime_compose(Message msg);
// Sync and Distribution decoder
string make_pEp_msg(Message msg);
struct Transport { struct Transport {
string inbox_path = "inbox"; string inbox_path = "inbox";

84
test/test_leave_device_group.cc

@ -0,0 +1,84 @@
#include <iostream>
#include "framework.hh"
#include "passphrase_cache.hh"
#include "callback_dispatcher.hh"
#include <pEp/sync_api.h>
using namespace pEp;
using namespace pEp::Adapter;
using namespace std;
PEP_STATUS test_messageToSend(::message *_msg)
{
Test::Message msg = Test::make_message(_msg);
cerr << Test::make_pEp_msg(msg);
return PEP_STATUS_OK;
}
PEP_STATUS test_notifyHandshake(pEp_identity *_me, pEp_identity *_partner, sync_handshake_signal signal)
{
Test::Identity me = Test::make_identity(_me);
Test::Identity partner = Test::make_identity(_partner);
return PEP_STATUS_OK;
}
int main(int argc, char **argv)
{
Test::setup(argc, argv);
// set up two own identites for sync
passphrase_cache.add("erwin");
passphrase_cache.add("bob");
const char* bob_filename = ENGINE_TEST "/test_keys/bob-primary-with-password-bob-subkey-without.pgp";
const char* bob_fpr = "5C76378A62B04CF3F41BEC8D4940FC9FA1878736";
const char* erwin_filename = ENGINE_TEST "/test_keys/erwin_normal_encrypted.pgp";
const char* erwin_fpr = "CBA968BC01FCEB89F04CCF155C5E9E3F0420A570";
Test::import_key_from_file(bob_filename);
Test::import_key_from_file(erwin_filename);
pEp_identity* bob = ::new_identity("bob@example.org", bob_fpr, "BOB", "Bob Dog");
PEP_STATUS status = ::set_own_key(session(), bob, bob_fpr);
assert(status == PEP_STATUS_OK);
status = ::enable_identity_for_sync(session(), bob);
assert(status == PEP_STATUS_OK);
pEp_identity* erwin = ::new_identity("erwin@example.org", erwin_fpr, "BOB", "Bob is Erwin");
status = ::set_own_key(session(), erwin, erwin_fpr);
assert(status == PEP_STATUS_OK);
status = ::enable_identity_for_sync(session(), erwin);
assert(status == PEP_STATUS_OK);
// simulate a device group by setting the identities to in sync
status = set_identity_flags(session(), bob, PEP_idf_devicegroup);
status = set_identity_flags(session(), erwin, PEP_idf_devicegroup);
// register at callback_dispatcher and start sync
callback_dispatcher.add(test_messageToSend, test_notifyHandshake);
CallbackDispatcher::start_sync();
// stop sync
CallbackDispatcher::stop_sync();
// free own identities and release session and release session
::free_identity(bob);
::free_identity(erwin);
session(Adapter::release);
return 0;
}
Loading…
Cancel
Save