aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/eIDASDataStoreTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/eIDASDataStoreTest.java')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/eIDASDataStoreTest.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/eIDASDataStoreTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/eIDASDataStoreTest.java
new file mode 100644
index 00000000..16865b33
--- /dev/null
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/test/eidas/specific/modules/authmodule_eIDASv2/eIDASDataStoreTest.java
@@ -0,0 +1,87 @@
+package at.asitplus.test.eidas.specific.modules.authmodule_eIDASv2;
+
+import java.security.MessageDigest;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.util.Base64Utils;
+
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.exception.SQLiteServiceException;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.exception.eIDASAuthenticationException;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.service.eIDASDataStore;
+import at.asitplus.eidas.specific.modules.authmodule_eIDASv2.utils.eIDASResponseUtils;
+import at.gv.egiz.eaaf.core.impl.data.Trible;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("/SpringTest-context_basic_test.xml")
+public class eIDASDataStoreTest {
+
+ @Autowired private eIDASDataStore dataStore;
+
+ private static final String P1_TRANSID = "123456789";
+ private static final String P1_eIDASID = "DE/AT/121asdf1as5f1as6f1asd2f1asdf1asdf1asd23f1asdf1asdf4sd7fsdf1asdf1asd2f1asd56f7asdf4asdfasdf1";
+
+ private static final String P2_TRANSID = "987654321";
+ private static final String P2_eIDASID = "EE/AT/asfasfasdfasdfasdfasdfasdfasvafasdfasdfasdfasdfasdfasvascasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasd";
+
+ @Test
+ public void dummyTest() {
+
+ }
+
+ @Test
+ public void insertTestOne() throws SQLiteServiceException, eIDASAuthenticationException {
+ Trible<String, String, String> eidasId = eIDASResponseUtils.parseEidasPersonalIdentifier(P1_eIDASID);
+ String ernbId = createHashFromUniqueId(eidasId.getThird());
+ dataStore.storeNationalId(
+ P1_TRANSID,
+ eidasId,
+ ernbId);
+
+
+ if (StringUtils.isEmpty(dataStore.getEidasRawNationalId(ernbId))
+ && dataStore.getEidasRawNationalId(ernbId).equals(eidasId.getThird()))
+ throw new SQLiteServiceException("No eIDAS RAW Id in SQLite DB", null);
+
+ if (StringUtils.isEmpty(dataStore.getErnbNationalId(eidasId))
+ && dataStore.getErnbNationalId(eidasId).equals(ernbId) )
+ throw new SQLiteServiceException("No ERnB Id in SQLite DB", null);
+
+ }
+
+ @Test
+ public void insertTestTwo() throws SQLiteServiceException, eIDASAuthenticationException {
+ Trible<String, String, String> eidasId = eIDASResponseUtils.parseEidasPersonalIdentifier(P2_eIDASID);
+ String ernbId = createHashFromUniqueId(eidasId.getThird());
+ dataStore.storeNationalId(
+ P2_TRANSID,
+ eidasId,
+ ernbId);
+
+ if (StringUtils.isEmpty(dataStore.getEidasRawNationalId(ernbId))
+ && dataStore.getEidasRawNationalId(ernbId).equals(eidasId.getThird()))
+ throw new SQLiteServiceException("No eIDAS RAW Id in SQLite DB", null);
+
+ if (StringUtils.isEmpty(dataStore.getErnbNationalId(eidasId))
+ && dataStore.getErnbNationalId(eidasId).equals(ernbId))
+ throw new SQLiteServiceException("No ERnB Id in SQLite DB", null);
+
+ }
+
+ private String createHashFromUniqueId(String uniqueId) throws eIDASAuthenticationException {
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA-256");
+ byte[] hash = md.digest(uniqueId.getBytes("UTF-8"));
+ String hashBase64 = new String(Base64Utils.encode(hash), "UTF-8").replaceAll("\r\n", "");
+ return hashBase64;
+
+ } catch (Exception ex) {
+ throw new eIDASAuthenticationException("internal.03", new Object[]{}, ex);
+
+ }
+ }
+}