Browse Source

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

JNI-147
heck 1 year ago
parent
commit
2c390d1652
9 changed files with 71 additions and 42 deletions
  1. +5
    -6
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  2. +1
    -1
      test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java
  3. +5
    -5
      test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java
  4. +4
    -5
      test/java/foundation/pEp/jniadapter/test/jni114/TestAlice.java
  5. +2
    -3
      test/java/foundation/pEp/jniadapter/test/jni118/TestAlice.java
  6. +2
    -2
      test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java
  7. +9
    -9
      test/java/foundation/pEp/jniadapter/test/regression/TestMain.java
  8. +14
    -11
      test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java
  9. +29
    -0
      test/java/foundation/pEp/jniadapter/test/utils/AttachmentList.java

+ 5
- 6
test/java/foundation/pEp/jniadapter/test/basic/TestMain.java View File

@ -1,6 +1,5 @@
package foundation.pEp.jniadapter.test.basic;
import foundation.pEp.jniadapter.Blob;
import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.Message;
import foundation.pEp.jniadapter.decrypt_message_Return;
@ -49,21 +48,21 @@ class TestMain {
});
new TestUnit<BasicTestContext>("setAttachments", btc, ctx -> {
log("Adding " + ctx.attachmentsLen + " attachments");
ctx.msgToBob.setAttachments(ctx.attachments);
log("Adding " + ctx.attachmentList.getCount() + " attachments");
ctx.msgAliceToBob.setAttachments(ctx.attachmentList.getAttachments());
});
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));
});
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 -> {
log("Rating" + ctx.engine.outgoing_message_rating(ctx.msgToBob));
log("Rating" + ctx.engine.outgoing_message_rating(ctx.msgAliceToBob));
});
new TestUnit<BasicTestContext>("Decrypt", btc, ctx -> {


+ 1
- 1
test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java View File

@ -17,7 +17,7 @@ class TestMain {
ctx.alice = ctx.engine.myself(ctx.alice);
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();


+ 5
- 5
test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java View File

@ -53,7 +53,7 @@ class TestAlice {
new TestUnit<AdapterBaseTestContext>("encrypt_message() -> pEpPassphraseRequired ", jni111Ctx, ctx -> {
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) {
assert e instanceof pEpPassphraseRequired: "wrong exception type";
return;
@ -67,7 +67,7 @@ class TestAlice {
new TestUnit<AdapterBaseTestContext>("encrypt_message() -> pEpWrongPassphrase ", jni111Ctx, ctx -> {
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) {
assert e instanceof pEpWrongPassphrase: "wrong exception type";
return;
@ -80,10 +80,10 @@ class TestAlice {
});
new TestUnit<AdapterBaseTestContext>("encrypt_message() -> success", jni111Ctx, ctx -> {
assert ctx.msgToSelf.getEncFormat() == Message.EncFormat.None : "Orig msg not plain";
Message enc = ctx.engine.encrypt_message(ctx.msgToSelf, new Vector<>(), Message.EncFormat.PEP);
assert ctx.msgAliceToAlice.getEncFormat() == Message.EncFormat.None : "Orig msg not plain";
Message enc = ctx.engine.encrypt_message(ctx.msgAliceToAlice, new Vector<>(), Message.EncFormat.PEP);
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));
});


+ 4
- 5
test/java/foundation/pEp/jniadapter/test/jni114/TestAlice.java View File

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


+ 2
- 3
test/java/foundation/pEp/jniadapter/test/jni118/TestAlice.java View File

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


+ 2
- 2
test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java View File

@ -32,7 +32,7 @@ class TestMain {
ctx.engine.importKey(ctx.keyBobPub);
// Make msg1 by encrypting msgToBob
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));
// Lets get the pgpText of the msg1, and the EncFormat
@ -55,7 +55,7 @@ class TestMain {
ctx.engine.importKey(ctx.keyBobPub);
// Make msg1 by encrypting msgToBob
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));
// Lets get the pgpText of the msg1, and the EncFormat


+ 9
- 9
test/java/foundation/pEp/jniadapter/test/regression/TestMain.java View File

@ -41,9 +41,9 @@ class CTXReEvaluateMessageRating extends AdapterBaseTestContext {
Vector<Identity> msgToBobRcpts = new Vector<>();
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;
msgToBobDecryptResult = engine.decrypt_message(msgToBobDecrypted, new Vector<String>(), 0);
if (msgToBobEncrypted == null) {
@ -78,19 +78,19 @@ class TestMain {
});
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 -> {
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 -> {
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 -> {
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 -> {
@ -98,11 +98,11 @@ class TestMain {
});
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 -> {
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 -> {
@ -147,7 +147,7 @@ class TestMain {
});
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 -> {


+ 14
- 11
test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java View File

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


+ 29
- 0
test/java/foundation/pEp/jniadapter/test/utils/AttachmentList.java View File

@ -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