Browse Source

Tests: test_tofu now assertive

LIB-11
heck 4 years ago
parent
commit
a05c596be3
  1. 95
      test/test_tofu.cc

95
test/test_tofu.cc

@ -19,45 +19,80 @@ using namespace pEp::Adapter;
using namespace pEp::Test::Utils; using namespace pEp::Test::Utils;
using namespace pEp::PityTest11; using namespace pEp::PityTest11;
bool did_tx_encrypted = false;
bool did_rx_encrypted = false;
void tofu(PityUnit<PityPerspective> &unit, PityPerspective *ctx, bool init) // The most minimal received msg contains of:
// * from addres
// * content
using MinMsgRx =std::tuple<std::string, std::string>;
void send(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{
pity.log("Initiating TOFU...");
pEpMessage msg = createMessage(ctx->own_ident, ctx->cpt_name, "INIT TOFU");
EncryptResult msg_enc = encryptAndEncode(msg);
std::string mime_text = std::get<1>(msg_enc);
did_tx_encrypted = std::get<2>(msg_enc);
pity.transport()->sendMsg(ctx->cpt_name, mime_text);
}
MinMsgRx receive(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{
MinMsgRx ret;
std::string mime_data_rx = pity.transport()->receiveMsg();
DecryptResult msg_rx = decryptAndDecode(mime_data_rx);
pEpMessage msg_rx_dec = std::get<0>(msg_rx);
did_rx_encrypted = std::get<4>(msg_rx);
pity.log("rx msg is encrypted: " + std::to_string(did_rx_encrypted));
std::get<0>(ret) = std::string(msg_rx_dec->from->address);
std::get<1>(ret) = std::string(msg_rx_dec->longmsg);
return ret;
}
void reply(PityUnit<PityPerspective> &pity, PityPerspective *ctx, MinMsgRx msg_orig)
{ {
unit.log("Model : " + ctx->model.getName()); std::string addr_orig = std::get<0>(msg_orig);
unit.log("myself : " + ctx->name); std::string longmsg_orig = std::get<1>(msg_orig);
unit.log("partner: " + ctx->partner);
unit.log("HOME : " + std::string(getenv("HOME"))); pEpMessage msg = createMessage(
unit.log("PUD : " + std::string(::per_user_directory())); ctx->own_ident,
addr_orig,
"REPLY[ " + std::string(addr_orig) + " ] " + longmsg_orig);
EncryptResult eres = encryptAndEncode(msg);
std::string mime_data_tx = std::get<1>(eres);
did_tx_encrypted = std::get<2>(eres);
pity.log("tx msg is encrypted: " + std::to_string(did_tx_encrypted));
pity.transport()->sendMsg(addr_orig, mime_data_tx);
}
void tofu(PityUnit<PityPerspective> &pity, PityPerspective *ctx, bool init)
{
pity.log("Model : " + ctx->model.getName());
pity.log("myself : " + ctx->own_name);
pity.log("partner: " + ctx->cpt_name);
pity.log("HOME : " + std::string(getenv("HOME")));
pity.log("PUD : " + std::string(::per_user_directory()));
// Create new identity // Create new identity
unit.log("updating or creating identity for me"); pity.log("updating or creating identity for me");
pEpIdent my_ident = createIdentity(ctx->name, true); ctx->own_ident = createIdentity(ctx->own_name, true);
::PEP_STATUS status = ::myself(Adapter::session(), my_ident.get()); ::PEP_STATUS status = ::myself(Adapter::session(), ctx->own_ident.get());
pEp::throw_status(status); pEp::throw_status(status);
if (init) { if (init) {
unit.log("Initiating TOFU..."); send(pity, ctx);
pEpMessage msg = createMessage(my_ident, ctx->partner, "INIT TOFU");
std::string mime_data = encryptAndEncode(msg);
unit.transport()->sendMsg(ctx->partner, mime_data);
} }
while (true) { MinMsgRx rx_msg = receive(pity,ctx);
std::string mime_data_rx = unit.transport()->receiveMsg(); reply(pity,ctx, rx_msg);
pEpMessage msg_rx = decryptAndDecode(mime_data_rx);
unit.log(">"); if(!init) {
// receive(pity,ctx);
pEpIdent rx_from = wrap(msg_rx->from);
std::string rx_longmessage = msg_rx->longmsg;
//
pEpMessage msg = createMessage(
my_ident,
rx_from->address,
"REPLY[ " + std::string(rx_from->address) + " ] " + rx_longmessage);
std::string mime_data_tx = encryptAndEncode(msg);
unit.transport()->sendMsg(rx_from->address, mime_data_tx);
unit.log("<");
Utils::sleep_millis(1000);
} }
PTASSERT(did_tx_encrypted, "could never send encrypted");
PTASSERT(did_rx_encrypted, "no encrypted msg received");
} }

Loading…
Cancel
Save