-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add more tests.
Showing
6 changed files
with
265 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
standalone/src/test/java/cz/crcs/ectester/reader/IdentTests.java
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
standalone/src/test/java/cz/crcs/ectester/standalone/AppTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
standalone/src/test/java/cz/crcs/ectester/standalone/IdentTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
standalone/src/test/java/cz/crcs/ectester/standalone/LibTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} | ||
} |