aboutsummaryrefslogtreecommitdiff
path: root/standalone
diff options
context:
space:
mode:
authorJ08nY2024-03-27 14:24:15 +0100
committerJ08nY2024-03-27 14:24:15 +0100
commit042f82049d87e1ee600ec84114ed69d0743ea9d0 (patch)
tree20a947428b6c4252dbb8f91cde7fa77321af7076 /standalone
parentccdeec2bfab550091dd17936770c0fff3d730049 (diff)
downloadECTester-042f82049d87e1ee600ec84114ed69d0743ea9d0.tar.gz
ECTester-042f82049d87e1ee600ec84114ed69d0743ea9d0.tar.zst
ECTester-042f82049d87e1ee600ec84114ed69d0743ea9d0.zip
Diffstat (limited to 'standalone')
-rw-r--r--standalone/build.gradle.kts6
-rw-r--r--standalone/src/test/java/cz/crcs/ectester/reader/IdentTests.java14
-rw-r--r--standalone/src/test/java/cz/crcs/ectester/standalone/AppTests.java75
-rw-r--r--standalone/src/test/java/cz/crcs/ectester/standalone/IdentTests.java49
-rw-r--r--standalone/src/test/java/cz/crcs/ectester/standalone/LibTests.java54
5 files changed, 184 insertions, 14 deletions
diff --git a/standalone/build.gradle.kts b/standalone/build.gradle.kts
index 095c4b4..1c9c485 100644
--- a/standalone/build.gradle.kts
+++ b/standalone/build.gradle.kts
@@ -3,6 +3,7 @@ plugins {
application
jacoco
id("com.google.osdetector") version "1.7.3"
+ id("com.adarshr.test-logger") version "4.0.0"
}
repositories {
@@ -15,9 +16,14 @@ dependencies {
testImplementation(platform("org.junit:junit-bom:5.10.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
+ testImplementation("org.junit-pioneer:junit-pioneer:2.2.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
+java {
+ sourceCompatibility = JavaVersion.VERSION_11
+}
+
application {
applicationName = "ECTesterStandalone"
mainClass = "cz.crcs.ectester.standalone.ECTesterStandalone"
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());
+ }
+
+ }
+}