From 41f60dbeba15430542dc2e08505a8e8662774e57 Mon Sep 17 00:00:00 2001 From: mikera Date: Mon, 29 Jan 2024 17:31:37 +0000 Subject: [PATCH] Tests for encrypted PEM key export --- .../java/convex/cli/key/KeyExportTest.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/convex-cli/src/test/java/convex/cli/key/KeyExportTest.java b/convex-cli/src/test/java/convex/cli/key/KeyExportTest.java index 70ebdd076..b1d1bb9e9 100644 --- a/convex-cli/src/test/java/convex/cli/key/KeyExportTest.java +++ b/convex-cli/src/test/java/convex/cli/key/KeyExportTest.java @@ -11,6 +11,8 @@ import convex.cli.CLTester; import convex.cli.ExitCodes; import convex.cli.Helpers; +import convex.core.crypto.AKeyPair; +import convex.core.crypto.PEMTools; import convex.core.crypto.PFXTools; import convex.core.data.AccountKey; import convex.core.util.Utils; @@ -61,27 +63,16 @@ public void testKeyGenerateAndExport() { "key", "export", "--keystore-password", new String(KEYSTORE_PASSWORD), - "--p", new String(KEY_PASSWORD), - "--keystore", KEYSTORE_FILENAME, - "--key", publicKey, - "--export-password", new String(EXPORT_PASSWORD) - ); - assertEquals(ExitCodes.SUCCESS,tester.getResult()); - // TODO test generated output - - // command key.export publicKey with leading 0x - tester = CLTester.run( - "key", - "export", - "--keystore-password", new String(KEYSTORE_PASSWORD), + "--password", new String(KEY_PASSWORD), "--keystore", KEYSTORE_FILENAME, - "--key", "0x" + publicKey, + "--public-key", publicKey, "--export-password", new String(EXPORT_PASSWORD) ); + String s=tester.getOutput(); + System.out.println(s); assertEquals(ExitCodes.SUCCESS,tester.getResult()); - // TODO test generated output - - + AKeyPair kp=AKeyPair.create(PEMTools.decryptPrivateKeyFromPEM(s, EXPORT_PASSWORD)); + assertEquals(ak,kp.getAccountKey()); } }