Browse Source

AdapterBaseTestContext: Add AttachmentList and change naming of default ctx messages.

JNI-147
heck 4 years ago
parent
commit
2c390d1652
  1. 11
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  2. 2
      test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java
  3. 10
      test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java
  4. 9
      test/java/foundation/pEp/jniadapter/test/jni114/TestAlice.java
  5. 5
      test/java/foundation/pEp/jniadapter/test/jni118/TestAlice.java
  6. 4
      test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java
  7. 18
      test/java/foundation/pEp/jniadapter/test/regression/TestMain.java
  8. 25
      test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java
  9. 29
      test/java/foundation/pEp/jniadapter/test/utils/AttachmentList.java

11
test/java/foundation/pEp/jniadapter/test/basic/TestMain.java

@ -1,6 +1,5 @@
package foundation.pEp.jniadapter.test.basic; package foundation.pEp.jniadapter.test.basic;
import foundation.pEp.jniadapter.Blob;
import foundation.pEp.jniadapter.Identity; import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.Message; import foundation.pEp.jniadapter.Message;
import foundation.pEp.jniadapter.decrypt_message_Return; import foundation.pEp.jniadapter.decrypt_message_Return;
@ -49,21 +48,21 @@ class TestMain {
}); });
new TestUnit<BasicTestContext>("setAttachments", btc, ctx -> { new TestUnit<BasicTestContext>("setAttachments", btc, ctx -> {
log("Adding " + ctx.attachmentsLen + " attachments"); log("Adding " + ctx.attachmentList.getCount() + " attachments");
ctx.msgToBob.setAttachments(ctx.attachments); ctx.msgAliceToBob.setAttachments(ctx.attachmentList.getAttachments());
}); });
new TestUnit<BasicTestContext>("Encrypt", btc, ctx -> { new TestUnit<BasicTestContext>("Encrypt", btc, ctx -> {
ctx.enc = ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP); ctx.enc = ctx.engine.encrypt_message(ctx.msgAliceToBob, null, Message.EncFormat.PEP);
log(AdapterTestUtils.msgToString(ctx.enc, false)); log(AdapterTestUtils.msgToString(ctx.enc, false));
}); });
new TestUnit<BasicTestContext>("Rating Preview", btc, ctx -> { new TestUnit<BasicTestContext>("Rating Preview", btc, ctx -> {
log("Rating preview: " + ctx.engine.outgoing_message_rating_preview(ctx.msgToBob)); log("Rating preview: " + ctx.engine.outgoing_message_rating_preview(ctx.msgAliceToBob));
}); });
new TestUnit<BasicTestContext>("Rating", btc, ctx -> { new TestUnit<BasicTestContext>("Rating", btc, ctx -> {
log("Rating" + ctx.engine.outgoing_message_rating(ctx.msgToBob)); log("Rating" + ctx.engine.outgoing_message_rating(ctx.msgAliceToBob));
}); });
new TestUnit<BasicTestContext>("Decrypt", btc, ctx -> { new TestUnit<BasicTestContext>("Decrypt", btc, ctx -> {

2
test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java

@ -17,7 +17,7 @@ class TestMain {
ctx.alice = ctx.engine.myself(ctx.alice); ctx.alice = ctx.engine.myself(ctx.alice);
TestLogger.log(AdapterTestUtils.identityToString(ctx.alice, true)); TestLogger.log(AdapterTestUtils.identityToString(ctx.alice, true));
Message msg1 = ctx.engine.encrypt_message(ctx.msgToBob, new Vector<String>(), Message.EncFormat.PEP); Message msg1 = ctx.engine.encrypt_message(ctx.msgAliceToBob, new Vector<String>(), Message.EncFormat.PEP);
ctx.engine.key_reset_all_own_keys(); ctx.engine.key_reset_all_own_keys();

10
test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java

@ -53,7 +53,7 @@ class TestAlice {
new TestUnit<AdapterBaseTestContext>("encrypt_message() -> pEpPassphraseRequired ", jni111Ctx, ctx -> { new TestUnit<AdapterBaseTestContext>("encrypt_message() -> pEpPassphraseRequired ", jni111Ctx, ctx -> {
try { try {
Message enc = ctx.engine.encrypt_message(ctx.msgToSelf, new Vector<>(), Message.EncFormat.PEP); Message enc = ctx.engine.encrypt_message(ctx.msgAliceToAlice, new Vector<>(), Message.EncFormat.PEP);
} catch (pEpException e) { } catch (pEpException e) {
assert e instanceof pEpPassphraseRequired: "wrong exception type"; assert e instanceof pEpPassphraseRequired: "wrong exception type";
return; return;
@ -67,7 +67,7 @@ class TestAlice {
new TestUnit<AdapterBaseTestContext>("encrypt_message() -> pEpWrongPassphrase ", jni111Ctx, ctx -> { new TestUnit<AdapterBaseTestContext>("encrypt_message() -> pEpWrongPassphrase ", jni111Ctx, ctx -> {
try { try {
Message enc = ctx.engine.encrypt_message(ctx.msgToSelf, new Vector<>(), Message.EncFormat.PEP); Message enc = ctx.engine.encrypt_message(ctx.msgAliceToAlice, new Vector<>(), Message.EncFormat.PEP);
} catch (pEpException e) { } catch (pEpException e) {
assert e instanceof pEpWrongPassphrase: "wrong exception type"; assert e instanceof pEpWrongPassphrase: "wrong exception type";
return; return;
@ -80,10 +80,10 @@ class TestAlice {
}); });
new TestUnit<AdapterBaseTestContext>("encrypt_message() -> success", jni111Ctx, ctx -> { new TestUnit<AdapterBaseTestContext>("encrypt_message() -> success", jni111Ctx, ctx -> {
assert ctx.msgToSelf.getEncFormat() == Message.EncFormat.None : "Orig msg not plain"; assert ctx.msgAliceToAlice.getEncFormat() == Message.EncFormat.None : "Orig msg not plain";
Message enc = ctx.engine.encrypt_message(ctx.msgToSelf, new Vector<>(), Message.EncFormat.PEP); Message enc = ctx.engine.encrypt_message(ctx.msgAliceToAlice, new Vector<>(), Message.EncFormat.PEP);
assert enc.getEncFormat() == Message.EncFormat.PGPMIME :"Message not encrypted"; assert enc.getEncFormat() == Message.EncFormat.PGPMIME :"Message not encrypted";
assert !enc.getLongmsg().contains(ctx.msgToSelf.getLongmsg()): "Message not encrypted"; assert !enc.getLongmsg().contains(ctx.msgAliceToAlice.getLongmsg()): "Message not encrypted";
log(AdapterTestUtils.msgToString(enc, false)); log(AdapterTestUtils.msgToString(enc, false));
}); });

9
test/java/foundation/pEp/jniadapter/test/jni114/TestAlice.java

@ -1,7 +1,6 @@
package foundation.pEp.jniadapter.test.jni114; package foundation.pEp.jniadapter.test.jni114;
import static foundation.pEp.pitytest.TestLogger.*; import static foundation.pEp.pitytest.TestLogger.*;
import static foundation.pEp.pitytest.utils.TestUtils.readKey;
import static foundation.pEp.pitytest.utils.TestUtils.sleep; import static foundation.pEp.pitytest.utils.TestUtils.sleep;
import foundation.pEp.jniadapter.*; import foundation.pEp.jniadapter.*;
@ -38,7 +37,7 @@ class TestAlice {
new TestUnit<AdapterBaseTestContext>("no callback / encrypt fails nonblocking", jni114Ctx, ctx -> { new TestUnit<AdapterBaseTestContext>("no callback / encrypt fails nonblocking", jni114Ctx, ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice); ctx.alice = ctx.engine.myself(ctx.alice);
try { try {
Message enc = ctx.engine.encrypt_message(ctx.msgToSelf, new Vector<>(), Message.EncFormat.PEP); Message enc = ctx.engine.encrypt_message(ctx.msgAliceToAlice, new Vector<>(), Message.EncFormat.PEP);
} catch (pEpException e) { } catch (pEpException e) {
assert e instanceof pEpPassphraseRequired : "wrong exception type"; assert e instanceof pEpPassphraseRequired : "wrong exception type";
return; return;
@ -65,10 +64,10 @@ class TestAlice {
log(AdapterTestUtils.identityToString(ctx.alice, true)); log(AdapterTestUtils.identityToString(ctx.alice, true));
// Encrypt // Encrypt
assert ctx.msgToSelf.getEncFormat() == Message.EncFormat.None : "Orig msg not plain"; assert ctx.msgAliceToAlice.getEncFormat() == Message.EncFormat.None : "Orig msg not plain";
Message enc = ctx.engine.encrypt_message(ctx.msgToSelf, new Vector<>(), Message.EncFormat.PEP); Message enc = ctx.engine.encrypt_message(ctx.msgAliceToAlice, new Vector<>(), Message.EncFormat.PEP);
assert enc.getEncFormat() == Message.EncFormat.PGPMIME : "Message not encrypted"; assert enc.getEncFormat() == Message.EncFormat.PGPMIME : "Message not encrypted";
assert !enc.getLongmsg().contains(ctx.msgToSelf.getLongmsg()) : "Message not encrypted"; assert !enc.getLongmsg().contains(ctx.msgAliceToAlice.getLongmsg()) : "Message not encrypted";
log(AdapterTestUtils.msgToString(enc, false)); log(AdapterTestUtils.msgToString(enc, false));
}); });

5
test/java/foundation/pEp/jniadapter/test/jni118/TestAlice.java

@ -7,7 +7,6 @@ import foundation.pEp.pitytest.*;
import foundation.pEp.pitytest.utils.TestUtils; import foundation.pEp.pitytest.utils.TestUtils;
import foundation.pEp.jniadapter.test.utils.*; import foundation.pEp.jniadapter.test.utils.*;
import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
// re_evaluate_message_rating(Message m) // re_evaluate_message_rating(Message m)
@ -50,9 +49,9 @@ class JNI1118Context extends AdapterBaseTestContext {
Vector<Identity> msgToBobRcpts = new Vector<>(); Vector<Identity> msgToBobRcpts = new Vector<>();
msgToBobRcpts.add(bob); msgToBobRcpts.add(bob);
msgToBob.setTo(msgToBobRcpts); msgAliceToBob.setTo(msgToBobRcpts);
msgToBobEncrypted = engine.encrypt_message(msgToBob, null, Message.EncFormat.PEP); msgToBobEncrypted = engine.encrypt_message(msgAliceToBob, null, Message.EncFormat.PEP);
msgToBobDecrypted = msgToBobEncrypted; msgToBobDecrypted = msgToBobEncrypted;
msgToBobDecryptResult = engine.decrypt_message(msgToBobDecrypted, new Vector<String>(), 0); msgToBobDecryptResult = engine.decrypt_message(msgToBobDecrypted, new Vector<String>(), 0);
if (msgToBobEncrypted == null) { if (msgToBobEncrypted == null) {

4
test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java

@ -32,7 +32,7 @@ class TestMain {
ctx.engine.importKey(ctx.keyBobPub); ctx.engine.importKey(ctx.keyBobPub);
// Make msg1 by encrypting msgToBob // Make msg1 by encrypting msgToBob
logH2("Create target Message"); logH2("Create target Message");
Message msg1 = ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP); Message msg1 = ctx.engine.encrypt_message(ctx.msgAliceToBob, null, Message.EncFormat.PEP);
log("\n" + msgToString(msg1, false)); log("\n" + msgToString(msg1, false));
// Lets get the pgpText of the msg1, and the EncFormat // Lets get the pgpText of the msg1, and the EncFormat
@ -55,7 +55,7 @@ class TestMain {
ctx.engine.importKey(ctx.keyBobPub); ctx.engine.importKey(ctx.keyBobPub);
// Make msg1 by encrypting msgToBob // Make msg1 by encrypting msgToBob
logH2("Create target Message"); logH2("Create target Message");
Message msg1 = ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEPEncInlineEA); Message msg1 = ctx.engine.encrypt_message(ctx.msgAliceToBob, null, Message.EncFormat.PEPEncInlineEA);
log("\n" + msgToString(msg1, false)); log("\n" + msgToString(msg1, false));
// Lets get the pgpText of the msg1, and the EncFormat // Lets get the pgpText of the msg1, and the EncFormat

18
test/java/foundation/pEp/jniadapter/test/regression/TestMain.java

@ -41,9 +41,9 @@ class CTXReEvaluateMessageRating extends AdapterBaseTestContext {
Vector<Identity> msgToBobRcpts = new Vector<>(); Vector<Identity> msgToBobRcpts = new Vector<>();
msgToBobRcpts.add(bob); msgToBobRcpts.add(bob);
msgToBob.setTo(msgToBobRcpts); msgAliceToBob.setTo(msgToBobRcpts);
msgToBobEncrypted = engine.encrypt_message(msgToBob, null, Message.EncFormat.PEP); msgToBobEncrypted = engine.encrypt_message(msgAliceToBob, null, Message.EncFormat.PEP);
msgToBobDecrypted = msgToBobEncrypted; msgToBobDecrypted = msgToBobEncrypted;
msgToBobDecryptResult = engine.decrypt_message(msgToBobDecrypted, new Vector<String>(), 0); msgToBobDecryptResult = engine.decrypt_message(msgToBobDecrypted, new Vector<String>(), 0);
if (msgToBobEncrypted == null) { if (msgToBobEncrypted == null) {
@ -78,19 +78,19 @@ class TestMain {
}); });
new TestUnit<AdapterBaseTestContext>("Engine.encrypt_message", new AdapterBaseTestContext(), ctx -> { new TestUnit<AdapterBaseTestContext>("Engine.encrypt_message", new AdapterBaseTestContext(), ctx -> {
ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP); ctx.engine.encrypt_message(ctx.msgAliceToBob, null, Message.EncFormat.PEP);
}); });
new TestUnit<CTXAlice>("Engine.encrypt_message_and_add_priv_key", new CTXAlice(), ctx -> { new TestUnit<CTXAlice>("Engine.encrypt_message_and_add_priv_key", new CTXAlice(), ctx -> {
ctx.engine.encrypt_message_and_add_priv_key(ctx.msgToSelf, ctx.alice.fpr); ctx.engine.encrypt_message_and_add_priv_key(ctx.msgAliceToAlice, ctx.alice.fpr);
}); });
new TestUnit<CTXAlice>("Engine.encrypt_message_for_self", new CTXAlice(), ctx -> { new TestUnit<CTXAlice>("Engine.encrypt_message_for_self", new CTXAlice(), ctx -> {
ctx.engine.encrypt_message_for_self(ctx.alice, ctx.msgToSelf, null); ctx.engine.encrypt_message_for_self(ctx.alice, ctx.msgAliceToAlice, null);
}); });
new TestUnit<AdapterBaseTestContext>("Engine.decrypt_message", new AdapterBaseTestContext(), ctx -> { new TestUnit<AdapterBaseTestContext>("Engine.decrypt_message", new AdapterBaseTestContext(), ctx -> {
ctx.engine.decrypt_message(ctx.msgToSelf, new Vector<String>(), 0); ctx.engine.decrypt_message(ctx.msgAliceToAlice, new Vector<String>(), 0);
}); });
new TestUnit<CTXReEvaluateMessageRating>("Engine.re_evaluate_message_rating", new CTXReEvaluateMessageRating(), ctx -> { new TestUnit<CTXReEvaluateMessageRating>("Engine.re_evaluate_message_rating", new CTXReEvaluateMessageRating(), ctx -> {
@ -98,11 +98,11 @@ class TestMain {
}); });
new TestUnit<AdapterBaseTestContext>("Engine.outgoing_message_rating", new AdapterBaseTestContext(), ctx -> { new TestUnit<AdapterBaseTestContext>("Engine.outgoing_message_rating", new AdapterBaseTestContext(), ctx -> {
ctx.engine.outgoing_message_rating(ctx.msgToBob); ctx.engine.outgoing_message_rating(ctx.msgAliceToBob);
}); });
new TestUnit<AdapterBaseTestContext>("Engine.outgoing_message_rating_preview", new AdapterBaseTestContext(), ctx -> { new TestUnit<AdapterBaseTestContext>("Engine.outgoing_message_rating_preview", new AdapterBaseTestContext(), ctx -> {
ctx.engine.outgoing_message_rating_preview(ctx.msgToBob); ctx.engine.outgoing_message_rating_preview(ctx.msgAliceToBob);
}); });
new TestUnit<CTXAlice>("Engine.get_identity", new CTXAlice(), ctx -> { new TestUnit<CTXAlice>("Engine.get_identity", new CTXAlice(), ctx -> {
@ -147,7 +147,7 @@ class TestMain {
}); });
new TestUnit<AdapterBaseTestContext>("Engine.get_message_trustwords", new AdapterBaseTestContext(), ctx -> { new TestUnit<AdapterBaseTestContext>("Engine.get_message_trustwords", new AdapterBaseTestContext(), ctx -> {
ctx.engine.get_message_trustwords(ctx.msgToBob, null, ctx.bob, "en", false); ctx.engine.get_message_trustwords(ctx.msgAliceToBob, null, ctx.bob, "en", false);
}); });
new TestUnit<AdapterBaseTestContext>("Engine.get_languagelist", new AdapterBaseTestContext(), ctx -> { new TestUnit<AdapterBaseTestContext>("Engine.get_languagelist", new AdapterBaseTestContext(), ctx -> {

25
test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java

@ -6,12 +6,10 @@ import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.Message; import foundation.pEp.jniadapter.Message;
import foundation.pEp.pitytest.AbstractTestContext; import foundation.pEp.pitytest.AbstractTestContext;
import foundation.pEp.pitytest.TestLogger; import foundation.pEp.pitytest.TestLogger;
import foundation.pEp.pitytest.utils.TestUtils;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Vector;
//public class ABAliceTestContext extends AdapterBaseTestContext { //public class ABAliceTestContext extends AdapterBaseTestContext {
@ -31,6 +29,7 @@ import java.util.Vector;
//} //}
public class AdapterBaseTestContext extends AbstractTestContext { public class AdapterBaseTestContext extends AbstractTestContext {
// Basic // Basic
public Engine engine; public Engine engine;
@ -61,14 +60,16 @@ public class AdapterBaseTestContext extends AbstractTestContext {
private String filenameBobSec = "../resources/test_keys/bob-sec.asc"; private String filenameBobSec = "../resources/test_keys/bob-sec.asc";
// Messages // Messages
public Message msgToSelf; public Message msgAliceToAlice;
public Message msgToBob; public Message msgAliceToBob;
// Message types // Message types
public Message.Direction msgDirOutgoing = Message.Direction.Outgoing; public Message.Direction msgDirOutgoing = Message.Direction.Outgoing;
public Blob attachment1 = new Blob(); public Blob attachmentTiny;
public int attachmentsLen = 3; public Blob attachment1KB;
public Vector<Blob> attachments = new Vector<Blob>(); public Blob attachment1MB;
public Blob attachment10MB;
public AttachmentList attachmentList = new AttachmentList(3,10000);
public AdapterBaseTestContext init() throws Throwable { public AdapterBaseTestContext init() throws Throwable {
@ -82,8 +83,10 @@ public class AdapterBaseTestContext extends AbstractTestContext {
TestLogger.logH2("User directory:"); TestLogger.logH2("User directory:");
TestLogger.log(engine.getUserDirectory()); TestLogger.log(engine.getUserDirectory());
attachment1 = AdapterTestUtils.makeNewTestBlob("attachment1", "attachment1.txt", "text/plain"); attachmentTiny = AdapterTestUtils.makeNewTestBlob("attachment1", "attachment1.txt", "text/plain");
attachments = AdapterTestUtils.makeNewTestBlobList(attachmentsLen); attachment1KB = AdapterTestUtils.makeNewTestBlob(1000, "att with size 1KB", null);
attachment1MB = AdapterTestUtils.makeNewTestBlob(1000000, "att with size 1MB", null);
attachment10MB = AdapterTestUtils.makeNewTestBlob(10000000, "att with size 10MB", null);
alice = new Identity(); alice = new Identity();
alice.user_id = "23"; alice.user_id = "23";
@ -95,8 +98,8 @@ public class AdapterBaseTestContext extends AbstractTestContext {
bob.user_id = "42"; bob.user_id = "42";
bob.address = "bob@peptest.org"; bob.address = "bob@peptest.org";
msgToSelf = AdapterTestUtils.makeNewTestMessage(alice, alice, Message.Direction.Outgoing); msgAliceToAlice = AdapterTestUtils.makeNewTestMessage(alice, alice, Message.Direction.Outgoing);
msgToBob = AdapterTestUtils.makeNewTestMessage(alice, bob, Message.Direction.Outgoing); msgAliceToBob = AdapterTestUtils.makeNewTestMessage(alice, bob, Message.Direction.Outgoing);
Path path; Path path;
path = Paths.get(filenameBobPub); path = Paths.get(filenameBobPub);

29
test/java/foundation/pEp/jniadapter/test/utils/AttachmentList.java

@ -0,0 +1,29 @@
package foundation.pEp.jniadapter.test.utils;
import foundation.pEp.jniadapter.Blob;
import java.util.Vector;
public class AttachmentList {
private Vector<Blob> attachments;
private int count = 1;
private int dataSize = 100;
public Vector<Blob> getAttachments() {
return attachments;
}
public int getCount() {
return count;
}
public int getDataSize() {
return dataSize;
}
public AttachmentList(int count, int dataSize) {
this.count = count;
this.dataSize = dataSize;
attachments = AdapterTestUtils.makeNewTestBlobList(dataSize, "attachment.txt", "text/plain", count);
}
}
Loading…
Cancel
Save