aboutsummaryrefslogtreecommitdiff
path: root/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java')
-rw-r--r--modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java131
1 files changed, 64 insertions, 67 deletions
diff --git a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java
index 0d9d4fb8..4d4ac47d 100644
--- a/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java
+++ b/modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/EidasSignalServletTest.java
@@ -14,7 +14,6 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.PrepareForTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
@@ -47,12 +46,10 @@ import eu.eidas.auth.commons.tx.BinaryLightToken;
import eu.eidas.specificcommunication.exception.SpecificCommunicationException;
@RunWith(SpringJUnit4ClassRunner.class)
-@PrepareForTest(CreateIdentityLinkTask.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
@ContextConfiguration(locations = {
"/SpringTest-context_tasks_test.xml",
"/SpringTest-context_basic_mapConfig.xml"})
-@EnableWebMvc
public class EidasSignalServletTest {
@Autowired private MsConnectorDummyConfigMap basicConfig;
@@ -61,14 +58,14 @@ public class EidasSignalServletTest {
@Autowired private ITransactionStorage transStore;
@Autowired private DummyProtocolAuthService protAuthService;
@Autowired private DummySpecificCommunicationService connector;
-
-
+
+
private MockHttpServletRequest httpReq;
private MockHttpServletResponse httpResp;
private TestRequestImpl pendingReq;
private MsConnectorDummySpConfiguration oaParam;
-
-
+
+
/**
* jUnit test set-up.
*/
@@ -78,7 +75,7 @@ public class EidasSignalServletTest {
httpResp = new MockHttpServletResponse();
RequestContextHolder.resetRequestAttributes();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(httpReq, httpResp));
-
+
final Map<String, String> spConfig = new HashMap<>();
spConfig.put(EaafConfigConstants.SERVICE_UNIQUEIDENTIFIER, "testSp");
spConfig.put("target", "urn:publicid:gv.at:cdid+XX");
@@ -92,51 +89,51 @@ public class EidasSignalServletTest {
pendingReq.setAuthUrl("http://test.com/");
pendingReq.setTransactionId("avaasbav");
pendingReq.setPiiTransactionId(RandomStringUtils.randomAlphanumeric(10));
-
+
connector.setiLightResponse(null);
-
-
+
+
}
-
+
@Test
public void noResponsToken() throws IOException, EaafException {
//set-up
-
+
//execute test
controller.restoreEidasAuthProcess(httpReq, httpResp);
-
+
//validate state
Assert.assertNull("eIDAS response", httpReq.getAttribute(Constants.DATA_FULL_EIDAS_RESPONSE));
Assert.assertNotNull("missing error", protAuthService.getException());
- Assert.assertEquals("Wrong errorId", "auth.26",
+ Assert.assertEquals("Wrong errorId", "auth.26",
((EaafException) protAuthService.getException()).getErrorId());
-
+
}
-
+
@Test
public void unknownResponseToken() throws IOException, EaafException {
//set-up
- httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
+ httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
RandomStringUtils.randomAlphanumeric(10));
-
+
//execute test
controller.restoreEidasAuthProcess(httpReq, httpResp);
-
+
//validate state
Assert.assertNull("eIDAS response", httpReq.getAttribute(Constants.DATA_FULL_EIDAS_RESPONSE));
Assert.assertNotNull("missing error", protAuthService.getException());
- Assert.assertEquals("Wrong errorId", "auth.26",
+ Assert.assertEquals("Wrong errorId", "auth.26",
((EaafException) protAuthService.getException()).getErrorId());
-
+
}
-
+
@Test
public void withRelayState() throws IOException, EaafException, SpecificCommunicationException {
- //set-up
- String relayState = RandomStringUtils.randomAlphanumeric(10);
+ //set-up
+ String relayState = RandomStringUtils.randomAlphanumeric(10);
pendingReq.setPendingReqId(relayState);
storage.storePendingRequest(pendingReq);
-
+
Builder iLightResponse = new AuthenticationResponse.Builder();
iLightResponse.id("_".concat(Random.nextHexRandom16()))
.issuer(RandomStringUtils.randomAlphabetic(10))
@@ -145,37 +142,37 @@ public class EidasSignalServletTest {
.inResponseTo("_".concat(Random.nextHexRandom16()))
.subjectNameIdFormat("afaf")
.relayState(relayState);
-
+
AuthenticationResponse eidasResp = iLightResponse.build();
- BinaryLightToken token = connector.putResponse(eidasResp);
- httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
+ BinaryLightToken token = connector.putResponse(eidasResp);
+ httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
Base64.getEncoder().encodeToString(token.getTokenBytes()));
-
+
//execute test
controller.restoreEidasAuthProcess(httpReq, httpResp);
-
-
+
+
//validate state
Assert.assertNotNull("eIDAS response", httpReq.getAttribute(Constants.DATA_FULL_EIDAS_RESPONSE));
- Assert.assertEquals("wrong eIDAS response", eidasResp,
+ Assert.assertEquals("wrong eIDAS response", eidasResp,
httpReq.getAttribute(Constants.DATA_FULL_EIDAS_RESPONSE));
-
- Assert.assertNotNull("missing error", protAuthService.getException());
- Assert.assertEquals("Wrong errorId", "PendingRequest object is not of type 'RequestImpl.class'",
+
+ Assert.assertNotNull("missing error", protAuthService.getException());
+ Assert.assertEquals("Wrong errorId", "PendingRequest object is not of type 'RequestImpl.class'",
((EaafException) protAuthService.getException()).getErrorId());
-
+
}
-
+
@Test
public void withOutRelayStateMissingPendingReq() throws IOException, EaafException, SpecificCommunicationException {
- //set-up
- String pendingReqId = RandomStringUtils.randomAlphanumeric(10);
+ //set-up
+ String pendingReqId = RandomStringUtils.randomAlphanumeric(10);
pendingReq.setPendingReqId(pendingReqId);
storage.storePendingRequest(pendingReq);
-
+
String inResponseTo = "_".concat(Random.nextHexRandom16());
-
+
Builder iLightResponse = new AuthenticationResponse.Builder();
iLightResponse.id("_".concat(Random.nextHexRandom16()))
.issuer(RandomStringUtils.randomAlphabetic(10))
@@ -183,35 +180,35 @@ public class EidasSignalServletTest {
.statusCode(Constants.SUCCESS_URI)
.inResponseTo(inResponseTo)
.subjectNameIdFormat("afaf");
-
+
AuthenticationResponse eidasResp = iLightResponse.build();
- BinaryLightToken token = connector.putResponse(eidasResp);
- httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
+ BinaryLightToken token = connector.putResponse(eidasResp);
+ httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
Base64.getEncoder().encodeToString(token.getTokenBytes()));
-
+
//execute test
controller.restoreEidasAuthProcess(httpReq, httpResp);
-
-
+
+
//validate state
Assert.assertNull("eIDAS response", httpReq.getAttribute(Constants.DATA_FULL_EIDAS_RESPONSE));
Assert.assertNotNull("missing error", protAuthService.getException());
- Assert.assertEquals("Wrong errorId", "auth.26",
+ Assert.assertEquals("Wrong errorId", "auth.26",
((EaafException) protAuthService.getException()).getErrorId());
-
+
}
-
+
@Test
public void withInResponseToElement() throws IOException, EaafException, SpecificCommunicationException {
- //set-up
- String pendingReqId = RandomStringUtils.randomAlphanumeric(10);
+ //set-up
+ String pendingReqId = RandomStringUtils.randomAlphanumeric(10);
pendingReq.setPendingReqId(pendingReqId);
storage.storePendingRequest(pendingReq);
-
+
String inResponseTo = "_".concat(Random.nextHexRandom16());
transStore.put(inResponseTo, pendingReqId, -1);
-
+
Builder iLightResponse = new AuthenticationResponse.Builder();
iLightResponse.id("_".concat(Random.nextHexRandom16()))
.issuer(RandomStringUtils.randomAlphabetic(10))
@@ -219,26 +216,26 @@ public class EidasSignalServletTest {
.statusCode(Constants.SUCCESS_URI)
.inResponseTo(inResponseTo)
.subjectNameIdFormat("afaf");
-
+
AuthenticationResponse eidasResp = iLightResponse.build();
- BinaryLightToken token = connector.putResponse(eidasResp);
- httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
+ BinaryLightToken token = connector.putResponse(eidasResp);
+ httpReq.setParameter(EidasParameterKeys.TOKEN.toString(),
Base64.getEncoder().encodeToString(token.getTokenBytes()));
-
+
//execute test
controller.restoreEidasAuthProcess(httpReq, httpResp);
-
-
+
+
//validate state
Assert.assertNotNull("eIDAS response", httpReq.getAttribute(Constants.DATA_FULL_EIDAS_RESPONSE));
- Assert.assertEquals("wrong eIDAS response", eidasResp,
+ Assert.assertEquals("wrong eIDAS response", eidasResp,
httpReq.getAttribute(Constants.DATA_FULL_EIDAS_RESPONSE));
-
- Assert.assertNotNull("missing error", protAuthService.getException());
- Assert.assertEquals("Wrong errorId", "PendingRequest object is not of type 'RequestImpl.class'",
+
+ Assert.assertNotNull("missing error", protAuthService.getException());
+ Assert.assertEquals("Wrong errorId", "PendingRequest object is not of type 'RequestImpl.class'",
((EaafException) protAuthService.getException()).getErrorId());
-
+
}
-
+
}