From 8d97abea3d167acd93863ae1c41df715f3a86302 Mon Sep 17 00:00:00 2001 From: heck Date: Tue, 30 Jun 2020 14:12:54 +0200 Subject: [PATCH] test for key_import() --- .../pEp/jniadapter/test/jni96/Makefile | 37 +++++++++++ .../pEp/jniadapter/test/jni96/TestAlice.java | 61 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 test/java/foundation/pEp/jniadapter/test/jni96/Makefile create mode 100644 test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java diff --git a/test/java/foundation/pEp/jniadapter/test/jni96/Makefile b/test/java/foundation/pEp/jniadapter/test/jni96/Makefile new file mode 100644 index 0000000..101e87d --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni96/Makefile @@ -0,0 +1,37 @@ +include ../../../../../../../Makefile.conf +include ../Makefile.conf + +TEST_UNIT_NAME=jni96 + +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 diff --git a/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java b/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java new file mode 100644 index 0000000..084c0b6 --- /dev/null +++ b/test/java/foundation/pEp/jniadapter/test/jni96/TestAlice.java @@ -0,0 +1,61 @@ +package foundation.pEp.jniadapter.test.jni96; +import static foundation.pEp.pitytest.TestLogger.*; + +import foundation.pEp.jniadapter.Identity; +import foundation.pEp.pitytest.*; +import foundation.pEp.pitytest.utils.TestUtils; +import foundation.pEp.jniadapter.test.utils.*; + +import static foundation.pEp.pitytest.TestLogger.log; + +import java.util.Vector; + +class TestAlice { + public static void main(String[] args) throws Exception { + TestSuite.getDefault().setVerbose(true); + TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN); + + new TestUnit("import_key() with pub no return",new AdapterBaseTestContext() , ctx -> { + Vector privKeys = null; + privKeys = ctx.engine.importKey(ctx.keyAlicePub); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 0: "pub key should not be in return"; + }); + + new TestUnit("import_key() with priv key",new AdapterBaseTestContext() , ctx -> { + Vector privKeys = null; + privKeys = ctx.engine.importKey(ctx.keyAliceSec); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 1: "imported priv key should be returned"; + }); + + new TestUnit("import_key() 2 pub",new AdapterBaseTestContext() , ctx -> { + byte[] keys = concat(ctx.keyAlicePub, ctx.keyBobPub); + + Vector privKeys = null; + privKeys = ctx.engine.importKey(keys); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 0: "imported priv key should be returned"; + }); + + new TestUnit("import_key() with key array",new AdapterBaseTestContext() , ctx -> { + byte[] keys = concat(ctx.keyAlicePub, concat(ctx.keyAliceSec, concat(ctx.keyBobPub, ctx.keyBobSec))); + + Vector privKeys = null; + privKeys = ctx.engine.importKey(keys); + log(AdapterTestUtils.identityListToString(privKeys, false)); + assert privKeys.size() == 3: "imported priv key should be returned"; + }); + + TestSuite.getDefault().run(); + } + + public static byte[] concat(byte[] a, byte[] b) { + byte[] c = new byte[a.length + b.length]; + System.arraycopy(a, 0, c, 0, a.length); + System.arraycopy(b, 0, c, a.length, b.length); + return c; + } +} + +