Browse Source

merge in JNI-118

JNI-119
heck 5 years ago
parent
commit
356689ccb7
  1. 9
      src/codegen/Makefile
  2. 51
      src/codegen/gen_java_Message.ysl2
  3. 128
      src/codegen/pEp.yml2
  4. 6
      src/codegen/textutils.ysl2
  5. 14
      src/java/foundation/pEp/jniadapter/Identity.java
  6. 6
      src/java/foundation/pEp/jniadapter/Pair.java
  7. 6
      test/java/foundation/pEp/jniadapter/test/Makefile
  8. 5
      test/java/foundation/pEp/jniadapter/test/basic/TestMain.java
  9. 4
      test/java/foundation/pEp/jniadapter/test/jni100/TestMain.java
  10. 21
      test/java/foundation/pEp/jniadapter/test/jni111/TestAlice.java
  11. 15
      test/java/foundation/pEp/jniadapter/test/jni115/TestAlice.java
  12. 37
      test/java/foundation/pEp/jniadapter/test/jni118/Makefile
  13. 107
      test/java/foundation/pEp/jniadapter/test/jni118/TestAlice.java
  14. 4
      test/java/foundation/pEp/jniadapter/test/jni98/TestMain.java
  15. 226
      test/java/foundation/pEp/jniadapter/test/regression/TestMain.java
  16. 3
      test/java/foundation/pEp/jniadapter/test/templateAliceBob/MultiPeerCTX.java
  17. 49
      test/java/foundation/pEp/jniadapter/test/utils/AdapterBaseTestContext.java
  18. 3
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/ctx/FsMQManagerBaseTestContext.java
  19. 3
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/ctx/FsMQManagerTestContext.java
  20. 3
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/identities/TestMain.java
  21. 4
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx/TestMain.java
  22. 4
      test/java/foundation/pEp/jniadapter/test/utils/transport/fsmsgqueue/test/regression/TestMain.java
  23. 8
      test/java/foundation/pEp/pitytest/TestContextInterface.java
  24. 2
      test/java/foundation/pEp/pitytest/TestSuite.java
  25. 49
      test/java/foundation/pEp/pitytest/TestUnit.java
  26. 12
      test/java/foundation/pEp/pitytest/examples/ctxinitfail/TestMain.java
  27. 3
      test/java/foundation/pEp/pitytest/examples/ctxmembers/TestMain.java
  28. 3
      test/java/foundation/pEp/pitytest/examples/helloworld/TestMain.java
  29. 3
      test/java/foundation/pEp/pitytest/examples/testsuite/TestMain.java
  30. 6
      test/java/foundation/pEp/pitytest/utils/Pair.java
  31. 102
      test/java/foundation/pEp/pitytest/utils/TestUtils.java
  32. 27
      utils/gen_status_codes.sh

9
src/codegen/Makefile

@ -38,13 +38,8 @@ codegen: create-dirs gen-status-codes $(YML2_MARKERS)
$(YML2_MARKERS): $(MARKER_DIR)/%.marker : %.ysl2 pEp.yml2 $(YML2_INCLUDES)
$(YML2_PROC) -y $< pEp.yml2
gen-status-codes: status_list.yml2 passphrase_status_list.yml2
status_list.yml2: pEp.yml2
bash ../../utils/extract_pEp_status_codes_from_engine.sh "$(PEP_HEADER)" $@
passphrase_status_list.yml2: status_list.yml2
grep passphrase $< > $@
gen-status-codes: pEp.yml2
bash ../../utils/gen_status_codes.sh "$(PEP_HEADER)"
# ------------- Housekeeping ---------------
create-dirs:

51
src/codegen/gen_java_Message.ysl2

