Skip to content

Commit

Permalink
Fixed tests after upgrade open-saml
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Jan 10, 2025
1 parent da85bc8 commit f8acc32
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 374 deletions.
5 changes: 2 additions & 3 deletions src/main/java/saml/DefaultSAMLService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package saml;

import jakarta.servlet.http.HttpServletResponse;
import lombok.SneakyThrows;
import net.shibboleth.shared.xml.impl.BasicParserPool;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.xml.impl.BasicParserPool;
import net.shibboleth.shared.xml.SerializeSupport;
import net.shibboleth.shared.xml.impl.BasicParserPool;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
Expand Down Expand Up @@ -53,7 +53,6 @@
import saml.parser.EncodingUtils;
import saml.parser.OpenSamlVelocityEngine;

import jakarta.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/saml/crypto/X509Utilities.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package saml.crypto;


import jakarta.xml.bind.DatatypeConverter;
import lombok.SneakyThrows;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;

import javax.xml.bind.DatatypeConverter;
import java.io.ByteArrayInputStream;
import java.io.CharArrayReader;
import java.security.KeyPair;
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/saml/parser/OpenSamlVelocityEngine.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package saml.parser;

import org.apache.velocity.app.VelocityEngine;
//import net.shibboleth.utilities.java.support.velocity.VelocityEngine;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.slf4j.helpers.NOPLogger;

import java.io.Writer;
Expand All @@ -12,16 +12,19 @@

public class OpenSamlVelocityEngine {

private static final String templateId = "/templates/saml2-post-binding.vm";
private final org.apache.velocity.app.VelocityEngine velocityEngine;
private static final String templateId = "/templates/saml2-post-binding.vm";
private final VelocityEngine velocityEngine;

public OpenSamlVelocityEngine() {
this.velocityEngine = VelocityEngine.newVelocityEngine();
this.velocityEngine = new VelocityEngine();
velocityEngine.setProperty("resource.loader.string.class", "org.apache.velocity.runtime.resource.loader.StringResourceLoader");
velocityEngine.setProperty("resource.loader.classpath.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
velocityEngine.setProperty("resource.loaders", "classpath, string");
velocityEngine.setProperty("runtime.log.instance", NOPLogger.NOP_LOGGER);
velocityEngine.setProperty("velocimacro.library.autoreload", false);
velocityEngine.setProperty("resource.loader.file.cache", true);
velocityEngine.setProperty("resource.loader.file.modificationCheckInterval", -1);
velocityEngine.init();
this.velocityEngine.init();
}

public void process(Map<String, Object> model, Writer out) {
Expand Down
27 changes: 14 additions & 13 deletions src/test/java/saml/DefaultSAMLServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package saml;

import lombok.SneakyThrows;
import net.shibboleth.utilities.java.support.resolver.CriteriaSet;
import net.shibboleth.utilities.java.support.resolver.ResolverException;
import net.shibboleth.utilities.java.support.xml.SerializeSupport;
import net.shibboleth.shared.resolver.CriteriaSet;
import net.shibboleth.shared.resolver.ResolverException;
import net.shibboleth.shared.xml.SerializeSupport;
import org.apache.commons.io.IOUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
Expand Down Expand Up @@ -33,10 +33,7 @@
import java.security.KeyStore;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -267,7 +264,7 @@ void sendResponseNoAuthnContext() {

StatusCode statusCode = response.getStatus().getStatusCode();
StatusCode innerStatusCode = statusCode.getStatusCode();
assertEquals("urn:oasis:names:tc:SAML:2.0:status:Responder", statusCode.getValue() );
assertEquals("urn:oasis:names:tc:SAML:2.0:status:Responder", statusCode.getValue());
assertEquals(SAMLStatus.NO_AUTHN_CONTEXT.getStatus(), innerStatusCode.getValue());

assertEquals("Not Ok", response.getStatus().getStatusMessage().getValue());
Expand Down Expand Up @@ -334,11 +331,15 @@ void createAuthnRequest() {
*/
@Test
void testSignatureWrappingAttacks() {
File[] files = new File(DefaultSAMLService.class.getClassLoader().getResource("req-wrapping").getPath()).listFiles();
Stream.of(files).forEach(file -> {
String authnRequestXML = readFile("req-wrapping/" + file.getName());
assertThrows(SignatureException.class, () -> defaultSAMLService.parseAuthnRequest(authnRequestXML, false, false));
});
Stream.of(Objects.requireNonNull(new File(Objects.requireNonNull(DefaultSAMLService.class.getClassLoader()
.getResource("req-wrapping")).getPath())
.listFiles()))
.sorted(Comparator.comparing(File::getName))
.forEach(file -> {
String authnRequestXML = readFile("req-wrapping/" + file.getName());
assertThrows(SignatureException.class, () ->
defaultSAMLService.parseAuthnRequest(authnRequestXML, false, false));
});
}

/**
Expand Down
76 changes: 0 additions & 76 deletions src/test/resources/req-wrapping/withSignatureReqACEqualID.xml

This file was deleted.

76 changes: 0 additions & 76 deletions src/test/resources/req-wrapping/withSignatureReqACMissingID.xml

This file was deleted.

Loading

0 comments on commit f8acc32

Please sign in to comment.