diff options
Diffstat (limited to 'standalone/src/test/java/cz')
4 files changed, 178 insertions, 14 deletions
diff --git a/standalone/src/test/java/cz/crcs/ectester/reader/IdentTests.java b/standalone/src/test/java/cz/crcs/ectester/reader/IdentTests.java deleted file mode 100644 index 2940f1e..0000000 --- a/standalone/src/test/java/cz/crcs/ectester/reader/IdentTests.java +++ /dev/null @@ -1,14 +0,0 @@ -package cz.crcs.ectester.reader; - -import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -public class IdentTests { - @Test - void kaIdents() { - for (KeyAgreementIdent keyAgreementIdent : KeyAgreementIdent.list()) { - assertNotNull(keyAgreementIdent.getBaseAlgo()); - } - } -} diff --git a/standalone/src/test/java/cz/crcs/ectester/standalone/AppTests.java b/standalone/src/test/java/cz/crcs/ectester/standalone/AppTests.java new file mode 100644 index 0000000..cffc94f --- /dev/null +++ b/standalone/src/test/java/cz/crcs/ectester/standalone/AppTests.java @@ -0,0 +1,75 @@ +package cz.crcs.ectester.standalone; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.junitpioneer.jupiter.ExpectedToFail; +import org.junitpioneer.jupiter.StdErr; +import org.junitpioneer.jupiter.StdIo; +import org.junitpioneer.jupiter.StdOut; + +import static org.junit.jupiter.api.Assertions.*; + +public class AppTests { + + @Test + @StdIo() + public void help(StdOut out) { + ECTesterStandalone.main(new String[]{"-h"}); + String s = out.capturedString(); + assertTrue(s.contains("ECTesterStandalone")); + } + + @Test + @StdIo() + public void listLibraries(StdOut out) { + ECTesterStandalone.main(new String[]{"list-libs"}); + String s = out.capturedString(); + assertTrue(s.contains("BouncyCastle")); + } + + @Test + @StdIo() + public void listData(StdOut out) { + ECTesterStandalone.main(new String[]{"list-data"}); + String s = out.capturedString(); + assertTrue(s.contains("secg")); + } + + @Test + @StdIo() + public void listSuites(StdOut out) { + ECTesterStandalone.main(new String[]{"list-suites"}); + String s = out.capturedString(); + assertTrue(s.contains("default test suite")); + } + + @Test + @StdIo() + public void listIdents(StdOut out) { + ECTesterStandalone.main(new String[]{"list-types"}); + String s = out.capturedString(); + assertTrue(s.contains("NONEwithECDSA")); + } + + @SuppressWarnings("JUnitMalformedDeclaration") + @ExpectedToFail + @ParameterizedTest + // TODO: Add "wolfCrypt" to the list + @ValueSource(strings = {"Bouncy", "Sun", "libtomcrypt", "Botan", "Crypto++", "OpenSSL 3", "BoringSSL", "libgcrypt", "mbedTLS", "2021" /* IPPCP */, "Nettle", "LibreSSL"}) + @StdIo() + public void defaultSuite(String libName, StdOut out, StdErr err) { + String[] args = new String[]{"test", "default", libName}; + if (libName.equals("Botan") || libName.equals("Crypto++")) { + args = new String[]{"test", "--kpg-type", "ECDH", "default", libName}; + } + ECTesterStandalone.main(args); + String sout = out.capturedString(); + if (sout.contains("Exception")) { + fail("Default suite has exceptions."); + } + String serr = err.capturedString(); + if (!serr.isEmpty()) { + fail(serr); + } + } +} diff --git a/standalone/src/test/java/cz/crcs/ectester/standalone/IdentTests.java b/standalone/src/test/java/cz/crcs/ectester/standalone/IdentTests.java new file mode 100644 index 0000000..e6f520e --- /dev/null +++ b/standalone/src/test/java/cz/crcs/ectester/standalone/IdentTests.java @@ -0,0 +1,49 @@ +package cz.crcs.ectester.standalone; + +import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; +import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent; +import cz.crcs.ectester.standalone.consts.SignatureIdent; +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.junit.jupiter.api.Test; + +import javax.crypto.KeyAgreement; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.Provider; +import java.security.Signature; + +import static org.junit.jupiter.api.Assertions.*; + +public class IdentTests { + + Provider bc = new BouncyCastleProvider(); + + @Test + void kaIdents() throws NoSuchAlgorithmException { + for (KeyAgreementIdent keyAgreementIdent : KeyAgreementIdent.list()) { + assertNotNull(keyAgreementIdent.getBaseAlgo()); + } + KeyAgreementIdent ecdh = KeyAgreementIdent.get("ECDH"); + assertNotNull(ecdh); + KeyAgreement instance = ecdh.getInstance(bc); + assertNotNull(instance); + } + + @Test + void kpgIdents() throws NoSuchAlgorithmException { + assertFalse(KeyPairGeneratorIdent.list().isEmpty()); + KeyPairGeneratorIdent kpg = KeyPairGeneratorIdent.get("ECDH"); + assertNotNull(kpg); + KeyPairGenerator instance = kpg.getInstance(bc); + assertNotNull(instance); + } + + @Test + void sigIdents() throws NoSuchAlgorithmException { + assertFalse(SignatureIdent.list().isEmpty()); + SignatureIdent ecdsa = SignatureIdent.get("NONEwithECDSA"); + assertNotNull(ecdsa); + Signature instance = ecdsa.getInstance(bc); + assertNotNull(instance); + } +} diff --git a/standalone/src/test/java/cz/crcs/ectester/standalone/LibTests.java b/standalone/src/test/java/cz/crcs/ectester/standalone/LibTests.java new file mode 100644 index 0000000..6e11ccd --- /dev/null +++ b/standalone/src/test/java/cz/crcs/ectester/standalone/LibTests.java @@ -0,0 +1,54 @@ +package cz.crcs.ectester.standalone; +import cz.crcs.ectester.standalone.libs.*; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import java.lang.reflect.InvocationTargetException; +import java.util.LinkedList; +import java.util.List; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class LibTests { + + ProviderECLibrary[] libs; + + @BeforeAll + public void loadLibs() { + List<ProviderECLibrary> libObjects = new LinkedList<>(); + Class<?>[] libClasses = new Class[]{SunECLib.class, + BouncyCastleLib.class, + TomcryptLib.class, + BotanLib.class, + CryptoppLib.class, + OpensslLib.class, + BoringsslLib.class, + GcryptLib.class, + MscngLib.class, + WolfCryptLib.class, + MbedTLSLib.class, + IppcpLib.class, + MatrixsslLib.class, + NettleLib.class, + LibresslLib.class}; + for (Class<?> c : libClasses) { + try { + libObjects.add((ProviderECLibrary) c.getDeclaredConstructor().newInstance()); + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | + InvocationTargetException ignored) { + } + } + libs = libObjects.toArray(new ProviderECLibrary[0]); + for (ProviderECLibrary lib : libs) { + lib.initialize(); + } + } + + @Test + public void loaded() { + for (ProviderECLibrary lib : libs) { + System.err.printf("%s: %b%n", lib.getClass().getSimpleName(), lib.isInitialized()); + } + + } +} |
