diff options
| author | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-01-12 16:14:59 +0100 | 
|---|---|---|
| committer | Alexander Marsalek <amarsalek@iaik.tugraz.at> | 2021-01-12 16:14:59 +0100 | 
| commit | e1fe4825116ff87d3352aee248920a6e561b1ee0 (patch) | |
| tree | 13f45dc7c7e8048a20fdc2a20eb5d49f26fc0b2f /eidas_modules/authmodule-eIDAS-v2/src/test | |
| parent | c1b44dcd325e9e49ba38c384b9bfb981dca5a776 (diff) | |
| parent | 7961d920b67a4ce6cfb6bb9d9941242041bd47c6 (diff) | |
| download | National_eIDAS_Gateway-e1fe4825116ff87d3352aee248920a6e561b1ee0.tar.gz National_eIDAS_Gateway-e1fe4825116ff87d3352aee248920a6e561b1ee0.tar.bz2 National_eIDAS_Gateway-e1fe4825116ff87d3352aee248920a6e561b1ee0.zip | |
Merge branch 'eidas-matching' into issue6
# Conflicts:
#	eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/tasks/InitialSearchTask.java
Diffstat (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test')
2 files changed, 271 insertions, 424 deletions
| diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java index f7fc6b06..9f58ba71 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/tasks/InitialSearchTaskFirstTest.java @@ -1,11 +1,33 @@ +/* + * Copyright 2020 A-SIT Plus GmbH + * AT-specific eIDAS Connector has been developed in a cooperation between EGIZ, + * A-SIT Plus GmbH, A-SIT, and Graz University of Technology. + * + * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "License"); + * You may not use this work except in compliance with the License. + * You may obtain a copy of the License at: + * https://joinup.ec.europa.eu/news/understanding-eupl-v12 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * This product combines work with different licenses. See the "NOTICE" text + * file for details on the various modules and licenses. + * The "NOTICE" text file is part of the distribution. Any derivative works + * that you distribute must include a readable copy of the "NOTICE" text file. + */ +  package at.asitplus.eidas.specific.modules.auth.eidas.v2.test.tasks;  import at.asitplus.eidas.specific.modules.auth.eidas.v2.Constants;  import at.asitplus.eidas.specific.modules.auth.eidas.v2.dao.RegisterResult; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernb.IErnbClient; +import at.asitplus.eidas.specific.modules.auth.eidas.v2.ernp.IErnpClient;  import at.asitplus.eidas.specific.modules.auth.eidas.v2.exception.ManualFixNecessaryException;  import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.DeSpecificDetailSearchProcessor; -import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.ICountrySpecificDetailSearchProcessor;  import at.asitplus.eidas.specific.modules.auth.eidas.v2.handler.ItSpecificDetailSearchProcessor;  import at.asitplus.eidas.specific.modules.auth.eidas.v2.tasks.InitialSearchTask;  import at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.IZmrClient; @@ -27,10 +49,9 @@ import org.junit.Before;  import org.junit.BeforeClass;  import org.junit.Test;  import org.junit.runner.RunWith; -import org.mockito.InjectMocks;  import org.mockito.Mock;  import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; +import org.mockito.MockitoAnnotations;  import org.springframework.mock.web.MockHttpServletRequest;  import org.springframework.mock.web.MockHttpServletResponse;  import org.springframework.test.annotation.DirtiesContext; @@ -45,29 +66,36 @@ import java.io.IOException;  import java.net.URI;  import java.net.URISyntaxException;  import java.util.ArrayList; -import java.util.List; +import java.util.Collections; +import java.util.Random; -@RunWith(SpringJUnit4ClassRunner.class) +import static org.junit.Assert.assertThrows; +@RunWith(SpringJUnit4ClassRunner.class)  @ContextConfiguration("/SpringTest-context_tasks_test.xml")  @DirtiesContext(classMode = ClassMode.BEFORE_CLASS)  public class InitialSearchTaskFirstTest { -  @Autowired(required = true) -  @Mock -  @InjectMocks -  private InitialSearchTask task; +  private static final String DE_ST = "de/st/"; +  private static final String IT_ST = "it/st/"; +  private InitialSearchTask task; +  @Mock    private IZmrClient zmrClient; -  private IErnbClient ernbClient; +  @Mock +  private IErnpClient ernpClient;    final ExecutionContext executionContext = new ExecutionContextImpl(); -  private MockHttpServletRequest httpReq; -  private MockHttpServletResponse httpResp;    private TestRequestImpl pendingReq; -  private String randomIdentifier = RandomStringUtils.randomNumeric(10); -  private String randomFamilyName = RandomStringUtils.randomNumeric(11); -  private String randomGivenName = RandomStringUtils.randomNumeric(12); +  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 randomDate = "2011-01-" + (10 + new Random().nextInt(18)); +    /**     * jUnit class initializer.     * @@ -85,8 +113,11 @@ public class InitialSearchTaskFirstTest {     */    @Before    public void setUp() throws URISyntaxException, EaafStorageException { -    httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); -    httpResp = new MockHttpServletResponse(); +    MockitoAnnotations.initMocks(this); +    task = new InitialSearchTask(new ArrayList<>(), ernpClient, zmrClient); + +    MockHttpServletRequest httpReq = new MockHttpServletRequest("POST", "https://localhost/authhandler"); +    MockHttpServletResponse httpResp = new MockHttpServletResponse();      RequestContextHolder.resetRequestAttributes();      RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp)); @@ -96,446 +127,275 @@ public class InitialSearchTaskFirstTest {          .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response);    } -  @Test -  @DirtiesContext    /**     * One match, but register update needed     */ -  // NOTE: Why is the method named "testNode100a"? -  public void testNode100a() throws Exception { - -    //Mock ZMR -    ArrayList<RegisterResult> zmrResult = new ArrayList<>(); -    String randomBpk = RandomStringUtils.randomNumeric(6); -    zmrResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, "Max_new", randomFamilyName, "2011-01-01")); - -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult); - -    //Mock ernb -    ArrayList<RegisterResult> ernbResult = new ArrayList<>(); - -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult); - -    task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient); -    try { -      task.execute(pendingReq, executionContext); -      String bPk = (String) -          pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); -      Assert.assertTrue("Wrong bpk", bPk.equals(randomBpk)); - -    } catch (final TaskExecutionException e) { -      // NOTE: assertTrue is probably the wrong method to use ... why catch the exception anyway? -      Assert.assertTrue("Wrong workflow, should not reach this point", false); -    } -  } -    @Test -  // NOTE: Why is @DirtiesContext after each test necessary? What is changed in the context and why?    @DirtiesContext +  public void testNode100_UserIdentifiedUpdateNecessary_a() throws Exception { +    String newFirstName = RandomStringUtils.randomAlphabetic(10); +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList( +        new RegisterResult(randomBpk, randomPseudonym, newFirstName, randomFamilyName, randomDate))); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); + +    task.execute(pendingReq, executionContext); +    String bPk = (String) +        pendingReq.getSessionData(AuthProcessDataWrapper.class) +            .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + +    Assert.assertEquals("Wrong bpk", bPk, randomBpk); +  } +    /**     * One match, but register update needed     */ -  public void testNode100b() throws Exception { - -    //Mock ZMR -    ArrayList<RegisterResult> zmrResult = new ArrayList<>(); - -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult);//"de/st/max123"??? - -    //Mock ernb -    ArrayList<RegisterResult> ernbResult = new ArrayList<>(); -    String randomBpk = RandomStringUtils.randomNumeric(6); -    ernbResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, "Max_new", randomFamilyName, "2011-01-01")); - -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult); - -    task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient); -    try { -      task.execute(pendingReq, executionContext); -      String bPk = (String) -          pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); -      Assert.assertTrue("Wrong bpk", bPk.equals(randomBpk)); - -    } catch (final TaskExecutionException e) { -      Assert.assertTrue("Wrong workflow, should not reach this point", false); -    } -  } - -    @Test    @DirtiesContext +  public void testNode100_UserIdentifiedUpdateNecessary_b() throws TaskExecutionException { +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    String newRandomGivenName = RandomStringUtils.randomAlphabetic(10); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList( +        new RegisterResult(randomBpk, randomPseudonym, newRandomGivenName, randomFamilyName, randomDate))); + +    task.execute(pendingReq, executionContext); +    String bPk = (String) +        pendingReq.getSessionData(AuthProcessDataWrapper.class) +            .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + +    Assert.assertEquals("Wrong bpk", bPk, randomBpk); +  } +    /**     * Two matches found in ZMR     */ -  public void testNode101a() throws Exception { - -    //Mock ZMR +  @Test +  @DirtiesContext +  public void testNode101_ManualFixNecessary_a() {      ArrayList<RegisterResult> zmrResult = new ArrayList<>(); -    zmrResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01")); -    zmrResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, "Maximilian", randomFamilyName, "2011-01-01")); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult); - -    //Mock ernb -    ArrayList<RegisterResult> ernbResult = new ArrayList<>(); -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult); - -    task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient); -    try { -      task.execute(pendingReq, executionContext); -      Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false); -    } catch (final TaskExecutionException e) { -      Throwable origE = e.getOriginalException(); -      Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); -    } +    zmrResult.add(new RegisterResult(randomBpk, randomPseudonym, randomGivenName, randomFamilyName, randomDate)); +    String newRandomGivenName = randomGivenName + RandomStringUtils.randomAlphabetic(2); +    zmrResult.add(new RegisterResult(randomBpk, randomPseudonym, newRandomGivenName, randomFamilyName, randomDate)); +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(zmrResult); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); + +    TaskExecutionException exception = assertThrows(TaskExecutionException.class, +        () -> task.execute(pendingReq, executionContext)); + +    Throwable origE = exception.getOriginalException(); +    Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));    } -  @Test -  @DirtiesContext    /** -   * Two matches found in ErnB +   * Two matches found in ErnP     */ -  public void testNode101b() throws Exception { - -    //Mock ZMR -    ArrayList<RegisterResult> zmrResult = new ArrayList<>(); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult); - -    //Mock ernb -    ArrayList<RegisterResult> ernbResult = new ArrayList<>(); -    ernbResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01")); -    ernbResult.add(new RegisterResult("bpkMax", "de/st/"+randomIdentifier, "Maximilian", randomFamilyName, "2011-01-01")); - -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult); - -    task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient); -    try { -      task.execute(pendingReq, executionContext); -      Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false); -    } catch (final TaskExecutionException e) { -      Throwable origE = e.getOriginalException(); -      Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); -    } -  } -    @Test    @DirtiesContext +  public void testNode101_ManualFixNecessary_b() { +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    ArrayList<RegisterResult> ernpResult = new ArrayList<>(); +    ernpResult.add(new RegisterResult(randomBpk, randomPseudonym, randomGivenName, randomFamilyName, randomDate)); +    String newRandomGivenName = randomGivenName + RandomStringUtils.randomAlphabetic(2); +    ernpResult.add( +        new RegisterResult(randomBpk, randomPseudonym, newRandomGivenName, randomFamilyName, randomDate)); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(ernpResult); + +    TaskExecutionException exception = assertThrows(TaskExecutionException.class, +        () -> task.execute(pendingReq, executionContext)); + +    Throwable origE = exception.getOriginalException(); +    Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); +  } +    /**     * One match, no register update needed     */ -  public void testNode102a() throws Exception { - -    String randomBpk = RandomStringUtils.randomNumeric(12);; -    //Mock ZMR -    ArrayList<RegisterResult> zmrResult = new ArrayList<>(); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult); - -    //Mock ernb -    ArrayList<RegisterResult> ernbResult = new ArrayList<>(); -    ernbResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01")); - -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult); - -    task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient); -    try { -      task.execute(pendingReq, executionContext); -      String bPk = (String) -          pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); -      Assert.assertTrue("Wrong bpk", bPk.equals(randomBpk)); -    } catch (final TaskExecutionException e) { -      Assert.assertTrue("Wrong workflow, should not reach this point", false); -    } -  } -    @Test    @DirtiesContext +  public void testNode102_UserIdentified_a() throws Exception { +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList( +        new RegisterResult(randomBpk, randomPseudonym, randomGivenName, randomFamilyName, randomDate))); + +    task.execute(pendingReq, executionContext); +    String bPk = (String) +        pendingReq.getSessionData(AuthProcessDataWrapper.class) +            .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); +    Assert.assertEquals("Wrong bpk", bPk, randomBpk); +  } +    /**     * One match, no register update needed     */ -  public void testNode102b() throws Exception { -    String randomBpk = RandomStringUtils.randomNumeric(14); -    //Mock ZMR -    ArrayList<RegisterResult> zmrResult = new ArrayList<>(); -    zmrResult.add(new RegisterResult(randomBpk, "de/st/"+randomIdentifier, randomGivenName, randomFamilyName, "2011-01-01")); - -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult); - -    //Mock ernb -    ArrayList<RegisterResult> ernbResult = new ArrayList<>(); - -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult); +  @Test +  @DirtiesContext +  public void testNode102_UserIdentified_b() throws Exception { +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.singletonList( +        new RegisterResult(randomBpk, randomPseudonym, randomGivenName, randomFamilyName, randomDate))); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); -    task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient); -    try { -      task.execute(pendingReq, executionContext); -      String bPk = (String) -          pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); -      Assert.assertTrue("Wrong bpk", bPk.equals(randomBpk)); +    task.execute(pendingReq, executionContext); -    } catch (final TaskExecutionException e) { -      Assert.assertTrue("Wrong workflow, should not reach this point", false); -    } +    String bPk = (String) +        pendingReq.getSessionData(AuthProcessDataWrapper.class) +            .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); +    Assert.assertEquals("Wrong bpk", bPk, randomBpk);    } -  @Test -  @DirtiesContext    /** -   * One match found in ZMR and ErnB with detail search +   * One match found in ZMR and ErnP with detail search     */ -  public void testNode103IT() throws Exception { -    String bpkRegister = RandomStringUtils.randomNumeric(14); +  @Test +  @DirtiesContext +  public void testNode103_UserIdentified_IT() throws Exception {      String taxNumber = RandomStringUtils.randomNumeric(14);      final AuthenticationResponse response = buildDummyAuthResponseRandomPersonIT_Tax(taxNumber);      TestRequestImpl pendingReq1 = new TestRequestImpl();      pendingReq1.getSessionData(AuthProcessDataWrapper.class)          .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); - -    //Mock ZMR initial search -    ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>(); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial); -    ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>(); -    //String bpk, String pseudonym, String givenName, String familyName, String dateOfBirth, -    //                        String placeOfBirth, String birthName, String taxNumber, PostalAddressType address -    zmrResultSpecific.add(new RegisterResult(bpkRegister, "it/st/"+randomIdentifier+"4", randomGivenName, randomFamilyName, -        "2011-01-01", null, null, taxNumber, null)); - -    Mockito.when(zmrClient.searchItSpecific(taxNumber)).thenReturn(zmrResultSpecific); - -    //Mock ernb initial search -    ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>(); -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial); - - -    //Mock country specific search -    List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>(); -    ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor(ernbClient, zmrClient); -    handlers.add(it); -    task = new InitialSearchTask(handlers, ernbClient, zmrClient); - -    try { -      task.execute(pendingReq1, executionContext); - -      String bPk = (String) -          pendingReq1.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); -      Assert.assertTrue("Wrong bpk", bPk.equals(bpkRegister)); -    } catch (final TaskExecutionException e) { -      Assert.assertTrue("Wrong workflow, should not reach this point", false); -    } +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    String newRandomPseudonym = IT_ST + randomIdentifier + RandomStringUtils.randomNumeric(2); +    Mockito.when(zmrClient.searchItSpecific(taxNumber)).thenReturn(Collections.singletonList( +        new RegisterResult(randomBpk, newRandomPseudonym, randomGivenName, randomFamilyName, +            randomDate, null, null, taxNumber, null))); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    task = new InitialSearchTask( +        Collections.singletonList(new ItSpecificDetailSearchProcessor(ernpClient, zmrClient)), +        ernpClient, zmrClient); + +    task.execute(pendingReq1, executionContext); + +    String bPk = (String) +        pendingReq1.getSessionData(AuthProcessDataWrapper.class) +            .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); +    Assert.assertEquals("Wrong bpk", bPk, randomBpk);    } -  @Test -  @DirtiesContext    /** -   * Multiple matches found in ZMR and ErnB with detail search +   * Multiple matches found in ZMR and ErnP with detail search     */ -  public void testNode103DE() throws Exception { -    String givenName = randomGivenName; -    String familyName = randomFamilyName; -    String pseudonym = "de/st/max1234"; -    String bpk = "bpkMax"; -    String dateOfBirth = "2011-01-01"; -    String placeOfBirth = "München"; -    String birthName = "BabyMax"; -    final AuthenticationResponse response = buildDummyAuthResponseDE(givenName, familyName, pseudonym, -        dateOfBirth, placeOfBirth, birthName); +  @Test +  @DirtiesContext +  public void testNode103_UserIdentified_DE() throws Exception { +    final AuthenticationResponse response = buildDummyAuthResponseDE(randomGivenName, randomFamilyName, +        randomPseudonym, +        randomDate, randomPlaceOfBirth, randomBirthName);      TestRequestImpl pendingReq1 = new TestRequestImpl();      pendingReq1.getSessionData(AuthProcessDataWrapper.class)          .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); - -    //Mock ZMR initial search -    ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>(); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial); -    ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>(); - -    zmrResultSpecific.add(new RegisterResult(bpk, pseudonym, givenName, familyName, dateOfBirth, placeOfBirth, -        birthName, -        null, null)); - -    Mockito.when(zmrClient.searchDeSpecific(givenName, familyName, dateOfBirth, placeOfBirth, birthName)).thenReturn(zmrResultSpecific); - -    //Mock ernb initial search -    ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>(); -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial); - -    //Mock country specific search -    List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>(); -    DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor(ernbClient, zmrClient); -    handlers.add(de); -    task = new InitialSearchTask(handlers, ernbClient, zmrClient); - -    try { -      task.execute(pendingReq1, executionContext); - -      String bPk = (String) -          pendingReq1.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); -      Assert.assertTrue("Wrong bpk", bPk.equals(bpk)); -    } catch (final TaskExecutionException e) { -      Assert.assertTrue("Wrong workflow, should not reach this point", false); -    } +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    Mockito.when(zmrClient.searchDeSpecific(randomGivenName, randomFamilyName, randomDate, randomPlaceOfBirth, +        randomBirthName)) +        .thenReturn(Collections.singletonList(new RegisterResult(randomBpk, randomPseudonym, randomGivenName, +            randomFamilyName, randomDate, randomPlaceOfBirth, randomBirthName, null, null))); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    task = new InitialSearchTask( +        Collections.singletonList(new DeSpecificDetailSearchProcessor(ernpClient, zmrClient)), +        ernpClient, zmrClient); + +    task.execute(pendingReq1, executionContext); + +    String resultBpk = (String) +        pendingReq1.getSessionData(AuthProcessDataWrapper.class) +            .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); +    Assert.assertEquals("Wrong bpk", resultBpk, randomBpk);    } -  @Test -  @DirtiesContext    /** -   * Multiple matches found in ZMR and ErnB with detail search +   * Multiple matches found in ZMR and ErnP with detail search     */ -  public void testNode104DE() throws Exception { -    String givenName = randomGivenName; -    String familyName = randomFamilyName; -    String pseudonym1 = "de/st/max1234"; -    String pseudonym2 = "de/st/max12345"; -    String bpk1 = "bpkMax"; -    String bpk2 = "bpkMax1"; -    String dateOfBirth = "2011-01-01"; -    String placeOfBirth = "München"; -    String birthName = "BabyMax"; -    final AuthenticationResponse response = buildDummyAuthResponseDE(givenName, familyName, pseudonym1, -        dateOfBirth, placeOfBirth, birthName); +  @Test +  @DirtiesContext +  public void testNode104_ManualFixNecessary_DE() throws Exception { +    String newRandomPseudonym = randomPseudonym + RandomStringUtils.randomNumeric(2); +    String newRandomBpk = randomBpk + RandomStringUtils.randomNumeric(6); +    final AuthenticationResponse response = buildDummyAuthResponseDE(randomGivenName, randomFamilyName, +        randomPseudonym, +        randomDate, randomPlaceOfBirth, randomBirthName);      TestRequestImpl pendingReq1 = new TestRequestImpl();      pendingReq1.getSessionData(AuthProcessDataWrapper.class)          .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); - -    //Mock ZMR initial search -    ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>(); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial); +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());      ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>(); - -    zmrResultSpecific.add(new RegisterResult(bpk1, pseudonym1, givenName, familyName, dateOfBirth, placeOfBirth, -        birthName, -        null, null)); -    zmrResultSpecific.add(new RegisterResult(bpk2, pseudonym2, givenName, familyName, dateOfBirth, placeOfBirth, -        birthName, -        null, null)); -    Mockito.when(zmrClient.searchDeSpecific(givenName, familyName, dateOfBirth, placeOfBirth, birthName)).thenReturn(zmrResultSpecific); - - -    //Mock ernb initial search -    ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>(); -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial); - -    //Mock country specific search -    List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>(); -    DeSpecificDetailSearchProcessor de = new DeSpecificDetailSearchProcessor(ernbClient, zmrClient); -    handlers.add(de); -    task = new InitialSearchTask(handlers, ernbClient, zmrClient); - -    try { -      task.execute(pendingReq1, executionContext); - -      Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false); - -    } catch (final TaskExecutionException e) { -      Throwable origE = e.getOriginalException(); -      Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); -    } +    zmrResultSpecific.add( +        new RegisterResult(randomBpk, randomPseudonym, randomGivenName, randomFamilyName, randomDate, +            randomPlaceOfBirth, randomBirthName, null, null)); +    zmrResultSpecific.add(new RegisterResult(newRandomBpk, newRandomPseudonym, randomGivenName, randomFamilyName, randomDate, +        randomPlaceOfBirth, randomBirthName, null, null)); +    Mockito.when(zmrClient.searchDeSpecific(randomGivenName, randomFamilyName, randomDate, randomPlaceOfBirth, +        randomBirthName)).thenReturn(zmrResultSpecific); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    task = new InitialSearchTask( +        Collections.singletonList(new DeSpecificDetailSearchProcessor(ernpClient, zmrClient)), +        ernpClient, zmrClient); + +    TaskExecutionException exception = assertThrows(TaskExecutionException.class, +        () -> task.execute(pendingReq1, executionContext)); + +    Throwable origE = exception.getOriginalException(); +    Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));    } -  @Test -  @DirtiesContext    /** -   * Multiple matches found in ZMR and ErnB with detail search +   * Multiple matches found in ZMR and ErnP with detail search     */ -  public void testNode104IT() throws Exception { -    String fakeTaxNumber = RandomStringUtils.randomNumeric(14);; -    final AuthenticationResponse response = buildDummyAuthResponseRandomPersonIT_Tax(fakeTaxNumber); +  @Test +  @DirtiesContext +  public void testNode104_ManualFixNecessary_IT() throws Exception { +    String randomTaxNumber = RandomStringUtils.randomNumeric(14); +    final AuthenticationResponse response = buildDummyAuthResponseRandomPersonIT_Tax(randomTaxNumber);      TestRequestImpl pendingReq1 = new TestRequestImpl();      pendingReq1.getSessionData(AuthProcessDataWrapper.class)          .setGenericDataToSession(Constants.DATA_FULL_EIDAS_RESPONSE, response); - -    //Mock ZMR initial search -    ArrayList<RegisterResult> zmrResultInitial = new ArrayList<>(); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResultInitial); +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList());      ArrayList<RegisterResult> zmrResultSpecific = new ArrayList<>(); - -    zmrResultSpecific.add(new RegisterResult("bpkMax", "it/st/"+randomIdentifier+"4", randomGivenName, randomFamilyName, "2011-01-01", null, null, -        fakeTaxNumber, null)); -    zmrResultSpecific.add(new RegisterResult("bpkMax1", "it/st/"+randomIdentifier+"5", randomGivenName, randomFamilyName, "2011-01-01", null, null, -        fakeTaxNumber, null)); -    Mockito.when(zmrClient.searchItSpecific(fakeTaxNumber)).thenReturn(zmrResultSpecific); - -    //Mock ernb initial search -    ArrayList<RegisterResult> ernbResultInitial = new ArrayList<>(); -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResultInitial); - -    //Mock country specific search -    List<ICountrySpecificDetailSearchProcessor> handlers = new ArrayList<>(); -    ItSpecificDetailSearchProcessor it = new ItSpecificDetailSearchProcessor(ernbClient, zmrClient); -    handlers.add(it); -    task = new InitialSearchTask(handlers, ernbClient, zmrClient); - -    try { -      task.execute(pendingReq1, executionContext); - -      Assert.assertTrue("Wrong workflow, should not reach this point/ get a bpk", false); - -    } catch (final TaskExecutionException e) { -      Throwable origE = e.getOriginalException(); -      Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException)); -    } +    String randomPseudonym = IT_ST + randomIdentifier + "4"; +    zmrResultSpecific.add(new RegisterResult(randomBpk, randomPseudonym, randomGivenName, +        randomFamilyName, randomDate, null, null, randomTaxNumber, null)); +    String newRandomPseudonym = IT_ST + randomIdentifier + "5"; +    String newRandomBpk = RandomStringUtils.randomNumeric(6); +    zmrResultSpecific.add(new RegisterResult(newRandomBpk, newRandomPseudonym, randomGivenName, +        randomFamilyName, randomDate, null, null, randomTaxNumber, null)); +    Mockito.when(zmrClient.searchItSpecific(randomTaxNumber)).thenReturn(zmrResultSpecific); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    task = new InitialSearchTask( +        Collections.singletonList(new ItSpecificDetailSearchProcessor(ernpClient, zmrClient)), +        ernpClient, zmrClient); + +    TaskExecutionException exception = assertThrows(TaskExecutionException.class, +        () -> task.execute(pendingReq1, executionContext)); + +    Throwable origE = exception.getOriginalException(); +    Assert.assertTrue("Wrong exception", (origE.getCause() instanceof ManualFixNecessaryException));    } -  @Test -  @DirtiesContext    /** -   * NO match found in ZMR and ErnB with Initial search +   * NO match found in ZMR and ErnP with Initial search     */ -  public void testNode105() { +  @Test +  @DirtiesContext +  public void testNode105_TemporaryEnd() throws TaskExecutionException { +    Mockito.when(zmrClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); +    Mockito.when(ernpClient.searchWithPersonIdentifier(randomIdentifier)).thenReturn(Collections.emptyList()); -    //Mock ZMR -    ArrayList<RegisterResult> zmrResult = new ArrayList<>(); -    zmrClient = Mockito.mock(IZmrClient.class); -    Mockito.when(zmrClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(zmrResult); - -    //Mock ernb -    ArrayList<RegisterResult> ernbResult = new ArrayList<>(); -    ernbClient = Mockito.mock(IErnbClient.class); -    Mockito.when(ernbClient.searchWithPersonIdentifer(randomIdentifier)).thenReturn(ernbResult); - -    task = new InitialSearchTask(emptyHandlers(), ernbClient, zmrClient); -    try { -      task.execute(pendingReq, executionContext); - -      String bPk = (String) -          pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); -      Assert.assertTrue("Wrong bpk", bPk.equals("TODO-Temporary-Endnode-105")); -    } catch (final TaskExecutionException e) { -      Assert.assertTrue("Wrong workflow, should not reach this point", false); -    } +    task.execute(pendingReq, executionContext); + +    String bPk = (String) +        pendingReq.getSessionData(AuthProcessDataWrapper.class) +            .getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); +    Assert.assertEquals("Wrong bpk", "TODO-Temporary-Endnode-105", bPk);    }    @NotNull    private AuthenticationResponse buildDummyAuthResponseRandomPerson() throws URISyntaxException { -    // NOTE: Those strings "de/st/max123" seem to be somehow relevant, but where do we need to use that exact string -    // again? -    // NOTE: If not, why not using random strings? -    return buildDummyAuthResponse(randomGivenName, randomFamilyName, -        "de/st/"+randomIdentifier, "2011-01-01"); +    return buildDummyAuthResponse(randomGivenName, randomFamilyName, DE_ST + randomIdentifier, randomDate);    } -  private AuthenticationResponse buildDummyAuthResponseRandomPersonIT_Tax(String taxNumber) throws URISyntaxException { -    return buildDummyAuthResponse(randomGivenName, randomFamilyName, -        "it/st/"+randomIdentifier, "2011-01-01", taxNumber, null, null); +  private AuthenticationResponse buildDummyAuthResponseRandomPersonIT_Tax(String taxNumber) +      throws URISyntaxException { +    return buildDummyAuthResponse(randomGivenName, randomFamilyName, IT_ST + randomIdentifier, randomDate, +        taxNumber, null, null);    }    @NotNull @@ -555,59 +415,46 @@ public class InitialSearchTaskFirstTest {    private AuthenticationResponse buildDummyAuthResponse(String givenName, String familyName, String identifier,                                                          String dateOfBirth, String taxNumber, String placeOfBirth,                                                          String birthName) throws URISyntaxException { -    final AttributeDefinition attributeDef = AttributeDefinition.builder() -        .friendlyName(Constants.eIDAS_ATTR_PERSONALIDENTIFIER).nameUri(new URI("ad", "sd", "ff")) -        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "af")) -        .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); -    final AttributeDefinition attributeDef2 = AttributeDefinition.builder() -        .friendlyName(Constants.eIDAS_ATTR_CURRENTFAMILYNAME).nameUri(new URI("ad", "sd", "fff")) -        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "aff")) -        .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); -    final AttributeDefinition attributeDef3 = AttributeDefinition.builder() -        .friendlyName(Constants.eIDAS_ATTR_CURRENTGIVENNAME).nameUri(new URI("ad", "sd", "ffff")) -        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "afff")) -        .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); -    final AttributeDefinition attributeDef4 = AttributeDefinition.builder() -        .friendlyName(Constants.eIDAS_ATTR_DATEOFBIRTH).nameUri(new URI("ad", "sd", "fffff")) -        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "affff")) -        .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.DateTimeAttributeValueMarshaller").build(); -    final AttributeDefinition attributeDef5 = AttributeDefinition.builder() -        .friendlyName(Constants.eIDAS_ATTR_TAXREFERENCE).nameUri(new URI("ad", "sd", "ffffff")) -        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "afffff")) -        .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); -    final AttributeDefinition attributeDef6 = AttributeDefinition.builder() -        .friendlyName(Constants.eIDAS_ATTR_PLACEOFBIRTH).nameUri(new URI("ad", "sd", "fffffff")) -        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "affffff")) -        .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build(); -    final AttributeDefinition attributeDef7 = AttributeDefinition.builder() -        .friendlyName(Constants.eIDAS_ATTR_BIRTHNAME).nameUri(new URI("ad", "sd", "ffffffff")) -        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", "afffffff")) -        .attributeValueMarshaller("eu.eidas.auth.commons.attribute.impl.LiteralStringAttributeValueMarshaller").build();      ImmutableAttributeMap.Builder builder = ImmutableAttributeMap.builder() -        .put(attributeDef, identifier) -        .put(attributeDef2, familyName) -        .put(attributeDef3, givenName) -        .put(attributeDef4, dateOfBirth); - +        .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);      if (taxNumber != null) { -      builder.put(attributeDef5, taxNumber); +      builder.put(generateStringAttribute(Constants.eIDAS_ATTR_TAXREFERENCE, "ffffff", "afffff"), taxNumber);      }      if (birthName != null) { -      builder.put(attributeDef7, birthName); +      builder.put(generateStringAttribute(Constants.eIDAS_ATTR_BIRTHNAME, "fffffff", "affffff"), birthName);      }      if (placeOfBirth != null) { -      builder.put(attributeDef6, placeOfBirth); +      builder.put(generateStringAttribute(Constants.eIDAS_ATTR_PLACEOFBIRTH, "ffffffff", "afffffff"), +          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(); +        "afaf").attributes(attributeMap).build(); +  } + +  private AttributeDefinition<Object> generateStringAttribute(String friendlyName, String fragment, String prefix) +      throws URISyntaxException { +    return generateAttribute(friendlyName, fragment, prefix, "eu.eidas.auth.commons.attribute.impl" + +        ".LiteralStringAttributeValueMarshaller"); +  } + +  private AttributeDefinition<Object> generateDateTimeAttribute(String friendlyName, String fragment, String prefix) +      throws URISyntaxException { +    return generateAttribute(friendlyName, fragment, prefix, "eu.eidas.auth.commons.attribute.impl" + +        ".DateTimeAttributeValueMarshaller");    } -  private List<ICountrySpecificDetailSearchProcessor> emptyHandlers() { -    return new ArrayList<>(); +  private AttributeDefinition<Object> generateAttribute(String friendlyName, String fragment, String prefix, +                                                        String marshaller) throws URISyntaxException { +    return AttributeDefinition.builder() +        .friendlyName(friendlyName).nameUri(new URI("ad", "sd", fragment)) +        .personType(PersonType.LEGAL_PERSON).xmlType(new QName("http://saf", "as", prefix)) +        .attributeValueMarshaller(marshaller).build();    }  } diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml index 7d7f2c59..e362fd22 100644 --- a/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml +++ b/eidas_modules/authmodule-eIDAS-v2/src/test/resources/SpringTest-context_tasks_test.xml @@ -66,7 +66,7 @@          scope="prototype" />    <bean id="ErnbClientForeIDAS" -        class="at.asitplus.eidas.specific.modules.auth.eidas.v2.ernb.DummyErnbClient" /> +        class="at.asitplus.eidas.specific.modules.auth.eidas.v2.ernp.DummyErnpClient" />    <bean id="ZmrClientForeIDAS"          class="at.asitplus.eidas.specific.modules.auth.eidas.v2.zmr.DummyZmrClient" /> | 