@ -113,7 +113,7 @@ tstylesheet {
||
// CodeGen template enum, mode=inner
public enum «$jname» {
`` apply "*", mode=value
`` apply "enumitem"
;
public final int value;
@ -136,9 +136,20 @@ tstylesheet {
}
return null;
}
}
||
choose {
when "@has_int_str_val = 'true'" {
||
public String getInternalStringValue() {
return "Unimplemented";
}
||
}
}
||
}
||
}
function "exception" {
@ -319,9 +330,39 @@ tstylesheet {
||
}
template "*", mode=value {
const "name" call "toJava" with "type", "name(.)";
| «$name» («.»)`if "position()!=last()" > , `
template "enumitem" {
const "name_hyphenized" call "hyphenize" with "text", "@name";
const "javaname" call "toJava" with "type", "$name_hyphenized";
const "enum_index", ".";
||
«$javaname» («$enum_index») {
public String toString() {
||
choose {
when "@toString" {
||
return "«@toString»";
||
} otherwise {
||
return "«$javaname»";
||
}
}
||
}
||
choose {
when "@int_str_val" {
||
public String getInternalStringValue() {
return "«@int_str_val»";
}
||
}
}
| }`if "position()!=last()" > , `
}
}

128
src/codegen/pEp.yml2

@ -1,5 +1,6 @@
decl namespace @name;
decl enum @name;
decl enumitem @name;
decl interface @name;
decl exception @name;
decl method @name;
@ -16,77 +17,74 @@ namespace pEp {
};
enum Color {
PEP_color_no_color > 0
PEP_color_yellow > 1
PEP_color_green > 2
PEP_color_red > -1
enumitem PEP_color_no_color toString="None" > 0
enumitem PEP_color_yellow toString="Yellow" > 1
enumitem PEP_color_green toString="Green" > 2
enumitem PEP_color_red toString="Red" > -1
};
enum Rating {
pEp_rating_undefined > 0
pEp_rating_cannot_decrypt > 1
pEp_rating_have_no_key > 2
pEp_rating_unencrypted > 3
pEp_rating_unencrypted_for_some > 4
pEp_rating_unreliable > 5
pEp_rating_reliable > 6
pEp_rating_trusted > 7
pEp_rating_trusted_and_anonymized > 8
pEp_rating_fully_anonymous > 9
pEp_rating_mistrust > -1
pEp_rating_b0rken > -2
pEp_rating_under_attack > -3
enum has_int_str_val=true Rating {
enumitem pEp_rating_undefined int_str_val=undefined toString="undefined" > 0
enumitem pEp_rating_cannot_decrypt int_str_val=cannot_decrypt toString="cannot decrypt" > 1
enumitem pEp_rating_have_no_key int_str_val=have_no_key toString="have no key" > 2
enumitem pEp_rating_unencrypted int_str_val=unencrypted toString="unencrypted" > 3
enumitem pEp_rating_unencrypted_for_some int_str_val=unencrypted_for_some toString="unencrypted for some" > 4
enumitem pEp_rating_unreliable int_str_val=unreliable toString="unreliable" > 5
enumitem pEp_rating_reliable int_str_val=reliable toString="reliable" > 6
enumitem pEp_rating_trusted int_str_val=trusted toString="trusted" > 7
enumitem pEp_rating_trusted_and_anonymized int_str_val=trusted_and_anonymized toString="trusted and anonymized" > 8
enumitem pEp_rating_fully_anonymous int_str_val=fully_anonymous toString="fully anonymous" > 9
enumitem pEp_rating_mistrust int_str_val=mistrust toString="mistrust" > -1
enumitem pEp_rating_b0rken int_str_val=b0rken toString="b0rken" > -2
enumitem pEp_rating_under_attack int_str_val=under_attack toString="under attack" > -3
};
enum DecryptFlags {
pEp_decrypt_flag_own_private_key > 1
pEp_decrypt_flag_consumed > 2
pEp_decrypt_flag_ignored > 4
pEp_decrypt_flag_src_modified > 8
pEp_decrypt_flag_untrusted_server > 0x100
pEp_decrypt_flag_dont_trigger_sync > 0x200
enumitem pEp_decrypt_flag_own_private_key > 1
enumitem pEp_decrypt_flag_consumed > 2
enumitem pEp_decrypt_flag_ignored > 4
enumitem pEp_decrypt_flag_src_modified > 8
enumitem pEp_decrypt_flag_untrusted_server > 0x100
enumitem pEp_decrypt_flag_dont_trigger_sync > 0x200
};
enum IdentityFlags {
pEp_idf_not_for_sync > 1
pEp_idf_list > 2
pEp_idf_devicegroup > 256
enumitem pEp_idf_not_for_sync > 1
enumitem pEp_idf_list > 2
enumitem pEp_idf_devicegroup > 256
};
enum SyncHandshakeResult {
sync_handshake_cancel > -1
sync_handshake_accepted > 0
sync_handshake_rejected > 1
enumitem sync_handshake_cancel > -1
enumitem sync_handshake_accepted > 0
enumitem sync_handshake_rejected > 1
};
enum SyncHandshakeSignal {
sync_notify_undefined > 0
sync_notify_init_add_our_device > 1
sync_notify_init_add_other_device > 2
sync_notify_init_form_group > 3
// sync_notify_init_move_our_device > 4
sync_notify_timeout > 5
sync_notify_accepted_device_added > 6
sync_notify_accepted_group_created > 7
sync_notify_accepted_device_accepted > 8
// sync_notify_overtaken > 9
// sync_notify_forming_group > 10
sync_passphrase_required > 128
sync_notify_sole > 254
sync_notify_in_group > 255
enumitem sync_notify_undefined > 0
enumitem sync_notify_init_add_our_device > 1
enumitem sync_notify_init_add_other_device > 2
enumitem sync_notify_init_form_group > 3
enumitem sync_notify_timeout > 5
enumitem sync_notify_accepted_device_added > 6
enumitem sync_notify_accepted_group_created > 7
enumitem sync_notify_accepted_device_accepted > 8
enumitem sync_passphrase_required > 128
enumitem sync_notify_sole > 254
enumitem sync_notify_in_group > 255
};
enum CipherSuite {
pEp_cipher_suite_default > 0
pEp_cipher_suite_cv25519 > 1
pEp_cipher_suite_p256 > 2
pEp_cipher_suite_p384 > 3
pEp_cipher_suite_p521 > 4
pEp_cipher_suite_rsa2k > 5
pEp_cipher_suite_rsa3k > 6
pEp_cipher_suite_rsa4k > 7
pEp_cipher_suite_rsa8k > 8
enumitem pEp_cipher_suite_default > 0
enumitem pEp_cipher_suite_cv25519 > 1
enumitem pEp_cipher_suite_p256 > 2
enumitem pEp_cipher_suite_p384 > 3
enumitem pEp_cipher_suite_p521 > 4
enumitem pEp_cipher_suite_rsa2k > 5
enumitem pEp_cipher_suite_rsa3k > 6
enumitem pEp_cipher_suite_rsa4k > 7
enumitem pEp_cipher_suite_rsa8k > 8
};
interface Engine {
@ -275,23 +273,23 @@ namespace pEp {
struct message {
enum TextFormat {
plain > 0
html > 1
other > 255
enumitem plain > 0
enumitem html > 1
enumitem other > 255
}
enum direction {
incoming > 0
outgoing > 1
enumitem incoming > 0
enumitem outgoing > 1
}
enum EncFormat {
none > 0
inline > 1
SMIME > 2
PGPMIME > 3
PEP > 4
PEP_enc_inline_EA > 6
enumitem none > 0
enumitem inline > 1
enumitem SMIME > 2
enumitem PGPMIME > 3
enumitem PEP > 4
enumitem PEP_enc_inline_EA > 6
}
direction dir;

6
src/codegen/textutils.ysl2

@ -10,6 +10,12 @@ function "lcase" {
value "translate($text, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ-', 'abcdefghijklmnopqrstuvwxyz_')";
}
function "hyphenize" {
param "text";
value "translate($text, '_', '-')";
}
function "CamelCase" {
param "text";
const "tokens", "str:tokenize($text, '-')";

14
src/java/foundation/pEp/jniadapter/Identity.java

@ -2,6 +2,7 @@ package foundation.pEp.jniadapter;
import foundation.pEp.jniadapter.interfaces.*;
import java.io.Serializable;
import java.util.List;
public class Identity implements IdentityInterface, Serializable {
public String address;
@ -40,11 +41,22 @@ public class Identity implements IdentityInterface, Serializable {
private native int _getRating(int commType);
public static String toXKeyList(List<Identity> ids) {
String ret = "";
if(ids.size() > 0) {
for (Identity id : ids) {
ret += id.fpr;
ret += ",";
}
ret = ret.substring(0, ret.length() - 1);
}
return ret;
}
@Override
public String toString() {
return address + "::" + username + "\n" +
user_id + "::" + fpr;
}
}

6
src/java/foundation/pEp/jniadapter/Pair.java

@ -10,5 +10,11 @@ public class Pair<F, S> {
first = f;
second = s;
}
public String toString() {
String ret="";
ret += "'" + first.toString() + "' : '" + second.toString() + "'";
return ret;
}
}

6
test/java/foundation/pEp/jniadapter/test/Makefile

@ -7,6 +7,7 @@ run: compile
$(MAKE) -C templateAliceBob run
$(MAKE) -C basic run
$(MAKE) -C regression run
$(MAKE) -C speedtest run
$(MAKE) -C jni88 run
$(MAKE) -C jni91 run
$(MAKE) -C jni92 run
@ -17,12 +18,14 @@ run: compile
$(MAKE) -C jni111 run
$(MAKE) -C jni114 run
$(MAKE) -C jni115 run
$(MAKE) -C jni118 run
compile:
$(MAKE) -C templateAlice compile
$(MAKE) -C templateAliceBob compile
$(MAKE) -C basic compile
$(MAKE) -C regression compile
$(MAKE) -C speedtest compile
$(MAKE) -C jni88 compile
$(MAKE) -C jni91 compile
$(MAKE) -C jni92 compile
@ -33,12 +36,14 @@ compile:
$(MAKE) -C jni111 compile
$(MAKE) -C jni114 compile
$(MAKE) -C jni115 compile
$(MAKE) -C jni118 compile
clean:
$(MAKE) -C templateAlice clean
$(MAKE) -C templateAliceBob clean
$(MAKE) -C basic clean
$(MAKE) -C regression clean
$(MAKE) -C speedtest clean
$(MAKE) -C jni88 clean
$(MAKE) -C jni91 clean
$(MAKE) -C jni92 clean
@ -49,6 +54,7 @@ clean:
$(MAKE) -C jni111 clean
$(MAKE) -C jni114 clean
$(MAKE) -C jni115 clean
$(MAKE) -C jni118 clean
clean-pep-home:
$(MAKE) -C basic clean-pep-home

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

@ -17,6 +17,11 @@ class BasicTestContext extends AdapterBaseTestContext {
public BasicTestContext() {
setTestContextName("BasicTestContext");
}
public BasicTestContext init() throws Throwable{
super.init();
return this;
}
}
class TestMain {

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

@ -3,6 +3,8 @@ import foundation.pEp.pitytest.*;
import foundation.pEp.jniadapter.*;
import foundation.pEp.jniadapter.test.utils.*;
import java.util.Vector;
class TestMain {
public static void main(String[] args) throws Exception {
@ -15,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, ctx.vStr, Message.EncFormat.PEP);
Message msg1 = ctx.engine.encrypt_message(ctx.msgToBob, new Vector<String>(), Message.EncFormat.PEP);
ctx.engine.key_reset_all_own_keys();

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

@ -1,25 +1,30 @@
package foundation.pEp.jniadapter.test.jni111;
import static foundation.pEp.pitytest.TestLogger.*;
import static foundation.pEp.pitytest.utils.TestUtils.readKey;
import foundation.pEp.jniadapter.*;
import foundation.pEp.jniadapter.exceptions.*;
import foundation.pEp.pitytest.*;
import foundation.pEp.jniadapter.CommType;
import foundation.pEp.jniadapter.Message;
import foundation.pEp.jniadapter.exceptions.pEpException;
import foundation.pEp.jniadapter.exceptions.pEpPassphraseRequired;
import foundation.pEp.jniadapter.exceptions.pEpWrongPassphrase;
import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext;
import foundation.pEp.jniadapter.test.utils.AdapterTestUtils;
import foundation.pEp.pitytest.TestSuite;
import foundation.pEp.pitytest.TestUnit;
import foundation.pEp.pitytest.utils.TestUtils;
import foundation.pEp.jniadapter.test.utils.*;
import java.util.Vector;
import static foundation.pEp.pitytest.TestLogger.log;
// https://pep.foundation/jira/browse/JNI-111
class JNI111TestContext extends AdapterBaseTestContext {
@Override
public void init() throws Throwable {
public JNI111TestContext init() throws Throwable {
super.init();
alice = null;
bob = null;
return this;
}
}

15
test/java/foundation/pEp/jniadapter/test/jni115/TestAlice.java

@ -1,16 +1,18 @@
package foundation.pEp.jniadapter.test.jni115;
import static foundation.pEp.pitytest.TestLogger.*;
import foundation.pEp.jniadapter.Message;
import foundation.pEp.pitytest.*;
import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext;
import foundation.pEp.jniadapter.test.utils.AdapterTestUtils;
import foundation.pEp.pitytest.TestSuite;
import foundation.pEp.pitytest.TestUnit;
import foundation.pEp.pitytest.utils.TestUtils;
import foundation.pEp.jniadapter.test.utils.*;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import static foundation.pEp.pitytest.TestLogger.log;
import static foundation.pEp.pitytest.TestLogger.logRaw;
class Jni115TestContext extends AdapterBaseTestContext {
public int messagesToBobCount = 10;
public List<Message> messagesToBobSmall;
@ -19,7 +21,7 @@ class Jni115TestContext extends AdapterBaseTestContext {
public List<Message> messagesToBob;
@Override
public void init() throws Throwable {
public Jni115TestContext init() throws Throwable {
super.init();
messagesToBobSmall = new ArrayList<>();
messagesToBobBig = new ArrayList<>();
@ -52,6 +54,7 @@ class Jni115TestContext extends AdapterBaseTestContext {
messagesToBobHuge.add(tmp);
}
logRaw("\n");
return this;
}
}

37
test/java/foundation/pEp/jniadapter/test/jni118/Makefile

@ -0,0 +1,37 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=jni118
JAVA_CLASSES = \
TestAlice.class \
../utils/AdapterBaseTestContext.class \
../utils/AdapterTestUtils.class \
../utils/TestCallbacks.class
.PHONY: pitytest compile alice test clean
all: alice compile
pitytest:
$(MAKE) -C $(PITYTEST_DIR)
alice: compile clean-pep-home-alice
cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice
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-alice:
rm -rf $(PEP_HOME_DIR_ALICE)/.pEp

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

@ -0,0 +1,107 @@
package foundation.pEp.jniadapter.test.jni118;
import static foundation.pEp.pitytest.TestLogger.*;
import foundation.pEp.jniadapter.*;
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)
// needs a msg that holds the OptFields:
// * X-EncStatus - containing the pEpEngine internal string value of the rating
// * X-KeyList - containing the FPR's of all the receivers of the msg
//
// Handling of PEP_Rating
// When app needs to add optional fields like X-EncStatus, the value has to be the string rep for a rating.
// These internal string representations can be obtained with the method:
// * Rating.getInternalStringValue() - returning the pEpEngine internal string value
// For human readable description of all the enums, use:
// * Rating.toString()
//
// A convenience method Message.addRatingToOptFields(Rating r) would be desirable
//
// X-KeyList
// New method to generate X-Keylist formatted FPR list:
// * String Identity.toXKeyList(List<Identity> ids)
//
// A convenience method for adding X-KeyList for a message would be desirable
// * method Message.addIdentitiesToOptFields()
// Test objectives
// re_evaluate_message_rating() equal to decrypt_message_result.rating when Message has correct OptFields
// re_evaluate_message_rating() equal to decrypt_message_result.rating when Message has random rating string on XEncStatus
class JNI1118Context extends AdapterBaseTestContext {
public Message msgToBobEncrypted;
public Message msgToBobDecrypted;
public decrypt_message_Return msgToBobDecryptResult;
@Override
public JNI1118Context init() throws Throwable {
super.init();
alice = engine.myself(alice);
engine.importKey(keyBobPub);
Vector<Identity> msgToBobRcpts = new Vector<>();
msgToBobRcpts.add(bob);
msgToBob.setTo(msgToBobRcpts);
msgToBobEncrypted = engine.encrypt_message(msgToBob, null, Message.EncFormat.PEP);
msgToBobDecrypted = msgToBobEncrypted;
msgToBobDecryptResult = engine.decrypt_message(msgToBobDecrypted, new Vector<String>(), 0);
if (msgToBobEncrypted == null) {
throw new RuntimeException("Context failure, error decrypting message");
}
return this;
}
public void addRatingToOptFields(Message msg, String ratingStr) {
ArrayList<Pair<String, String>> opts = msg.getOptFields();
opts.add(new Pair<String, String>("X-EncStatus",ratingStr));
msg.setOptFields(opts);
}
public void addRcptsToOptFields(Message msg, String fprs) {
ArrayList<Pair<String, String>> opts = msg.getOptFields();
opts.add(new Pair<String, String>("X-KeyList", fprs));
msg.setOptFields(opts);
}
}
class TestAlice {
public static void main(String[] args) throws Throwable {
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
new TestUnit<JNI1118Context>("re_evaluate_message_rating() equal to decrypt_message_result.rating when Message has correct OptFields", new JNI1118Context(), ctx -> {
ctx.addRatingToOptFields(ctx.msgToBobDecrypted,ctx.msgToBobDecryptResult.rating.getInternalStringValue());
ctx.addRcptsToOptFields(ctx.msgToBobDecrypted,Identity.toXKeyList(ctx.msgToBobDecrypted.getTo()));
log("running re_evaluate_message_rating() on:\n" + AdapterTestUtils.msgToString(ctx.msgToBobDecrypted, false));
Rating rat = ctx.engine.re_evaluate_message_rating(ctx.msgToBobDecrypted);
log("re_evaluate_message_rating() result: " + rat.toString());
assert rat == ctx.msgToBobDecryptResult.rating : "Rating is " + rat.toString() + ",but should be " + ctx.msgToBobDecryptResult.rating.toString();
});
new TestUnit<JNI1118Context>("re_evaluate_message_rating() equal to decrypt_message_result.rating when Message has random rating string on XEncStatus", new JNI1118Context(), ctx -> {
ctx.addRatingToOptFields(ctx.msgToBobDecrypted, TestUtils.randomASCIIString(TestUtils.CharClass.Unbounded, TestUtils.randomInt(0,42)));
ctx.addRcptsToOptFields(ctx.msgToBobDecrypted,Identity.toXKeyList(ctx.msgToBobDecrypted.getTo()));
log("running re_evaluate_message_rating() on:\n" + AdapterTestUtils.msgToString(ctx.msgToBobDecrypted, false));
Rating rat = ctx.engine.re_evaluate_message_rating(ctx.msgToBobDecrypted);
log("re_evaluate_message_rating() result: " + rat.toString());
assert rat == ctx.msgToBobDecryptResult.rating : "Rating is " + rat.toString() + ",but should be " + ctx.msgToBobDecryptResult.rating.toString();
});
TestSuite.getDefault().run();
}
}

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

@ -5,6 +5,8 @@ import foundation.pEp.jniadapter.Message;
import foundation.pEp.pitytest.TestUnit;
import foundation.pEp.jniadapter.test.utils.AdapterBaseTestContext;
import java.util.Vector;
import static foundation.pEp.pitytest.TestLogger.log;
import static foundation.pEp.pitytest.TestLogger.logH2;
import static foundation.pEp.jniadapter.test.utils.AdapterTestUtils.msgToString;
@ -45,7 +47,7 @@ class TestMain {
logH2("Verify msg2");
decrypt_message_Return result = null;
result = ctx.engine.decrypt_message(msg2, ctx.vStr, 0);
result = ctx.engine.decrypt_message(msg2, new Vector<String>(), 0);
log("\n" + msgToString(result.dst, false));
}).run();

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

@ -3,268 +3,300 @@ import foundation.pEp.pitytest.*;
import foundation.pEp.jniadapter.test.utils.*;
import foundation.pEp.jniadapter.*;
class RegTestContext extends AdapterBaseTestContext {
// enhance the context
import java.util.ArrayList;
import java.util.Vector;
import static foundation.pEp.pitytest.TestLogger.log;
class CTXAlice extends AdapterBaseTestContext {
@Override
public CTXAlice init() throws Throwable {
super.init();
alice = engine.myself(alice);
return this;
}
}
class CTXAlice2 extends CTXAlice {
@Override
public void init() throws Throwable {
public CTXAlice2 init() throws Throwable {
super.init();
// init the enhancements
engine.importKey(keyBobSec);
bob = engine.updateIdentity(bob);
return this;
}
}
// Almost exact copy of JNI1118Context, we need a shared context hierarchy
class CTXReEvaluateMessageRating extends AdapterBaseTestContext {
public Message msgToBobEncrypted;
public Message msgToBobDecrypted;
public decrypt_message_Return msgToBobDecryptResult;
@Override
public CTXReEvaluateMessageRating init() throws Throwable {
super.init();
alice = engine.myself(alice);
engine.importKey(keyBobPub);
Vector<Identity> msgToBobRcpts = new Vector<>();
msgToBobRcpts.add(bob);
msgToBob.setTo(msgToBobRcpts);
msgToBobEncrypted = engine.encrypt_message(msgToBob, null, Message.EncFormat.PEP);
msgToBobDecrypted = msgToBobEncrypted;
msgToBobDecryptResult = engine.decrypt_message(msgToBobDecrypted, new Vector<String>(), 0);
if (msgToBobEncrypted == null) {
throw new RuntimeException("Context failure, error decrypting message");
}
addRatingToOptFields(msgToBobDecrypted, msgToBobDecryptResult.rating.getInternalStringValue());
addRcptsToOptFields(msgToBobDecrypted, Identity.toXKeyList(msgToBobDecrypted.getTo()));
return this;
}
public void addRatingToOptFields(Message msg, String ratingStr) {
ArrayList<Pair<String, String>> opts = msg.getOptFields();
opts.add(new Pair<String, String>("X-EncStatus",ratingStr));
msg.setOptFields(opts);
}
public void addRcptsToOptFields(Message msg, String fprs) {
ArrayList<Pair<String, String>> opts = msg.getOptFields();
opts.add(new Pair<String, String>("X-KeyList", fprs));
msg.setOptFields(opts);
}
}
class TestMain {
public static void main(String[] args) {
TestSuite.getDefault().setVerbose(false);
new TestUnit<RegTestContext>("Engine.myself", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.myself", new AdapterBaseTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.encrypt_message", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.encrypt_message", new AdapterBaseTestContext(), ctx -> {
ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP);
});
new TestUnit<RegTestContext>("Engine.encrypt_message_and_add_priv_key", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
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);
});
new TestUnit<RegTestContext>("Engine.encrypt_message_for_self", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.encrypt_message_for_self", new CTXAlice(), ctx -> {
ctx.engine.encrypt_message_for_self(ctx.alice, ctx.msgToSelf, null);
});
new TestUnit<RegTestContext>("Engine.decrypt_message", new RegTestContext(), ctx -> {
ctx.engine.decrypt_message(ctx.msgToSelf, ctx.vStr, 0);
new TestUnit<AdapterBaseTestContext>("Engine.decrypt_message", new AdapterBaseTestContext(), ctx -> {
ctx.engine.decrypt_message(ctx.msgToSelf, new Vector<String>(), 0);
});
//TODO: Coredump
// new TestUnit<RegTestContext>("Engine.re_evaluate_message_rating", new RegTestContext(), ctx -> {
// ctx.alice = ctx.engine.myself(ctx.alice);
// ctx.bob = ctx.engine.myself(ctx.bob);
// Message msg = ctx.engine.encrypt_message(ctx.msgToBob,null, Message.EncFormat.PEP);
// ctx.engine.re_evaluate_message_rating(msg);
// });
new TestUnit<CTXReEvaluateMessageRating>("Engine.re_evaluate_message_rating", new CTXReEvaluateMessageRating(), ctx -> {
ctx.engine.re_evaluate_message_rating(ctx.msgToBobDecrypted);
});
new TestUnit<RegTestContext>("Engine.outgoing_message_rating", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.outgoing_message_rating", new AdapterBaseTestContext(), ctx -> {
ctx.engine.outgoing_message_rating(ctx.msgToBob);
});
new TestUnit<RegTestContext>("Engine.outgoing_message_rating_preview", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.outgoing_message_rating_preview", new AdapterBaseTestContext(), ctx -> {
ctx.engine.outgoing_message_rating_preview(ctx.msgToBob);
});
new TestUnit<RegTestContext>("Engine.get_identity", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.get_identity", new CTXAlice(), ctx -> {
ctx.engine.get_identity(ctx.alice.address, ctx.alice.user_id);
});
new TestUnit<RegTestContext>("Engine.identity_rating", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.identity_rating", new CTXAlice(), ctx -> {
ctx.engine.identity_rating(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.blacklist_retrieve", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.blacklist_retrieve", new AdapterBaseTestContext(), ctx -> {
ctx.engine.blacklist_retrieve();
});
//FAIL
new TestUnit<RegTestContext>("Engine.own_message_private_key_details", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.bob = ctx.engine.myself(ctx.bob);
ctx.engine.encrypt_message(ctx.msgToBob, null, Message.EncFormat.PEP);
ctx.engine.own_message_private_key_details(ctx.msgToBob);
});
// TODO: FAILS
// new TestUnit<CTXAlice2>("Engine.own_message_private_key_details", new CTXAlice2(), ctx -> {
// ctx.engine.own_message_private_key_details(ctx.msgToSelf);
// });
new TestUnit<RegTestContext>("Engine.OpenPGP_list_keyinfo", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.OpenPGP_list_keyinfo", new AdapterBaseTestContext(), ctx -> {
ctx.engine.OpenPGP_list_keyinfo("");
});
new TestUnit<RegTestContext>("Engine.set_identity_flags", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.set_identity_flags", new AdapterBaseTestContext(), ctx -> {
ctx.engine.set_identity_flags(ctx.alice, 0);
});
new TestUnit<RegTestContext>("Engine.unset_identity_flags", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.unset_identity_flags", new AdapterBaseTestContext(), ctx -> {
ctx.engine.unset_identity_flags(ctx.alice, 0);
});
new TestUnit<RegTestContext>("Engine.own_identities_retrieve", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.own_identities_retrieve", new AdapterBaseTestContext(), ctx -> {
ctx.engine.own_identities_retrieve();
});
new TestUnit<RegTestContext>("Engine.get_trustwords", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.bob = ctx.engine.myself(ctx.bob);
new TestUnit<CTXAlice2>("Engine.get_trustwords", new CTXAlice2(), ctx -> {
ctx.engine.get_trustwords(ctx.alice, ctx.bob, "en", false);
});
new TestUnit<RegTestContext>("Engine.get_trustwords_for_fprs", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
ctx.bob = ctx.engine.myself(ctx.bob);
new TestUnit<CTXAlice2>("Engine.get_trustwords_for_fprs", new CTXAlice2(), ctx -> {
ctx.engine.get_trustwords_for_fprs(ctx.alice.fpr, ctx.bob.fpr, "en", false);
});
new TestUnit<RegTestContext>("Engine.get_message_trustwords", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.get_message_trustwords", new AdapterBaseTestContext(), ctx -> {
ctx.engine.get_message_trustwords(ctx.msgToBob, null, ctx.bob, "en", false);
});
new TestUnit<RegTestContext>("Engine.get_languagelist", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.get_languagelist", new AdapterBaseTestContext(), ctx -> {
ctx.engine.get_languagelist();
});
new TestUnit<RegTestContext>("Engine.key_reset_trust", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.key_reset_trust", new CTXAlice(), ctx -> {
ctx.engine.key_reset_trust(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.key_reset_identity", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.key_reset_identity", new CTXAlice(), ctx -> {
ctx.engine.key_reset_identity(ctx.alice, "");
});
new TestUnit<RegTestContext>("Engine.key_reset_user", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.key_reset_user", new CTXAlice(), ctx -> {
ctx.engine.key_reset_user("fsdjugsh", ctx.alice.fpr);
});
new TestUnit<RegTestContext>("Engine.key_reset_all_own_keys", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.key_reset_all_own_keys", new AdapterBaseTestContext(), ctx -> {
ctx.engine.key_reset_all_own_keys();
});
new TestUnit<RegTestContext>("Engine.deliverHandshakeResult", new RegTestContext(), ctx -> {
ctx.engine.deliverHandshakeResult(SyncHandshakeResult.SyncHandshakeCancel, ctx.vID);
});
// TODO: FAILS
// new TestUnit<AdapterBaseTestContext>("Engine.deliverHandshakeResult", new AdapterBaseTestContext(), ctx -> {
// ctx.engine.deliverHandshakeResult(SyncHandshakeResult.SyncHandshakeCancel, ctx.vID);
// });
//[17:51] < heck> | this one fails since: 4665:f067c9e95455
//[17:52] < heck> | i confirmed it still works in the parent revision 4662:71147c43e31b
//[17:52] < heck> | the error i get is:
//[17:53] < heck> | *** send message KeySync Beacon service KeySync_fsm.c:234
//[17:53] < heck> | Assertion failed: (msg->from && msg->from->fpr), function attach_own_key, file message_api.c, line 1581.
// new TestUnit<RegTestContext>("Engine.leave_device_group", new RegTestContext(), ctx -> {
// TODO: FAILS
// [17:51] < heck> | this one fails since: 4665:f067c9e95455
// [17:52] < heck> | i confirmed it still works in the parent revision 4662:71147c43e31b
// [17:52] < heck> | the error i get is:
// [17:53] < heck> | *** send message KeySync Beacon service KeySync_fsm.c:234
// [17:53] < heck> | Assertion failed: (msg->from && msg->from->fpr), function attach_own_key, file message_api.c, line 1581.
// new TestUnit<AdapterBaseTestContext>("Engine.leave_device_group", new AdapterBaseTestContext(), ctx -> {
// ctx.engine.startSync();
// ctx.engine.leave_device_group();
// });
new TestUnit<RegTestContext>("Engine.enable_identity_for_sync", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.enable_identity_for_sync", new CTXAlice(), ctx -> {
ctx.engine.enable_identity_for_sync(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.disable_identity_for_sync", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.disable_identity_for_sync", new CTXAlice(), ctx -> {
ctx.engine.disable_identity_for_sync(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.config_cipher_suite", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.config_cipher_suite", new AdapterBaseTestContext(), ctx -> {
ctx.engine.config_cipher_suite(CipherSuite.pEpCipherSuiteDefault);
});
new TestUnit<RegTestContext>("Engine.trustwords", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.trustwords", new AdapterBaseTestContext(), ctx -> {
ctx.engine.trustwords(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.updateIdentity", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.updateIdentity", new AdapterBaseTestContext(), ctx -> {
ctx.engine.updateIdentity(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.setOwnKey", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.setOwnKey", new CTXAlice(), ctx -> {
ctx.engine.setOwnKey(ctx.alice, ctx.alice.fpr);
});
new TestUnit<RegTestContext>("Engine.keyMistrusted", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.keyMistrusted", new CTXAlice(), ctx -> {
ctx.engine.keyMistrusted(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.keyResetTrust", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.keyResetTrust", new AdapterBaseTestContext(), ctx -> {
ctx.engine.keyResetTrust(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.trustPersonalKey", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.trustPersonalKey", new AdapterBaseTestContext(), ctx -> {
ctx.engine.trustPersonalKey(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.trustOwnKey", new RegTestContext(), ctx -> {
ctx.alice = ctx.engine.myself(ctx.alice);
new TestUnit<CTXAlice>("Engine.trustOwnKey", new CTXAlice(), ctx -> {
ctx.engine.trustOwnKey(ctx.alice);
});
new TestUnit<RegTestContext>("Engine.importKey", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.importKey", new AdapterBaseTestContext(), ctx -> {
ctx.engine.importKey(ctx.keyBobPub);
});
new TestUnit<RegTestContext>("Engine.blacklist_add", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.blacklist_add", new AdapterBaseTestContext(), ctx -> {
ctx.engine.blacklist_add("43");
});
new TestUnit<RegTestContext>("Engine.blacklist_delete", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.blacklist_delete", new AdapterBaseTestContext(), ctx -> {
ctx.engine.blacklist_delete("43");
});
new TestUnit<RegTestContext>("Engine.blacklist_is_listed", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.blacklist_is_listed", new AdapterBaseTestContext(), ctx -> {
ctx.engine.blacklist_is_listed("43");
});
new TestUnit<RegTestContext>("Engine.config_passive_mode", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.config_passive_mode", new AdapterBaseTestContext(), ctx -> {
ctx.engine.config_passive_mode(false);
});
new TestUnit<RegTestContext>("Engine.config_unencrypted_subject", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.config_unencrypted_subject", new AdapterBaseTestContext(), ctx -> {
ctx.engine.config_unencrypted_subject(false);
});
new TestUnit<RegTestContext>("Engine.getCrashdumpLog", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.getCrashdumpLog", new AdapterBaseTestContext(), ctx -> {
ctx.engine.getCrashdumpLog(0);
});
new TestUnit<RegTestContext>("Engine.getUserDirectory", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.getUserDirectory", new AdapterBaseTestContext(), ctx -> {
ctx.engine.getUserDirectory();
});
new TestUnit<RegTestContext>("Engine.getMachineDirectory", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.getMachineDirectory", new AdapterBaseTestContext(), ctx -> {
ctx.engine.getMachineDirectory();
});
// AbstractEngine.java
new TestUnit<RegTestContext>("Engine.close", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.close", new AdapterBaseTestContext(), ctx -> {
ctx.engine.close();
});
new TestUnit<RegTestContext>("Engine.getVersion", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.getVersion", new AdapterBaseTestContext(), ctx -> {
ctx.engine.getVersion();
});
new TestUnit<RegTestContext>("Engine.getProtocolVersion", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.getProtocolVersion", new AdapterBaseTestContext(), ctx -> {
ctx.engine.getProtocolVersion();
});
new TestUnit<RegTestContext>("Engine.startKeyserverLookup", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.startKeyserverLookup", new AdapterBaseTestContext(), ctx -> {
ctx.engine.startKeyserverLookup();
});
new TestUnit<RegTestContext>("Engine.startSync", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.startSync", new AdapterBaseTestContext(), ctx -> {
ctx.engine.startSync();
});
new TestUnit<RegTestContext>("Engine.stopSync", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.stopSync", new AdapterBaseTestContext(), ctx -> {
ctx.engine.stopSync();
});
new TestUnit<RegTestContext>("Engine.isSyncRunning", new RegTestContext(), ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.isSyncRunning", new AdapterBaseTestContext(), ctx -> {
ctx.engine.isSyncRunning();
});
new TestUnit<AdapterBaseTestContext>("Engine.config_passphrase",new RegTestContext() , ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.config_passphrase",new AdapterBaseTestContext() , ctx -> {
ctx.engine.config_passphrase("SUPERCOMPLICATEDPASSPHRASE");
});
new TestUnit<AdapterBaseTestContext>("Engine.config_passphrase_for_new_keys",new RegTestContext() , ctx -> {
new TestUnit<AdapterBaseTestContext>("Engine.config_passphrase_for_new_keys",new AdapterBaseTestContext() , ctx -> {
ctx.engine.config_passphrase_for_new_keys(true, "SUPERCOMPLICATEDPASSPHRASE");
});

3
test/java/foundation/pEp/jniadapter/test/templateAliceBob/MultiPeerCTX.java

@ -51,7 +51,7 @@ class MultiPeerCTX extends FsMQManagerTestContext {
super(selfAddress);
}
public void init() throws Throwable {
public MultiPeerCTX init() throws Throwable {
super.init();
vID = new Vector<Identity>();
vStr = new Vector<String>();
@ -97,5 +97,6 @@ class MultiPeerCTX extends FsMQManagerTestContext {
log("pEp PER_USER_DIR : " + engine.getUserDirectory());
log("pEp ProtocolVersion: " + engine.getProtocolVersion());
log("pEp Version : " + engine.getVersion());
return this;
}
}

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

@ -1,12 +1,14 @@
package foundation.pEp.jniadapter.test.utils;
import foundation.pEp.pitytest.*;
import foundation.pEp.jniadapter.*;
import foundation.pEp.jniadapter.Engine;
import foundation.pEp.jniadapter.Identity;
import foundation.pEp.jniadapter.Message;
import foundation.pEp.pitytest.AbstractTestContext;
import foundation.pEp.pitytest.TestLogger;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
//public class ABAliceTestContext extends AdapterBaseTestContext {
@ -59,14 +61,7 @@ public class AdapterBaseTestContext extends AbstractTestContext {
public Message msgToSelf;
public Message msgToBob;
// Misc
public Vector<Identity> vID;
public Vector<String> vStr;
public void init() throws Throwable {
vID = new Vector<Identity>();
vStr = new Vector<String>();
public AdapterBaseTestContext init() throws Throwable {
callbacks = new TestCallbacks();
engine = new Engine();
engine.setMessageToSendCallback(callbacks);
@ -74,7 +69,7 @@ public class AdapterBaseTestContext extends AbstractTestContext {
TestLogger.logH2("Machine directory: ");
TestLogger.log(engine.getMachineDirectory());
TestLogger.logH2("User directory:" );
TestLogger.logH2("User directory:");
TestLogger.log(engine.getUserDirectory());
@ -91,27 +86,29 @@ public class AdapterBaseTestContext extends AbstractTestContext {
msgToSelf = AdapterTestUtils.makeNewTestMessage(alice, alice, Message.Direction.Outgoing);
msgToBob = AdapterTestUtils.makeNewTestMessage(alice, bob, Message.Direction.Outgoing);
vID.add(bob);
vStr.add("StringItem");
Path path;
path = Paths.get(filenameBobPub);
keyBobPub = Files.readAllBytes(path);
try {
keyBobPub = Files.readAllBytes(path);
path = Paths.get(filenameBobSec);
keyBobSec = Files.readAllBytes(path);
path = Paths.get(filenameBobSec);
keyBobSec = Files.readAllBytes(path);
path = Paths.get(filenameAlicePub);
keyAlicePub = Files.readAllBytes(path);
path = Paths.get(filenameAlicePub);
keyAlicePub = Files.readAllBytes(path);
path = Paths.get(filenameAliceSec);
keyAliceSec = Files.readAllBytes(path);
path = Paths.get(filenameAliceSec);
keyAliceSec = Files.readAllBytes(path);
path = Paths.get(filenameAlicePubPassphrase);
keyAlicePubPassphrase = Files.readAllBytes(path);
path = Paths.get(filenameAlicePubPassphrase);
keyAlicePubPassphrase = Files.readAllBytes(path);
path = Paths.get(filenameAliceSecPassphrase);
keyAliceSecPassphrase = Files.readAllBytes(path);
path = Paths.get(filenameAliceSecPassphrase);
keyAliceSecPassphrase = Files.readAllBytes(path);
} catch (Throwable e) {
throw new RuntimeException(e);
}
return this;
}
}

3
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/ctx/FsMQManagerBaseTestContext.java

@ -23,7 +23,7 @@ public class FsMQManagerBaseTestContext extends AbstractTestContext {
}
@Override
public void init() throws Throwable {
public FsMQManagerBaseTestContext init() throws Throwable {
peerNames = new ArrayList<>();
peerNames.add("Alice");
peerNames.add("Bob");
@ -31,6 +31,7 @@ public class FsMQManagerBaseTestContext extends AbstractTestContext {
createPeerMapAndPeerList();
defineSelfAndUpdatePeers();
messages = FsMQManagerTestUtils.createTestMessages(self.getAddress(), MSG_COUNT);
return this;
}
private void createPeerMapAndPeerList() {

3
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/ctx/FsMQManagerTestContext.java

@ -10,10 +10,11 @@ public class FsMQManagerTestContext extends FsMQManagerBaseTestContext {
}
@Override
public void init() throws Throwable {
public FsMQManagerTestContext init() throws Throwable {
super.init();
qm = new FsMQManager(self);
qm.identities.addAll(peerList);
return this;
}
}

3
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/identities/TestMain.java

@ -31,8 +31,9 @@ class FsMQManagerIdentitiesTestContext extends AbstractTestContext {
List<String> messages;
@Override
public void init() throws Throwable {
public FsMQManagerIdentitiesTestContext init() throws Throwable {
messages = FsMQManagerTestUtils.createTestMessages(ownAddress, MSG_COUNT);
return this;
}
}

4
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmqmanager/test/stateless_rxtx/TestMain.java

@ -14,13 +14,13 @@ class FsMQManagerBaseTestContext extends AbstractTestContext {
Entity carol;
@Override
public void init() throws Throwable {
public FsMQManagerBaseTestContext init() throws Throwable {
alice = new Entity("Alice");
bob = new Entity("Bob");
carol = new Entity("Carol");
alice.add(bob);
alice.add(carol);
return this;
}
class Entity {

4
test/java/foundation/pEp/jniadapter/test/utils/transport/fsmsgqueue/test/regression/TestMain.java

@ -20,9 +20,10 @@ class FsMsgQueueTestContext extends AbstractTestContext {
FsMsgQueue queue;
@Override
public void init() throws Throwable {
public FsMsgQueueTestContext init() throws Throwable {
deleteQDir();
messages = createTestMessages(msgCount);
return this;
}
public void deleteQDir() {
@ -32,6 +33,7 @@ class FsMsgQueueTestContext extends AbstractTestContext {
deleteRecursively(qDir);
if (qDir.exists()) throw new RuntimeException("Cant delete Dir:" + qDirPath);
}
}
public ArrayList<String> createTestMessages(int count) {

8
test/java/foundation/pEp/pitytest/TestContextInterface.java

@ -1,11 +1,17 @@
package foundation.pEp.pitytest;
public interface TestContextInterface {
void init() throws Throwable;
TestContextInterface init() throws Throwable;
boolean isInitialized();
void setInitialized(boolean initialized);
boolean isUninitializable();
void setUninitializable(boolean uninitializable);
String getTestContextName();
void setTestContextName(String name);
}

2
test/java/foundation/pEp/pitytest/TestSuite.java

@ -75,7 +75,7 @@ public class TestSuite {
}
public void add(TestUnit t) {
tests.add(t);
tests.add(t.copy());
}
public void run() {

49
test/java/foundation/pEp/pitytest/TestUnit.java

@ -44,20 +44,45 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
add(TestSuite.getDefault());
}
//Shallow Copy
public TestUnit(TestUnit<T> orig) {
testUnitName = orig.testUnitName;
ctx = orig.ctx;
lambda = orig.lambda;
result = orig.result;
state = orig.state;
lastException = orig.lastException;
verboseMode = orig.verboseMode;
testColor = orig.testColor;
logFmtPadding = orig.logFmtPadding;
logFmtMsgLen = orig.logFmtMsgLen;
logFmtTestDuration = orig.logFmtTestDuration;
lineWidthMin = orig.lineWidthMin;
logFmtTestNameLen = orig.logFmtTestNameLen;
logFmtCtxNameLen = orig.logFmtCtxNameLen;
}
//Shallow Copy
public TestUnit<T> copy() {
return new TestUnit<>(this);
}
public boolean isVerboseMode() {
return verboseMode;
}
public void setVerboseMode(boolean verboseMode) {
public TestUnit<T> setVerboseMode(boolean verboseMode) {
this.verboseMode = verboseMode;
return this;
}
public TermColor getTestColor() {
return testColor;
}
public void setTestColor(TermColor testColor) {
public TestUnit<T> setTestColor(TermColor testColor) {
this.testColor = testColor;
return this;
}
public TestState getResult() {
@ -65,7 +90,11 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
}
public Throwable getLastException() {
return lastException;
Throwable ret = new Throwable("No Exception caught");
if(lastException != null) {
ret = lastException;
}
return ret;
}
public TestUnit<T> add(TestSuite suite) {
@ -82,10 +111,15 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
return ctx;
}
public TestUnit<T> setContext(T ctx) {
this.ctx = ctx;
return this;
}
public void run() {
TestUtils.standardOutErrEnabled(verboseMode);
if (ctx.isUninitializable()) {
setTestState(TestState.CTX_FAIL);
setTestState(TestState.SKIPPED);
TestUtils.standardOutErrEnabled(true);
} else {
try {
@ -147,18 +181,17 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
}
case CTX_FAIL: {
setTestResult(TestState.SKIPPED);
// logH1(makeLogString());
break;
}
}
}
private void setTestResult(TestState r) {
assert (r == TestState.SKIPPED || r == TestState.FAILED || r == TestState.SUCCESS || r == TestState.UNEVALUATED ): "PityTest Internal: illegal result value '" + r +"'";
assert (r == TestState.SKIPPED || r == TestState.FAILED || r == TestState.SUCCESS || r == TestState.UNEVALUATED) : "PityTest Internal: illegal result value '" + r + "'";
result = r;
TestUtils.standardOutErrEnabled(true);
logH1(makeLogString());
if (result == TestState.FAILED || result == TestState.CTX_FAIL) {
if (result == TestState.FAILED || state == TestState.CTX_FAIL) {
log("ERROR: " + getLastException().toString());
}
if (verboseMode) logRaw("\n\n");
@ -193,7 +226,7 @@ public class TestUnit<T extends TestContextInterface> implements Runnable {
DecimalFormat f = new DecimalFormat("0.000");
String durationFmtd = f.format(testDuration.toMillis() / 1000.0);
strTestDuration = TestUtils.padOrClipString(" [" + durationFmtd + " sec] ", "=", logFmtTestDuration, TestUtils.Alignment.Right, ".. ");
} else {
} else {
strTestDuration = TestUtils.padOrClipString("", "=", logFmtTestDuration, TestUtils.Alignment.Right, ".. ");
}

12
test/java/foundation/pEp/pitytest/examples/ctxinitfail/TestMain.java

@ -1,8 +1,10 @@
package foundation.pEp.pitytest.examples.ctxinitfail;
import static foundation.pEp.pitytest.TestLogger.*;
import foundation.pEp.pitytest.AbstractTestContext;
import foundation.pEp.pitytest.TestSuite;
import foundation.pEp.pitytest.TestUnit;
import foundation.pEp.pitytest.*;
import static foundation.pEp.pitytest.TestLogger.log;
class CtxInitFailContext extends AbstractTestContext {
@ -10,9 +12,13 @@ class CtxInitFailContext extends AbstractTestContext {
int result;
@Override
public void init() throws Throwable {
public CtxInitFailContext init() throws RuntimeException {
name = "PityTest";
log("Hello World from: " + name);
// throw new RuntimeException("regddjkl");
result = 50 / 0;
return this;
}
}

3
test/java/foundation/pEp/pitytest/examples/ctxmembers/TestMain.java

@ -18,12 +18,13 @@ class CtxMembersTestContext extends AbstractTestContext {
ExampleCtxMember incorrect = new ExampleCtxMember(false); // WRONG
@Override
public void init() throws Throwable {
public CtxMembersTestContext init() throws Throwable {
log("=== OUTPUT FROM TEST CONTEXT INIT BEGIN ===");
log(getTestContextName()+ " - init() called");
correct = new ExampleCtxMember(true);
name = "PityTest";
log("=== OUTPUT FROM TEST CONTEXT INIT END ===");
return this;
}
}

3
test/java/foundation/pEp/pitytest/examples/helloworld/TestMain.java

@ -7,8 +7,9 @@ class HelloWorldTestContext extends AbstractTestContext {
String name;
@Override
public void init() throws Throwable {
public HelloWorldTestContext init() throws Throwable {
name = "PityTest";
return this;
}
}

3
test/java/foundation/pEp/pitytest/examples/testsuite/TestMain.java

@ -6,8 +6,9 @@ class TestSuiteContext extends AbstractTestContext {
String name;
@Override
public void init() throws Throwable {
public TestSuiteContext init() throws Throwable {
name = "PityTest";
return this;
}
}

6
test/java/foundation/pEp/pitytest/utils/Pair.java

@ -24,5 +24,11 @@ public class Pair<K, V> {
key = f;
value = s;
}
public String toString() {
String ret="";
ret += "'" + key.toString() + "' : '" + value.toString() + "'";
return ret;
}
}

102
test/java/foundation/pEp/pitytest/utils/TestUtils.java

@ -7,10 +7,7 @@ import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@ -330,5 +327,102 @@ public class TestUtils {
return Math.max(min, Math.min(max, val));
}
/*
Random data generators
*/
public static int randomInt(int min, int max) {
int ret = 0;
int range = max - min;
if (range <= 0) {
range = 1;
}
Random rand = new Random();
ret = rand.nextInt(range) + min;
return ret;
}
public static String randomASCIIString(CharClass charClass, int len) {
byte[] array = new byte[len]; // length is bounded by 7
int rangeMin = 0;
int rangeMax = 0;
switch (charClass) {
case Unbounded: {
rangeMin = 0;
rangeMax = 255;
break;
}
case Alpha: {
rangeMin = 65;
rangeMax = 122;
break;
}
case Numeric: {
rangeMin = 48;
rangeMax = 57;
break;
}
case Alphanumeric: {
rangeMin = 48;
rangeMax = 122;
break;
}
}
new Random().nextBytes(array);
for (int i = 0; i < array.length; i++) {
array[i] = (byte)clip(randomInt(rangeMin, rangeMax),0,255);
}
String generatedString = new String(array, Charset.forName("UTF-8"));
return generatedString;
}
public enum CharClass {
Unbounded(0) {
@Override
public String toString() {
return "Unbounded";
}
},
Alpha(1) {
@Override
public String toString() {
return "Alpha";
}
},
Numeric(2) {
@Override
public String toString() {
return "Numeric";
}
},
Alphanumeric(3) {
@Override
public String toString() {
return "Alphanumeric";
}
};
public final int value;
private static HashMap<Integer, CharClass> intMap;
private CharClass(int value) {
this.value = value;
}
public static CharClass getByInt(int value) {
if (intMap == null) {
intMap = new HashMap<Integer, CharClass>();
for (CharClass s : CharClass.values()) {
intMap.put(s.value, s);
}
}
if (intMap.containsKey(value)) {
return intMap.get(value);
}
return null;
}
}
}

27
utils/extract_pEp_status_codes_from_engine.sh → utils/gen_status_codes.sh

@ -6,15 +6,14 @@ if [ ! -f $1 ]; then
echo -e "\e[1m\e[31mInput file not found!\e[0m"
fi
if [ -z "$2" ]; then
echo -e "\e[1m\e[31mNo output file supplied\e[0m"
fi
if [ "$#" -ne 2 ]; then
echo "Expected use is: $0 input_file output_file"
if [ "$#" -ne 1 ]; then
echo "Expected use is: $0 input_file"
exit 1
fi
STAT_FILE=status_list.yml2
PASS_FILE=passphrase_status_list.yml2
################################################################################
# Select GNU SED #
################################################################################
@ -33,15 +32,17 @@ esac
# Transform input file PEP_STATUS to yml2 status #
################################################################################
$SED -n '/} PEP_STATUS/q;p' $1 > $2
$SED -i -n '/STATUS_OK/,$p' $2
$SED -i -e 's/\(.*\)/\L\1/' $2
$SED -i "-e s/ pep/ pEp/g" $2
$SED -i s/=/\>/g $2
$SED -i s/,//g $2
$SED -n '/} PEP_STATUS/q;p' $1 > $STAT_FILE
$SED -i -n '/STATUS_OK/,$p' $STAT_FILE
$SED -i -e 's/\(.*\)/\L\1/' $STAT_FILE
$SED -i "-e s/ pep/ pEp/g" $STAT_FILE
$SED -i s/=/\>/g $STAT_FILE
$SED -i s/,//g $STAT_FILE
grep -i passphrase $STAT_FILE | sed -e 's/^/enumitem/' > $PASS_FILE
################################################################################
# Show results #
################################################################################
cat $2
cat $STAT_FILE
cat $PASS_FILE
Loading…
Cancel
Save