From 41a2c873d585d00ee06cc95a5e30fe17f4bc85a9 Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Tue, 15 Dec 2020 23:07:53 +0100 Subject: added machting (3-4) + tests --- .../v2/test/tasks/InitialSearchTaskFirstTest.java | 140 ++++++++++++++++++++- 1 file changed, 136 insertions(+), 4 deletions(-) (limited to 'eidas_modules/authmodule-eIDAS-v2/src/test/java') 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 1b1bdeae..2614f9ba 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 @@ -111,8 +111,8 @@ public class InitialSearchTaskFirstTest { //Mock ZMR ArrayList zmrResult = new ArrayList<>(); - zmrResult.add(new RegisterResult("de/st/max123", "Max", "Mustermann", "1111-01-01")); - zmrResult.add(new RegisterResult("de/st/max123", "Maximilian", "Mustermann", "1111-01-01")); + zmrResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "1111-01-01")); + zmrResult.add(new RegisterResult("bpkMax","de/st/max123", "Maximilian", "Mustermann", "1111-01-01")); zmrClient = Mockito.mock(DummyZmrClient.class); Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"??? task.setZmrClient(zmrClient); @@ -151,8 +151,8 @@ public class InitialSearchTaskFirstTest { //Mock ernb ArrayList ernbResult = new ArrayList<>(); - ernbResult.add(new RegisterResult("de/st/max123", "Max", "Mustermann", "1111-01-01")); - ernbResult.add(new RegisterResult("de/st/max123", "Maximilian", "Mustermann", "1111-01-01")); + ernbResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "1111-01-01")); + ernbResult.add(new RegisterResult("bpkMax","de/st/max123", "Maximilian", "Mustermann", "1111-01-01")); ernbClient = Mockito.mock(DummyErnbClient.class); Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"??? @@ -170,6 +170,138 @@ public class InitialSearchTaskFirstTest { } } + @Test + @DirtiesContext + /** + * One match, but register update needed + */ + public void testNode100a() throws Exception { + + //Mock ZMR + ArrayList zmrResult = new ArrayList<>(); + String randomBpk = RandomStringUtils.randomNumeric(6); + zmrResult.add(new RegisterResult(randomBpk,"de/st/max123", "Max_new", "Mustermann", "1111-01-01")); + + zmrClient = Mockito.mock(DummyZmrClient.class); + Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"??? + task.setZmrClient(zmrClient); + + //Mock ernb + ArrayList ernbResult = new ArrayList<>(); + + ernbClient = Mockito.mock(DummyErnbClient.class); + Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"??? + task.setErnbClient(ernbClient); + + 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 + /** + * One match, but register update needed + */ + public void testNode100b() throws Exception { + + //Mock ZMR + ArrayList zmrResult = new ArrayList<>(); + + zmrClient = Mockito.mock(DummyZmrClient.class); + Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"??? + task.setZmrClient(zmrClient); + + //Mock ernb + ArrayList ernbResult = new ArrayList<>(); + String randomBpk = RandomStringUtils.randomNumeric(6); + ernbResult.add(new RegisterResult(randomBpk,"de/st/max123", "Max_new", "Mustermann", "1111-01-01")); + + ernbClient = Mockito.mock(DummyErnbClient.class); + Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"??? + task.setErnbClient(ernbClient); + + 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 + /** + * One match, no register update needed + */ + public void testNode102a() throws Exception { + + //Mock ZMR + ArrayList zmrResult = new ArrayList<>(); + zmrClient = Mockito.mock(DummyZmrClient.class); + Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"??? + task.setZmrClient(zmrClient); + + //Mock ernb + ArrayList ernbResult = new ArrayList<>(); + ernbResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "1111-01-01")); + + ernbClient = Mockito.mock(DummyErnbClient.class); + Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"??? + task.setErnbClient(ernbClient); + + try { + task.execute(pendingReq, executionContext); + String bPk = (String) + pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + Assert.assertTrue("Wrong bpk", bPk.equals("bpkMax")); + + } catch (final TaskExecutionException e) { + Assert.assertTrue("Wrong workflow, should not reach this point", false); + } + } + + @Test + @DirtiesContext + /** + * One match, no register update needed + */ + public void testNode102b() throws Exception { + + //Mock ZMR + ArrayList zmrResult = new ArrayList<>(); + zmrResult.add(new RegisterResult("bpkMax","de/st/max123", "Max", "Mustermann", "1111-01-01")); + + zmrClient = Mockito.mock(DummyZmrClient.class); + Mockito.when(zmrClient.searchWithPersonIdentifer("max123")).thenReturn(zmrResult);//"de/st/max123"??? + task.setZmrClient(zmrClient); + + //Mock ernb + ArrayList ernbResult = new ArrayList<>(); + + ernbClient = Mockito.mock(DummyErnbClient.class); + Mockito.when(ernbClient.searchWithPersonIdentifer("max123")).thenReturn(ernbResult);//"de/st/max123"??? + task.setErnbClient(ernbClient); + + try { + task.execute(pendingReq, executionContext); + String bPk = (String) + pendingReq.getSessionData(AuthProcessDataWrapper.class).getGenericDataFromSession(Constants.DATA_RESULT_MATCHING_BPK); + Assert.assertTrue("Wrong bpk", bPk.equals("bpkMax")); + + } catch (final TaskExecutionException e) { + Assert.assertTrue("Wrong workflow, should not reach this point", false); + } + } @NotNull private AuthenticationResponse buildDummyAuthResponse() throws URISyntaxException { -- cgit v1.2.3