Browse Source

Test: test_tofu - updated

LIB-11
heck 4 years ago
parent
commit
8da80a4b14
  1. 48
      test/test_tofu.cc

48
test/test_tofu.cc

@ -13,7 +13,7 @@ using namespace pEp::Adapter;
using namespace pEp::Test::Utils; using namespace pEp::Test::Utils;
using namespace pEp::PityTest11; using namespace pEp::PityTest11;
using TestUnit = PityUnit<PityPerspective>; using TestUnitSwarm = PityUnit<PityPerspective>;
bool did_tx_encrypted = false; bool did_tx_encrypted = false;
@ -28,7 +28,7 @@ void send(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{ {
// Create Message // Create Message
pity.log("Initiating TOFU..."); pity.log("Initiating TOFU...");
pEpMessage msg = createMessage(ctx->own_ident, ctx->cpt_name, "INIT TOFU"); pEpMessage msg = createMessage(ctx->own_ident, ctx->getCpt().addr, "INIT TOFU");
pity.log("BEFORE encrypt: \n" + Utils::to_string(msg.get())); pity.log("BEFORE encrypt: \n" + Utils::to_string(msg.get()));
//Encrypt //Encrypt
@ -41,10 +41,10 @@ void send(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
std::string mime_text = mimeEncode(std::get<0>(msg_encrypted)); std::string mime_text = mimeEncode(std::get<0>(msg_encrypted));
// Send // Send
pity.transport()->sendMsg(ctx->cpt_name, mime_text); pity.transport()->sendMsg(ctx->getCpt().addr, mime_text);
} }
MinMsgRx receive(PityUnit<PityPerspective> &pity, PityPerspective *ctx) MinMsgRx tofu_receive(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
{ {
MinMsgRx ret; MinMsgRx ret;
// Receive // Receive
@ -67,7 +67,7 @@ MinMsgRx receive(PityUnit<PityPerspective> &pity, PityPerspective *ctx)
return ret; return ret;
} }
void reply(PityUnit<PityPerspective> &pity, PityPerspective *ctx, MinMsgRx msg_orig) void receiveAndReply(PityUnit<PityPerspective> &pity, PityPerspective *ctx, MinMsgRx msg_orig)
{ {
// Create Message // Create Message
std::string addr_orig = std::get<0>(msg_orig); std::string addr_orig = std::get<0>(msg_orig);
@ -81,12 +81,6 @@ void reply(PityUnit<PityPerspective> &pity, PityPerspective *ctx, MinMsgRx msg_o
// Encrypt // Encrypt
pity.log("TX message - BEFORE encrypt: \n" + Utils::to_string(msg.get())); pity.log("TX message - BEFORE encrypt: \n" + Utils::to_string(msg.get()));
// pEpIdent tmp_ident = createRawIdent(addr_orig);
// tmp_ident.get()->user_id = strdup("23");
// PEP_STATUS status = ::update_identity(Adapter::session(),tmp_ident.get());
// throw_status(status);
// pity.log("IDENTZZZ:" + Utils::to_string(tmp_ident.get()));
EncryptResult eres = encryptMessage(msg); EncryptResult eres = encryptMessage(msg);
pEpMessage msg_encrypted = std::get<0>(eres); pEpMessage msg_encrypted = std::get<0>(eres);
did_tx_encrypted = std::get<2>(eres); did_tx_encrypted = std::get<2>(eres);
@ -104,7 +98,7 @@ int tofu(PityUnit<PityPerspective> &pity, PityPerspective *ctx, bool init)
{ {
pity.log("Model : " + ctx->model.getName()); pity.log("Model : " + ctx->model.getName());
pity.log("myself : " + ctx->own_name); pity.log("myself : " + ctx->own_name);
pity.log("partner: " + ctx->cpt_name); pity.log("partner: " + ctx->getCpt().addr);
pity.log("HOME : " + std::string(getenv("HOME"))); pity.log("HOME : " + std::string(getenv("HOME")));
pity.log("PUD : " + std::string(::per_user_directory())); pity.log("PUD : " + std::string(::per_user_directory()));
@ -118,14 +112,14 @@ int tofu(PityUnit<PityPerspective> &pity, PityPerspective *ctx, bool init)
send(pity, ctx); send(pity, ctx);
} }
MinMsgRx rx_msg = receive(pity, ctx); MinMsgRx rx_msg = tofu_receive(pity, ctx);
reply(pity, ctx, rx_msg); receiveAndReply(pity, ctx, rx_msg);
if (!init) { if (!init) {
receive(pity, ctx); tofu_receive(pity, ctx);
} }
PITYASSERT(did_tx_encrypted, "could never send encrypted"); PITYASSERT(did_tx_encrypted, "could never tofu_send encrypted");
PITYASSERT(did_rx_encrypted, "no encrypted msg received"); PITYASSERT(did_rx_encrypted, "no encrypted msg received");
return 0; return 0;
} }
@ -136,19 +130,23 @@ int main(int argc, char *argv[])
PityUnit<PityPerspective>::debug_log_enabled = false; PityUnit<PityPerspective>::debug_log_enabled = false;
int nodesCount = 2; int nodesCount = 2;
PityModel model{ "test_tofu", nodesCount }; PityModel model{ "test_tofu_react", nodesCount };
TestUnit suite("suite_tofu"); TestUnitSwarm suite("suite_tofu");
PitySwarm swarm{ "swarm_tofu", model }; PitySwarm swarm{ "swarm_tofu", model };
suite.addRef(swarm.getSwarmUnit()); suite.addRef(swarm.getSwarmUnit());
swarm.addTestUnit(0, TestUnit("tofu1", [](PityUnit<PityPerspective> &unit, PityPerspective *ctx) { swarm.addTestUnit(
return tofu(unit, ctx, true); 0,
})); TestUnitSwarm("tofu1", [](PityUnit<PityPerspective> &unit, PityPerspective *ctx) {
return tofu(unit, ctx, true);
swarm.addTestUnit(1, TestUnit("tofu2", [](PityUnit<PityPerspective> &unit, PityPerspective *ctx) { }));
return tofu(unit, ctx, false);
})); swarm.addTestUnit(
1,
TestUnitSwarm("tofu2", [](PityUnit<PityPerspective> &unit, PityPerspective *ctx) {
return tofu(unit, ctx, false);
}));
suite.run(); suite.run();
} }
Loading…
Cancel
Save