aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules/authmodule-eIDAS-v2/src
diff options
context:
space:
mode:
authorChristian Kollmann <christian.kollmann@a-sit.at>2021-02-22 11:36:03 +0100
committerChristian Kollmann <christian.kollmann@a-sit.at>2021-02-22 11:36:03 +0100
commit3c838c11bc536a7418654989752b94b457d3f52f (patch)
treeca7c5850beaae8e5943344490e8645648f41c5dc /eidas_modules/authmodule-eIDAS-v2/src
parent84244f4ac1909c20ce36531f110705b24edbad12 (diff)
downloadNational_eIDAS_Gateway-3c838c11bc536a7418654989752b94b457d3f52f.tar.gz
National_eIDAS_Gateway-3c838c11bc536a7418654989752b94b457d3f52f.tar.bz2
National_eIDAS_Gateway-3c838c11bc536a7418654989752b94b457d3f52f.zip
Refactor test for InitialSearchTask
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java104
1 files changed, 50 insertions, 54 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java
index e0138f62..d855c98d 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskTest.java
@@ -41,7 +41,6 @@ import eu.eidas.auth.commons.attribute.AttributeDefinition;
import eu.eidas.auth.commons.attribute.ImmutableAttributeMap;
import eu.eidas.auth.commons.attribute.PersonType;
import eu.eidas.auth.commons.protocol.impl.AuthenticationResponse;
-import lombok.val;
import org.apache.commons.lang3.RandomStringUtils;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
@@ -67,6 +66,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
+import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.junit.Assert.assertThrows;
@RunWith(SpringJUnit4ClassRunner.class)
@@ -91,24 +91,12 @@ public class InitialSearchTaskTest {
private final String randomBpk = RandomStringUtils.randomNumeric(6);
private final String randomIdentifier = RandomStringUtils.randomNumeric(10);
private final String randomPseudonym = DE_ST + randomIdentifier;
- private final String randomFamilyName = RandomStringUtils.randomAlphabetic(10);
- private final String randomGivenName = RandomStringUtils.randomAlphabetic(10);
- private final String randomPlaceOfBirth = RandomStringUtils.randomAlphabetic(10);
- private final String randomBirthName = RandomStringUtils.randomAlphabetic(10);
+ private final String randomFamilyName = randomAlphabetic(10);
+ private final String randomGivenName = randomAlphabetic(10);
+ private final String randomPlaceOfBirth = randomAlphabetic(10);
+ private final String randomBirthName = randomAlphabetic(10);
private final String randomBirthDate = "2011-01-" + (10 + new Random().nextInt(18));
-// /**
-// * jUnit class initializer.
-// *
-// * @throws IOException In case of an error
-// */
-// @BeforeClass
-// public static void classInitializer() throws IOException {
-// final String current = new java.io.File(".").toURI().toString();
-// System.setProperty("eidas.ms.configuration", current
-// + "src/test/resources/config/junit_config_1.properties");
-// }
-
/**
* jUnit test set-up.
*/
@@ -134,7 +122,7 @@ public class InitialSearchTaskTest {
@Test
@DirtiesContext
public void testNode100_UserIdentifiedUpdateNecessary_a() throws Exception {
- String newFirstName = RandomStringUtils.randomAlphabetic(10);
+ String newFirstName = randomAlphabetic(10);
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList(
new RegisterResult(randomBpk, randomIdentifier, newFirstName, randomFamilyName, randomBirthDate)));
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
@@ -154,7 +142,7 @@ public class InitialSearchTaskTest {
@DirtiesContext
public void testNode100_UserIdentifiedUpdateNecessary_b() throws TaskExecutionException {
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
- String newRandomGivenName = RandomStringUtils.randomAlphabetic(10);
+ String newRandomGivenName = randomAlphabetic(10);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList(
new RegisterResult(randomBpk, randomIdentifier, newRandomGivenName, randomFamilyName, randomBirthDate)));
@@ -174,7 +162,7 @@ public class InitialSearchTaskTest {
public void testNode101_ManualFixNecessary_a() {
ArrayList<RegisterResult> zmrResult = new ArrayList<>();
zmrResult.add(new RegisterResult(randomBpk, randomIdentifier, randomGivenName, randomFamilyName, randomBirthDate));
- String newRandomGivenName = randomGivenName + RandomStringUtils.randomAlphabetic(2);
+ String newRandomGivenName = randomGivenName + randomAlphabetic(2);
zmrResult.add(new RegisterResult(randomBpk, randomIdentifier, newRandomGivenName, randomFamilyName, randomBirthDate));
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult);
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
@@ -196,7 +184,7 @@ public class InitialSearchTaskTest {
Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());
ArrayList<RegisterResult> ernpResult = new ArrayList<>();
ernpResult.add(new RegisterResult(randomBpk, randomPseudonym, randomGivenName, randomFamilyName, randomBirthDate));
- String newRandomGivenName = randomGivenName + RandomStringUtils.randomAlphabetic(2);
+ String newRandomGivenName = randomGivenName + randomAlphabetic(2);
ernpResult.add(
new RegisterResult(randomBpk, randomIdentifier, newRandomGivenName, randomFamilyName, randomBirthDate));
Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult);
@@ -384,12 +372,12 @@ public class InitialSearchTaskTest {
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
- Assert.assertEquals("Wrong bpk", null, bPk);
+ Assert.assertNull("Wrong bpk", bPk);
- Boolean transitionGUI = (Boolean)executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
- Assert.assertEquals("Wrong transition", null, transitionGUI);
- Boolean transitionErnb = (Boolean)executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
- Assert.assertEquals("Wrong transition", true, transitionErnb);
+ Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
+ Assert.assertNull("Wrong transition", transitionGUI);
+ Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
+ Assert.assertTrue("Wrong transition", transitionErnb);
}
/**
@@ -403,18 +391,18 @@ public class InitialSearchTaskTest {
Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate)).thenReturn(
Collections.singletonList(
- new RegisterResult(randomBpk, randomIdentifier, randomGivenName, randomFamilyName, randomBirthDate)));
+ new RegisterResult(randomBpk, randomIdentifier, randomGivenName, randomFamilyName, randomBirthDate)));
task.execute(pendingReq, executionContext);
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
- Assert.assertEquals("Wrong bpk", null, bPk);
- Boolean transitionGUI = (Boolean)executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
- Assert.assertEquals("Wrong transition", true, transitionGUI);
- Boolean transitionErnb = (Boolean)executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
- Assert.assertEquals("Wrong transition", null, transitionErnb);
+ Assert.assertNull("Wrong bpk", bPk);
+ Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
+ Assert.assertTrue("Wrong transition", transitionGUI);
+ Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
+ Assert.assertNull("Wrong transition", transitionErnb);
}
/**
@@ -435,11 +423,11 @@ public class InitialSearchTaskTest {
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
- Assert.assertEquals("Wrong bpk", null, bPk);
- Boolean transitionGUI = (Boolean)executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
- Assert.assertEquals("Wrong transition", true, transitionGUI);
- Boolean transitionErnb = (Boolean)executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
- Assert.assertEquals("Wrong transition", null, transitionErnb);
+ Assert.assertNull("Wrong bpk", bPk);
+ Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
+ Assert.assertTrue("Wrong transition", transitionGUI);
+ Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
+ Assert.assertNull("Wrong transition", transitionErnb);
}
/**
@@ -453,7 +441,7 @@ public class InitialSearchTaskTest {
ArrayList<RegisterResult> ernbResult = new ArrayList<>();
ernbResult.add(new RegisterResult(randomBpk, randomIdentifier, randomGivenName, randomFamilyName,
randomBirthDate));
- ernbResult.add(new RegisterResult(randomBpk+"1", randomIdentifier, randomGivenName, randomFamilyName,
+ ernbResult.add(new RegisterResult(randomBpk + "1", randomIdentifier, randomGivenName, randomFamilyName,
randomBirthDate));
Mockito.when(ernpClient.searchWithMds(randomGivenName, randomFamilyName, randomBirthDate)).thenReturn(ernbResult);
@@ -462,11 +450,11 @@ public class InitialSearchTaskTest {
String bPk = (String)
pendingReq.getSessionData(AuthProcessDataWrapper.class)
.getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK);
- Assert.assertEquals("Wrong bpk", null, bPk);
- Boolean transitionGUI = (Boolean)executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
- Assert.assertEquals("Wrong transition", true, transitionGUI);
- Boolean transitionErnb = (Boolean)executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
- Assert.assertEquals("Wrong transition", null, transitionErnb);
+ Assert.assertNull("Wrong bpk", bPk);
+ Boolean transitionGUI = (Boolean) executionContext.get(Constants.TRANSITION_TO_GENERATE_OTHER_LOGIN_METHOD_GUI_TASK);
+ Assert.assertTrue("Wrong transition", transitionGUI);
+ Boolean transitionErnb = (Boolean) executionContext.get(Constants.TRANSITION_TO_CREATE_NEW_ERNB_ENTRY_TASK);
+ Assert.assertNull("Wrong transition", transitionErnb);
}
@NotNull
@@ -498,25 +486,32 @@ public class InitialSearchTaskTest {
String dateOfBirth, String taxNumber, String placeOfBirth,
String birthName) throws URISyntaxException {
ImmutableAttributeMap.Builder builder = ImmutableAttributeMap.builder()
- .put(generateStringAttribute(Constants.eIDAS_ATTR_PERSONALIDENTIFIER, "ff", "af"), identifier)
- .put(generateStringAttribute(Constants.eIDAS_ATTR_CURRENTFAMILYNAME, "fff", "aff"), familyName)
- .put(generateStringAttribute(Constants.eIDAS_ATTR_CURRENTGIVENNAME, "ffff", "afff"), givenName)
- .put(generateDateTimeAttribute(Constants.eIDAS_ATTR_DATEOFBIRTH, "fffff", "affff"), dateOfBirth);
+ .put(generateStringAttribute(Constants.eIDAS_ATTR_PERSONALIDENTIFIER,
+ randomAlphabetic(2), randomAlphabetic(2)), identifier)
+ .put(generateStringAttribute(Constants.eIDAS_ATTR_CURRENTFAMILYNAME,
+ randomAlphabetic(3), randomAlphabetic(3)), familyName)
+ .put(generateStringAttribute(Constants.eIDAS_ATTR_CURRENTGIVENNAME,
+ randomAlphabetic(4), randomAlphabetic(4)), givenName)
+ .put(generateDateTimeAttribute(Constants.eIDAS_ATTR_DATEOFBIRTH,
+ randomAlphabetic(5), randomAlphabetic(5)), dateOfBirth);
if (taxNumber != null) {
- builder.put(generateStringAttribute(Constants.eIDAS_ATTR_TAXREFERENCE, "ffffff", "afffff"), taxNumber);
+ builder.put(generateStringAttribute(Constants.eIDAS_ATTR_TAXREFERENCE,
+ randomAlphabetic(6), randomAlphabetic(6)), taxNumber);
}
if (birthName != null) {
- builder.put(generateStringAttribute(Constants.eIDAS_ATTR_BIRTHNAME, "fffffff", "affffff"), birthName);
+ builder.put(generateStringAttribute(Constants.eIDAS_ATTR_BIRTHNAME,
+ randomAlphabetic(7), randomAlphabetic(7)), birthName);
}
if (placeOfBirth != null) {
- builder.put(generateStringAttribute(Constants.eIDAS_ATTR_PLACEOFBIRTH, "ffffffff", "afffffff"),
- placeOfBirth);
+ builder.put(generateStringAttribute(Constants.eIDAS_ATTR_PLACEOFBIRTH,
+ randomAlphabetic(8), randomAlphabetic(8)), placeOfBirth);
}
final ImmutableAttributeMap attributeMap = builder.build();
- val b = new AuthenticationResponse.Builder();
- return b.id("aasdf").issuer("asd").subject("asf").statusCode("200").inResponseTo("asdf").subjectNameIdFormat(
- "afaf").attributes(attributeMap).build();
+ return new AuthenticationResponse.Builder().id(randomAlphabetic(5))
+ .issuer(randomAlphabetic(5)).subject(randomAlphabetic(5)).statusCode("200")
+ .inResponseTo(randomAlphabetic(5)).subjectNameIdFormat(randomAlphabetic(5))
+ .attributes(attributeMap).build();
}
private AttributeDefinition<Object> generateStringAttribute(String friendlyName, String fragment, String prefix)
@@ -525,6 +520,7 @@ public class InitialSearchTaskTest {
".LiteralStringAttributeValueMarshaller");
}
+ @SuppressWarnings("SameParameterValue")
private AttributeDefinition<Object> generateDateTimeAttribute(String friendlyName, String fragment, String prefix)
throws URISyntaxException {
return generateAttribute(friendlyName, fragment, prefix, "eu.eidas.auth.commons.attribute.impl" +