aboutsummaryrefslogtreecommitdiff
path: root/eidas_modules
diff options
context:
space:
mode:
authorlalber <lukas.alber@iaik.tugraz.at>2020-11-05 12:18:26 +0100
committerlalber <lukas.alber@iaik.tugraz.at>2020-11-05 12:18:26 +0100
commitd40505ed35a8db7d242a8b218297e322350722b3 (patch)
tree53208c7e3ba00781edfbb08d5b27737800eefc88 /eidas_modules
parent3e422c60952d5892a0e568de8c28ce878610eb2f (diff)
downloadNational_eIDAS_Gateway-d40505ed35a8db7d242a8b218297e322350722b3.tar.gz
National_eIDAS_Gateway-d40505ed35a8db7d242a8b218297e322350722b3.tar.bz2
National_eIDAS_Gateway-d40505ed35a8db7d242a8b218297e322350722b3.zip
Test fixes
Diffstat (limited to 'eidas_modules')
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/szr/SzrClient.java6
-rw-r--r--eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java139
2 files changed, 87 insertions, 58 deletions
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/szr/SzrClient.java b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/szr/SzrClient.java
index d2ce2f5d..69b993a4 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/szr/SzrClient.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/main/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/szr/SzrClient.java
@@ -234,7 +234,7 @@ public class SzrClient {
throw new SzrCommunicationException("ernb.02", new Object[]{e.getMessage()}, e);
}
- if (resp == null || StringUtils.isEmpty(resp)) {
+ if (StringUtils.isEmpty(resp)) {
throw new SzrCommunicationException("ernb.01", new Object[]{"Stammzahl response empty"}); // TODO error handling
}
@@ -277,9 +277,9 @@ public class SzrClient {
final SignContentResponseType resp = szr.signContent(req.isAppendCert(), req.getJWSHeaderParam(), req.getIn());
log.trace("Receive SZR response on bcBind siging operation ");
- if (resp == null
+ if (resp == null || resp.getOut() == null
|| resp.getOut().isEmpty()
- || resp.getOut().get(0).getValue() == null) {
+ || StringUtils.isEmpty(resp.getOut().get(0).getValue())) {
throw new SzrCommunicationException("ernb.01", new Object[]{"BcBind response empty"});
}
diff --git a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java
index d6bce8eb..9709aeb9 100644
--- a/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java
+++ b/eidas_modules/authmodule-eIDAS-v2/src/test/java/at/asitplus/eidas/specific/modules/auth/eidas/v2/test/SzrClientTest.java
@@ -105,10 +105,10 @@ public class SzrClientTest {
private SZR szrMock = null;
-
+
@Rule
public SoapServiceRule soap = SoapServiceRule.newInstance();
-
+
/**
* jUnit class initializer.
*
@@ -123,28 +123,38 @@ public class SzrClientTest {
/**
* Initialize jUnit test.
- *
*/
@Before
public void initializer() {
if (szrMock == null) {
szrMock = soap.mock(SZR.class, "http://localhost:1234/demoszr");
-
- }
+
+ }
}
-
-
+
+
@Test
- public void getStammzahlenEcryptedTest() throws JAXBException, SZRException_Exception {
+ public void getStammzahlenEcryptedTest() throws JAXBException, SZRException_Exception, SzrCommunicationException {
final GetBPKFromStammzahlEncryptedResponse szrResponse = new GetBPKFromStammzahlEncryptedResponse();
final GetBPKFromStammzahlEncryptedResponseType result1 = new GetBPKFromStammzahlEncryptedResponseType();
szrResponse.getOut().add(result1);
- when(szrMock.getBPKFromStammzahlEncrypted(anyList()))
- .thenReturn(Arrays.asList(result1));
+ result1.setKey(RandomStringUtils.randomAlphanumeric(20));
+
+ // when(szrMock.getBPKFromStammzahlEncrypted(anyList()))
+ // .thenReturn(Arrays.asList(result1));
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(result1.getKey());
- String stammzahlEncrypted = szrMock.getStammzahlEncrypted(new PersonInfoType(), false);
+ String stammzahlEncrypted = szrClient.getEncryptedStammzahl(new PersonInfoType());
+ Assert.assertEquals("bcBind not match", result1.getKey(), stammzahlEncrypted);
+
+ when(szrMock.getStammzahlEncrypted(any(), any())).thenReturn(null);
+ try {
+ stammzahlEncrypted = szrClient.getEncryptedStammzahl(new PersonInfoType());
+ } catch (SzrCommunicationException e) {
+ Assert.assertTrue("Not correct error", e.getMessage().contains("ernb.01"));
+ }
}
@Test
@@ -160,32 +170,61 @@ public class SzrClientTest {
when(szrMock.signContent(any(), anyList(), anyList())).thenReturn(content);
- final String bcBind = szrClient.getBcBind(
- RandomStringUtils.randomAlphabetic(10),
- RandomStringUtils.randomAlphabetic(10),
- RandomStringUtils.randomAlphabetic(10));
+ final String bcBind = szrClient
+ .getBcBind(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAlphabetic(10),
+ RandomStringUtils.randomAlphabetic(10));
Assert.assertNotNull("bcBind is null", bcBind);
Assert.assertEquals("bcBind not match", result1.getValue(), bcBind);
+ when(szrMock.signContent(any(), anyList(), anyList())).thenReturn(null);
+ try {
+ szrClient
+ .getBcBind(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAlphabetic(10),
+ RandomStringUtils.randomAlphabetic(10));
+ } catch (SzrCommunicationException e) {
+ Assert.assertTrue("Not correct error", e.getMessage().contains("ernb.01"));
+ }
+
+ final SignContentEntry result2 = new SignContentEntry();
+ final SignContentResponseType content1 = new SignContentResponseType();
+ content1.getOut().add(result2);
+ when(szrMock.signContent(any(), anyList(), anyList())).thenReturn(content1);
+ try {
+ szrClient
+ .getBcBind(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAlphabetic(10),
+ RandomStringUtils.randomAlphabetic(10));
+ } catch (SzrCommunicationException e) {
+ Assert.assertTrue("Not correct error", e.getMessage().contains("ernb.01"));
+ }
+
+ result2.setKey("bcBindReq");
+ result2.setValue("");
+ when(szrMock.signContent(any(), anyList(), anyList())).thenReturn(content1);
+ try {
+ szrClient
+ .getBcBind(RandomStringUtils.randomAlphabetic(10), RandomStringUtils.randomAlphabetic(10),
+ RandomStringUtils.randomAlphabetic(10));
+ } catch (SzrCommunicationException e) {
+ Assert.assertTrue("Not correct error", e.getMessage().contains("ernb.01"));
+ }
}
@Test
- public void getIdentityLinkRawModeValidResponse() throws SZRException_Exception, EaafParserException,
- NoSuchProviderException, IOException, InvalidKeyException, EidasSAuthenticationException,
- JAXBException {
+ public void getIdentityLinkRawModeValidResponse()
+ throws SZRException_Exception, EaafParserException, NoSuchProviderException, IOException, InvalidKeyException,
+ EidasSAuthenticationException, JAXBException {
setSzrResponseIdentityLink("/data/szr/szr_resp_valid_1.xml");
try {
log.debug("Starting connecting SZR Gateway");
- final IdentityLinkType result = szrClient.getIdentityLinkInRawMode(
- getPersonInfo());
+ final IdentityLinkType result = szrClient.getIdentityLinkInRawMode(getPersonInfo());
Assert.assertNotNull(result);
Assert.assertNotNull(result.getAssertion());
- final IIdentityLink identityLink = new SimpleIdentityLinkAssertionParser((Element) result
- .getAssertion()).parseIdentityLink();
+ final IIdentityLink identityLink = new SimpleIdentityLinkAssertionParser((Element) result.getAssertion())
+ .parseIdentityLink();
Assert.assertNotNull(identityLink);
System.out.println(identityLink.getSerializedSamlAssertion());
@@ -206,15 +245,14 @@ public class SzrClientTest {
}
@Test
- public void getIdentityLinkRawModeErrorTravelerDocExists() throws SZRException_Exception,
- EaafParserException, NoSuchProviderException, IOException, InvalidKeyException,
+ public void getIdentityLinkRawModeErrorTravelerDocExists()
+ throws SZRException_Exception, EaafParserException, NoSuchProviderException, IOException, InvalidKeyException,
EidasSAuthenticationException, JAXBException, ParserConfigurationException, SAXException {
setSzrExceptionIdentityLink("/data/szr/szr_resp_error_travelerdocexists.xml");
try {
log.debug("Starting connecting SZR Gateway");
- szrClient.getIdentityLinkInRawMode(
- getPersonInfo());
+ szrClient.getIdentityLinkInRawMode(getPersonInfo());
Assert.fail();
} catch (final SzrCommunicationException e) {
@@ -224,8 +262,7 @@ public class SzrClientTest {
Assert.assertNotNull(((SOAPFaultException) e.getCause()).getFault());
checkElement("p344:F455", ((SOAPFaultException) e.getCause()).getFault().getFaultCode());
checkElement(
- "The travel document you sent to insert a person already exists for another person. "
- + "Either check the document or have the person altered accordingly",
+ "The travel document you sent to insert a person already exists for another person. " + "Either check the document or have the person altered accordingly",
((SOAPFaultException) e.getCause()).getFault().getFaultString());
}
@@ -235,17 +272,15 @@ public class SzrClientTest {
@Ignore
@Test
public void getBpkTest() throws SZRException_Exception, EidasSAuthenticationException {
- final List<String> bPK = szrClient.getBpk(getPersonInfo(), DUMMY_TARGET,
- basicConfig.getBasicConfiguration(
- Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_VKZ,
- "no VKZ defined"));
+ final List<String> bPK = szrClient.getBpk(getPersonInfo(), DUMMY_TARGET, basicConfig
+ .getBasicConfiguration(Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_VKZ, "no VKZ defined"));
if (bPK.isEmpty()) {
- throw new SzrCommunicationException("ernb.01", new Object[] { "bPK list is empty" });
+ throw new SzrCommunicationException("ernb.01", new Object[]{"bPK list is empty"});
}
for (final String b : bPK) {
if (StringUtils.isEmpty(b)) {
- throw new SzrCommunicationException("ernb.01", new Object[] { "bPK is null or empty" });
+ throw new SzrCommunicationException("ernb.01", new Object[]{"bPK is null or empty"});
}
}
@@ -257,29 +292,24 @@ public class SzrClientTest {
}
- private void setSzrResponseIdentityLink(String responseXmlPath) throws JAXBException,
- SZRException_Exception {
- final JAXBContext jaxbContext = JAXBContext.newInstance(
- szrservices.ObjectFactory.class,
- org.w3._2001._04.xmldsig_more.ObjectFactory.class,
- org.w3._2000._09.xmldsig.ObjectFactory.class,
- at.gv.e_government.reference.namespace.persondata._20020228.ObjectFactory.class);
+ private void setSzrResponseIdentityLink(String responseXmlPath) throws JAXBException, SZRException_Exception {
+ final JAXBContext jaxbContext = JAXBContext
+ .newInstance(szrservices.ObjectFactory.class, org.w3._2001._04.xmldsig_more.ObjectFactory.class,
+ org.w3._2000._09.xmldsig.ObjectFactory.class,
+ at.gv.e_government.reference.namespace.persondata._20020228.ObjectFactory.class);
final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
final GetIdentityLinkEidasResponse szrResponse = (GetIdentityLinkEidasResponse) jaxbUnmarshaller
.unmarshal(this.getClass().getResourceAsStream(responseXmlPath));
- when(szrMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenReturn(szrResponse
- .getGetIdentityLinkReturn());
+ when(szrMock.getIdentityLinkEidas(any(PersonInfoType.class))).thenReturn(szrResponse.getGetIdentityLinkReturn());
}
- private void setSzrExceptionIdentityLink(String responseXmlPath) throws JAXBException,
- ParserConfigurationException, SAXException, IOException, SZRException_Exception {
- final Element detailerror = DomUtils.parseXmlNonValidating(this.getClass().getResourceAsStream(
- responseXmlPath));
+ private void setSzrExceptionIdentityLink(String responseXmlPath)
+ throws JAXBException, ParserConfigurationException, SAXException, IOException, SZRException_Exception {
+ final Element detailerror = DomUtils.parseXmlNonValidating(this.getClass().getResourceAsStream(responseXmlPath));
final javax.xml.namespace.QName qName = new javax.xml.namespace.QName("urn:SZRServices", "F455", "p344");
final SoapFault fault = new SoapFault(
- "The travel document you sent to insert a person already exists for another person. "
- + "Either check the document or have the person altered accordingly",
+ "The travel document you sent to insert a person already exists for another person. " + "Either check the document or have the person altered accordingly",
qName);
fault.setRole("urn:SZRServices");
fault.setDetail(detailerror);
@@ -295,7 +325,7 @@ public class SzrClientTest {
return hashBase64;
} catch (final Exception ex) {
- throw new EidasSAuthenticationException("internal.03", new Object[] {}, ex);
+ throw new EidasSAuthenticationException("internal.03", new Object[]{}, ex);
}
}
@@ -311,8 +341,7 @@ public class SzrClientTest {
personInfo.setTravelDocument(eDocument);
// parse some eID attributes
- final Triple<String, String, String> eIdentifier =
- EidasResponseUtils.parseEidasPersonalIdentifier(eIDASeID);
+ final Triple<String, String, String> eIdentifier = EidasResponseUtils.parseEidasPersonalIdentifier(eIDASeID);
final String uniqueId = createHashFromUniqueId(eIdentifier.getThird());
final String citizenCountry = eIdentifier.getFirst();
@@ -324,9 +353,9 @@ public class SzrClientTest {
eDocument.setDocumentNumber(uniqueId);
// eID document information
- eDocument.setDocumentType(basicConfig.getBasicConfiguration(
- Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_EDOCUMENTTYPE,
- Constants.SZR_CONSTANTS_DEFAULT_DOCUMENT_TYPE));
+ eDocument.setDocumentType(basicConfig
+ .getBasicConfiguration(Constants.CONIG_PROPS_EIDAS_SZRCLIENT_PARAMS_EDOCUMENTTYPE,
+ Constants.SZR_CONSTANTS_DEFAULT_DOCUMENT_TYPE));
return personInfo;
}