summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/InlineKeyStoreTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/InlineKeyStoreTest.java')
-rw-r--r--eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/InlineKeyStoreTest.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/InlineKeyStoreTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/InlineKeyStoreTest.java
new file mode 100644
index 00000000..d4419956
--- /dev/null
+++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/credentials/InlineKeyStoreTest.java
@@ -0,0 +1,140 @@
+package at.gv.egiz.eaaf.core.test.credentials;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
+
+import java.net.URL;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.annotation.DirtiesContext.ClassMode;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import at.gv.egiz.eaaf.core.exceptions.EaafException;
+import at.gv.egiz.eaaf.core.impl.credential.inline.InlineKeyStoreParser;
+import at.gv.egiz.eaaf.core.test.dummy.DummyAuthConfigMap;
+import lombok.SneakyThrows;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/spring/test_eaaf_pvp_lazy.beans.xml")
+@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
+public class InlineKeyStoreTest {
+
+ @Autowired
+ private DummyAuthConfigMap mapConfig;
+
+ @Autowired
+ private ResourceLoader resourceLoader;
+
+ @Test
+ @SneakyThrows
+ public void inlineKeyStoreEccSuccess() throws EaafException {
+ assertNotNull("no keystore", InlineKeyStoreParser.buildKeyStore(
+ new URL(null,
+ "pkcs12:keystore?private=src/test/resources/data/certs/privateEcKey.pem"
+ + "&cert=src/test/resources/data/certs/selfSignedEcCertificate.pem",
+ new InlineKeyStoreParser()),
+ resourceLoader,
+ mapConfig.getConfigurationRootDirectory()));
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void inlineTrustStoreSuccess() throws EaafException {
+ assertNotNull("no keystore", InlineKeyStoreParser.buildKeyStore(
+ new URL(null,
+ "pkcs12:truststore?"
+ + "cert=src/test/resources/data/certs/selfSignedEcCertificate.pem",
+ new InlineKeyStoreParser()),
+ resourceLoader,
+ mapConfig.getConfigurationRootDirectory()));
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void inlineKeyStoreSymSuccess() throws EaafException {
+ assertNotNull("no keystore", InlineKeyStoreParser.buildKeyStore(
+ new URL(null,
+ "pkcs12:keystore?"
+ + "inlineSecret=mxuqEAXci2cMNU5FCdbxIaNzJoMv%2FWds7j9gY992TTw%3D",
+ new InlineKeyStoreParser()),
+ resourceLoader,
+ mapConfig.getConfigurationRootDirectory()));
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void invalidCertFile() throws EaafException {
+ check("pkcs12:keystore?"
+ + "private=src/test/resources/data/certs/privateEcKey.pem"
+ + "&cert=src/test/resources/data/certs/invalidCertificate.pem");
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void missingKey() throws EaafException {
+ check("pkcs12:keystore?"
+ + "cert=src/test/resources/data/certs/selfSignedEcCertificate.pem"
+ + "&cert=src/test/resources/data/certs/BRZStammCA201.pem");
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void missingCert() throws EaafException {
+ check("pkcs12:keystore?"
+ + "private=src/test/resources/data/certs/privateEcKey.pem");
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void invalidType() throws EaafException {
+ check("pkcs12:unknown?"
+ + "private=src/test/resources/data/certs/privateEcKey.pem");
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void twoKeyFiles() throws EaafException {
+ check("pkcs12:keystore?"
+ + "cert=src/test/resources/data/certs/selfSignedEcCertificate.pem"
+ + "&private=src/test/resources/data/certs/privateEcKey.pem"
+ + "&private=src/test/resources/data/certs/privateEcKey.pem");
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void twoSymKeyFiles() throws EaafException {
+ check("pkcs12:keystore?"
+ + "inlineSecret=mxuqEAXci2cMNU5FCdbxIaNzJoMv%2FWds7j9gY992TTw%3D"
+ + "&inlineSecret=mxuqEAXci2cMNU5FCdbxIaNzJoMv%2FWds7j9gY992TTw%3D");
+
+ }
+
+ @Test
+ @SneakyThrows
+ public void missingParams() throws EaafException {
+ check("pkcs12:keystore");
+
+ }
+
+ private void check(String url) {
+ assertThrows(IllegalArgumentException.class,
+ () -> InlineKeyStoreParser.buildKeyStore(
+ new URL(null, url, new InlineKeyStoreParser()), resourceLoader,
+ mapConfig.getConfigurationRootDirectory()));
+
+ }
+
+}