
7 changed files with 202 additions and 3 deletions
@ -0,0 +1,9 @@ |
|||||
|
|
||||
|
|
||||
|
namespace pEp { |
||||
|
namespace JNIAdapter { |
||||
|
|
||||
|
char* passphraseRequiredCallback(); |
||||
|
|
||||
|
}; |
||||
|
}; |
@ -0,0 +1,37 @@ |
|||||
|
include ../../../../../../../Makefile.conf |
||||
|
include ../Makefile.conf |
||||
|
|
||||
|
TEST_UNIT_NAME=jni114 |
||||
|
|
||||
|
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 -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 |
@ -0,0 +1,76 @@ |
|||||
|
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.*; |
||||
|
import foundation.pEp.pitytest.*; |
||||
|
import foundation.pEp.pitytest.utils.TestUtils; |
||||
|
import foundation.pEp.jniadapter.test.utils.*; |
||||
|
|
||||
|
import java.util.Vector; |
||||
|
|
||||
|
|
||||
|
// https://pep.foundation/jira/browse/JNI-111
|
||||
|
|
||||
|
|
||||
|
class TestAlice { |
||||
|
public static void main(String[] args) throws Exception { |
||||
|
// readKey();
|
||||
|
TestSuite.getDefault().setVerbose(true); |
||||
|
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); |
||||
|
|
||||
|
AdapterBaseTestContext jni114Ctx = new AdapterBaseTestContext(); |
||||
|
new TestUnit<AdapterBaseTestContext>("ImportKey/SetOwnKey", jni114Ctx, ctx -> { |
||||
|
// ImportKey and setOwnKey (with passphrase, of course)
|
||||
|
ctx.alice = ctx.engine.importKey(ctx.keyAliceSecPassphrase).get(0); |
||||
|
log(AdapterTestUtils.identityToString(ctx.alice, true)); |
||||
|
ctx.alice.user_id = "23"; |
||||
|
ctx.alice = ctx.engine.setOwnKey(ctx.alice, ctx.alice.fpr); |
||||
|
assert ctx.alice != null : "Keyimport failed"; |
||||
|
assert ctx.alice.me == true; |
||||
|
assert ctx.alice.comm_type == CommType.PEP_ct_pEp; |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
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); |
||||
|
} catch (pEpException e) { |
||||
|
assert e instanceof pEpPassphraseRequired : "wrong exception type"; |
||||
|
return; |
||||
|
} |
||||
|
assert false : "encrypt_message() should have failed"; |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
new TestUnit<AdapterBaseTestContext>("use callback for encrypt", jni114Ctx, ctx -> { |
||||
|
// Register callback passphraseRequired()
|
||||
|
ctx.engine.setPassphraseRequiredCallback(new Sync.PassphraseRequiredCallback() { |
||||
|
@Override |
||||
|
public String passphraseRequired() { |
||||
|
log("passphraseRequired() called"); |
||||
|
log("Please Enter Passphrase..."); |
||||
|
sleep(2000); |
||||
|
return "passphrase_alice"; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
// myself
|
||||
|
ctx.alice = ctx.engine.myself(ctx.alice); |
||||
|
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 enc.getEncFormat() == Message.EncFormat.PGPMIME : "Message not encrypted"; |
||||
|
assert !enc.getLongmsg().contains(ctx.msgToSelf.getLongmsg()) : "Message not encrypted"; |
||||
|
log(AdapterTestUtils.msgToString(enc, false)); |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
TestSuite.getDefault().run(); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue