Tests: Add test JNI-153 - "'malloc_consolidate(): invalid chunk size' after receiving message from 'mistrusted' identity"
This is also the prototype for nextgen DistributedTests (RoleAbstraction,MultiNode, MultiIdents)JNI-153
parent
5c64bb184d
commit
273193ddd9
@ -0,0 +1,146 @@
|
||||
package foundation.pEp.jniadapter.test.jni153;
|
||||
|
||||
import foundation.pEp.jniadapter.Engine;
|
||||
import foundation.pEp.jniadapter.Identity;
|
||||
import foundation.pEp.jniadapter.Message;
|
||||
import foundation.pEp.jniadapter.decrypt_message_Return;
|
||||
import foundation.pEp.jniadapter.test.utils.TestCallbacks;
|
||||
import foundation.pEp.jniadapter.test.utils.model.*;
|
||||
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.FsMQIdentity;
|
||||
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.FsMQManager;
|
||||
import foundation.pEp.jniadapter.test.utils.transport.fsmqmanager.FsMQMessage;
|
||||
import foundation.pEp.pitytest.AbstractTestContext;
|
||||
import foundation.pEp.pitytest.TestContextInterface;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static foundation.pEp.pitytest.TestLogger.log;
|
||||
|
||||
public class CTXMultiNode extends AbstractTestContext {
|
||||
public Engine engine;
|
||||
public TestCallbacks callbacks;
|
||||
public FsMQManager transport;
|
||||
|
||||
// Model
|
||||
public TestModel model;
|
||||
// Mappings
|
||||
private NodeName ownNodeName;
|
||||
private TestNode ownNode;
|
||||
public TestIdentity myself;
|
||||
public TestIdentity partner;
|
||||
|
||||
CTXMultiNode(NodeName ownNodeName) {
|
||||
this.ownNodeName = ownNodeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestContextInterface init() throws Throwable {
|
||||
// pEp
|
||||
callbacks = new TestCallbacks();
|
||||
engine = new Engine();
|
||||
engine.setMessageToSendCallback(callbacks);
|
||||
engine.setNotifyHandshakeCallback(callbacks);
|
||||
|
||||
// Model
|
||||
model = setupModel();
|
||||
|
||||
// Setup Perspective
|
||||
ownNode = model.getNode(ownNodeName);
|
||||
myself = ownNode.getIdent();
|
||||
partner = myself.getDefaultPartner();
|
||||
|
||||
// Transport
|
||||
// Create own transport identity and Transport
|
||||
FsMQIdentity transportIdent = myself.getTransportIdent(ownNodeName);
|
||||
transport = new FsMQManager(transportIdent);
|
||||
|
||||
// Add all transport identities of the model
|
||||
for (TestIdentity ti : model.getAllIdents()) {
|
||||
transport.identities.addAll(ti.getAllTransportIdents());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void send(String pEpAddress, String msg) {
|
||||
//Find identity for address
|
||||
List<TestIdentity> res = model.getAllIdents().stream().filter(i -> {
|
||||
return i.pEpIdent.address.equals(pEpAddress);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if (res.size() > 1) {
|
||||
throw new RuntimeException("Unknown Error");
|
||||
} else if (res.size() <= 0) {
|
||||
throw new RuntimeException("Unknown address");
|
||||
}
|
||||
TestIdentity id = res.get(0);
|
||||
|
||||
for (FsMQIdentity tID : id.getAllTransportIdents()) {
|
||||
transport.sendMessage(tID.getAddress(), msg);
|
||||
// log("send() to: " + tID.getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
private TestModel setupModel() {
|
||||
TestModel ret = new TestModel();
|
||||
|
||||
ret.getNode(NodeName.NODE_A1).setRole(Role.ALICE);
|
||||
ret.getNode(NodeName.NODE_B1).setRole(Role.BOB);
|
||||
|
||||
ret.getIdent(Role.ALICE).setDefaultPartner(Role.BOB);
|
||||
ret.getIdent(Role.BOB).setDefaultPartner(Role.ALICE);
|
||||
// ret.getIdent(Role.CAROL).setDefaultPartner(Role.ALICE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Message reveiveMessage() {
|
||||
FsMQMessage rx = null;
|
||||
rx = transport.receiveMessage(2000);
|
||||
|
||||
// Receive
|
||||
Message msgIn = new Message(rx.getMsg());
|
||||
Message msgInDec = null;
|
||||
|
||||
decrypt_message_Return decRet = engine.decrypt_message(msgIn, null, 0);
|
||||
|
||||
msgInDec = decRet.dst;
|
||||
|
||||
String encFormat = "PLAIN";
|
||||
if (!msgIn.getLongmsg().equals(msgInDec.getLongmsg())) {
|
||||
encFormat = "CRYPT";
|
||||
}
|
||||
|
||||
log("-> : [" + encFormat + "] - " + msgInDec.getLongmsg());
|
||||
return msgInDec;
|
||||
}
|
||||
|
||||
public void sendMessage(Identity toIdent, String longMessage) {
|
||||
// Reply
|
||||
Message reply = new Message();
|
||||
Vector<Identity> to = new Vector<>();
|
||||
to.add(toIdent);
|
||||
reply.setTo(to);
|
||||
reply.setFrom(myself.pEpIdent);
|
||||
reply.setShortmsg("Reply");
|
||||
reply.setLongmsg(longMessage);
|
||||
reply.setDir(Message.Direction.Outgoing);
|
||||
|
||||
Message replyEnc = engine.encrypt_message(reply, null, Message.EncFormat.PEP);
|
||||
|
||||
String encFormat;
|
||||
longMessage = reply.getLongmsg();
|
||||
String transportMsg;
|
||||
if (replyEnc != null) {
|
||||
encFormat = "CRYPT";
|
||||
transportMsg = replyEnc.encodeMIME();
|
||||
} else {
|
||||
encFormat = "PLAIN";
|
||||
transportMsg = reply.encodeMIME();
|
||||
}
|
||||
log("<- : [" + encFormat + "] - " + longMessage);
|
||||
send(toIdent.address, transportMsg);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
include ../../../../../../../Makefile.conf
|
||||
include ../Makefile.conf
|
||||
|
||||
TEST_UNIT_NAME=jni153
|
||||
|
||||
JAVA_CLASSES+= \
|
||||
TestAlice.class \
|
||||
TestBob.class \
|
||||
CTXMultiNode.class
|
||||
|
||||
.PHONY: pitytest compile alice bob test clean
|
||||
|
||||
all: both compile
|
||||
|
||||
pitytest:
|
||||
$(MAKE) -C $(PITYTEST_DIR)
|
||||
|
||||
both:
|
||||
$(MAKE) bob&
|
||||
$(MAKE) alice
|
||||
|
||||
alice: compile clean-pep-home-alice
|
||||
cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice
|
||||
|
||||
bob: compile clean-pep-home-bob
|
||||
cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_BOB) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestBob
|
||||
|
||||
compile: $(JAVA_CLASSES) pitytest
|
||||
|
||||
%.class: %.java
|
||||
cd $(JAVA_CWD);$(JAVAC_CMD) -cp $(CLASSPATH) $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$<
|
||||
|
||||
clean:
|
||||
rm -f $(JAVA_CLASSES)
|
||||
rm -f *.class
|
||||
rm -f *.log
|
||||
rm -Rf .gnupg
|
||||
rm -Rf .lldb
|
||||
|
||||
clean-pep-home: clean-pep-home-alice clean-pep-home-bob
|
||||
|
||||
clean-pep-home-alice:
|
||||
rm -rf $(PEP_HOME_DIR_ALICE)/.pEp
|
||||
|
||||
clean-pep-home-bob:
|
||||
rm -rf $(PEP_HOME_DIR_BOB)/.pEp
|
@ -0,0 +1,41 @@
|
||||
package foundation.pEp.jniadapter.test.jni153;
|
||||
|
||||
import foundation.pEp.jniadapter.Message;
|
||||
import foundation.pEp.jniadapter.test.utils.AdapterTestUtils;
|
||||
import foundation.pEp.jniadapter.test.utils.model.NodeName;
|
||||
import foundation.pEp.pitytest.TestSuite;
|
||||
import foundation.pEp.pitytest.TestUnit;
|
||||
import foundation.pEp.pitytest.utils.TestUtils;
|
||||
|
||||
import static foundation.pEp.pitytest.TestLogger.log;
|
||||
|
||||
|
||||
class TestAlice {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TestSuite.getDefault().setVerbose(true);
|
||||
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
|
||||
|
||||
CTXMultiNode JNI153Ctx = new CTXMultiNode(NodeName.NODE_A1);
|
||||
|
||||
new TestUnit<CTXMultiNode>("test", JNI153Ctx, ctx -> {
|
||||
ctx.myself.pEpIdent = ctx.engine.myself(ctx.myself.pEpIdent);
|
||||
log(AdapterTestUtils.identityToString(ctx.myself.pEpIdent, true));
|
||||
ctx.transport.clearOwnQueue();
|
||||
int counter = 0;
|
||||
while (true) {
|
||||
Message src = AdapterTestUtils.makeNewTestMessage(ctx.myself.pEpIdent, ctx.partner.pEpIdent, Message.Direction.Outgoing);
|
||||
src.setLongmsg("UNIQUE_" + String.valueOf(counter));
|
||||
ctx.sendMessage(ctx.partner.pEpIdent, src.getLongmsg());
|
||||
ctx.reveiveMessage();
|
||||
|
||||
counter++;
|
||||
TestUtils.sleep(3000);
|
||||
// TestUtils.readKey();
|
||||
}
|
||||
});
|
||||
|
||||
TestSuite.getDefault().run();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
package foundation.pEp.jniadapter.test.jni153;
|
||||
|
||||
import foundation.pEp.jniadapter.Message;
|
||||
import foundation.pEp.jniadapter.test.utils.AdapterTestUtils;
|
||||
import foundation.pEp.jniadapter.test.utils.model.NodeName;
|
||||
import foundation.pEp.pitytest.TestSuite;
|
||||
import foundation.pEp.pitytest.TestUnit;
|
||||
import foundation.pEp.pitytest.utils.TestUtils;
|
||||
|
||||
import static foundation.pEp.pitytest.TestLogger.log;
|
||||
|
||||
class TestBob {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TestSuite.getDefault().setVerbose(true);
|
||||
TestSuite.getDefault().setTestColor(TestUtils.TermColor.YELLOW);
|
||||
|
||||
CTXMultiNode JNI153Ctx = new CTXMultiNode(NodeName.NODE_B1);
|
||||
|
||||
new TestUnit<CTXMultiNode>("test", JNI153Ctx, ctx -> {
|
||||
ctx.myself.pEpIdent = ctx.engine.myself(ctx.myself.pEpIdent);
|
||||
log(AdapterTestUtils.identityToString(ctx.myself.pEpIdent, true));
|
||||
ctx.transport.clearOwnQueue();
|
||||
int counter = 0;
|
||||
|
||||
while (true) {
|
||||
TestUtils.sleep(3000);
|
||||
Message msgRx = ctx.reveiveMessage();
|
||||
|
||||
//Mistrust
|
||||
if (counter == 1) {
|
||||
log("Mistrusting");
|
||||
ctx.engine.keyMistrusted(msgRx.getFrom());
|
||||
}
|
||||
|
||||
ctx.sendMessage(msgRx.getFrom(), msgRx.getLongmsg() + " - ACK");
|
||||
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
|
||||
TestSuite.getDefault().run();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue