diff options
Diffstat (limited to 'eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/SamlVerificationEngineWithHsmFacadeTest.java')
-rw-r--r-- | eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/SamlVerificationEngineWithHsmFacadeTest.java | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/SamlVerificationEngineWithHsmFacadeTest.java b/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/SamlVerificationEngineWithHsmFacadeTest.java index 926f25b2..1511eb73 100644 --- a/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/SamlVerificationEngineWithHsmFacadeTest.java +++ b/eaaf_modules/eaaf_module_pvp2_core/src/test/java/at/gv/egiz/eaaf/modules/pvp2/test/SamlVerificationEngineWithHsmFacadeTest.java @@ -1,7 +1,13 @@ package at.gv.egiz.eaaf.modules.pvp2.test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.opensaml.core.xml.io.UnmarshallingException; +import org.opensaml.saml.saml2.core.Response; import org.opensaml.xmlsec.signature.support.SignatureConstants; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext.ClassMode; @@ -10,7 +16,12 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import at.gv.egiz.eaaf.modules.pvp2.api.credential.EaafX509Credential; +import at.gv.egiz.eaaf.modules.pvp2.exception.CredentialsNotAvailableException; +import at.gv.egiz.eaaf.modules.pvp2.exception.Pvp2MetadataException; +import at.gv.egiz.eaaf.modules.pvp2.exception.SamlAssertionValidationExeption; import at.gv.egiz.eaaf.modules.pvp2.exception.SamlSigningException; +import lombok.SneakyThrows; +import net.shibboleth.utilities.java.support.xml.XMLParserException; //@IfProfileValue(name = "spring.profiles.active", value = "devEnvironment") @RunWith(SpringJUnit4ClassRunner.class) @@ -35,7 +46,6 @@ public class SamlVerificationEngineWithHsmFacadeTest extends AbstractSamlVerific @Override protected String getAuthnRequestWithoutSigPath() { return "/data/AuthRequest_without_sig_1.xml"; - } @Override @@ -69,6 +79,60 @@ public class SamlVerificationEngineWithHsmFacadeTest extends AbstractSamlVerific } } + + @Test + public void assertionDecryptionWithWrongEcKey() throws SamlSigningException, Pvp2MetadataException, + CredentialsNotAvailableException, XMLParserException, UnmarshallingException, SamlAssertionValidationExeption { + final String responsePath = "/data/response_decrypt_test.xml"; + final String spEntityId = "https://vidp.gv.at/EidasNode/ColleagueResponse"; + + final Response inputMsg = + initializeResponseSimple(spEntityId, responsePath, + credentialProvider.getMetaDataSigningCredential()); + + SamlAssertionValidationExeption error = assertThrows("wrong exception", SamlAssertionValidationExeption.class, + () -> verifyEngine.validateAssertion(inputMsg, credentialProvider.getMessageSigningCredential(), + spEntityId, "jUnit Test", false)); + assertEquals("wrong errorCode", "internal.pvp.16", error.getErrorId()); + + } + + @Test + public void assertionDecryptionWithWrongRsaKey() throws SamlSigningException, Pvp2MetadataException, + CredentialsNotAvailableException, XMLParserException, UnmarshallingException, SamlAssertionValidationExeption { + final String responsePath = "/data/response_decrypt_test.xml"; + final String spEntityId = "https://vidp.gv.at/EidasNode/ColleagueResponse"; + + final Response inputMsg = + initializeResponseSimple(spEntityId, responsePath, + credentialProvider.getMetaDataSigningCredential()); + SamlAssertionValidationExeption error = assertThrows("wrong exception", SamlAssertionValidationExeption.class, + () -> verifyEngine.validateAssertion(inputMsg, credentialProvider.getMetaDataSigningCredential(), + spEntityId, "jUnit Test", false)); + assertEquals("wrong errorCode", "internal.pvp.16", error.getErrorId()); + } + + @Test + @SneakyThrows + public void assertionEncryptionDecryptionRsa() throws SamlSigningException, Pvp2MetadataException, + CredentialsNotAvailableException, XMLParserException, UnmarshallingException, SamlAssertionValidationExeption { + performEncryptionDecrytion(credentialProvider.getMessageEncryptionCredential()); + + } + + + /* + * ECC keys currently not support for encryption. + */ + @Test + @Ignore + @SneakyThrows + public void assertionEncryptionDecryptionEcc() throws SamlSigningException, Pvp2MetadataException, + CredentialsNotAvailableException, XMLParserException, UnmarshallingException, SamlAssertionValidationExeption { + performEncryptionDecrytion(credentialProvider.getMessageSigningCredential()); + + } + } |