SWS-193 - separate unit tests
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package org.springframework.ws.soap.security;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
|
||||
public class SkipValidationWsSecurityInterceptorTest {
|
||||
|
||||
private MessageFactory messageFactory;
|
||||
private AbstractWsSecurityInterceptor interceptor;
|
||||
private SaajSoapMessageFactory soapMessageFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
messageFactory = MessageFactory.newInstance();
|
||||
soapMessageFactory = new SaajSoapMessageFactory(messageFactory);
|
||||
interceptor = new AbstractWsSecurityInterceptor() {
|
||||
|
||||
@Override
|
||||
protected void validateMessage(SoapMessage soapMessage,
|
||||
MessageContext messageContext)
|
||||
throws WsSecurityValidationException {
|
||||
fail("validation must be skipped.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void secureMessage(SoapMessage soapMessage,
|
||||
MessageContext messageContext)
|
||||
throws WsSecuritySecurementException {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cleanUp() {
|
||||
}
|
||||
};
|
||||
interceptor.setSkipValidationIfNoHeaderPresent(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipValidationOnNoHeader() throws Exception {
|
||||
doTestSkipValidation("noHeader-soap.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipValidationOnEmptyHeader() throws Exception {
|
||||
doTestSkipValidation("emptyHeader-soap.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipValidationOnNoSecurityHeader() throws Exception {
|
||||
doTestSkipValidation("noSecurityHeader-soap.xml");
|
||||
}
|
||||
|
||||
|
||||
private void doTestSkipValidation(String fileName) throws Exception {
|
||||
SoapMessage message = loadSaajMessage(fileName);
|
||||
MessageContext messageContext = new DefaultMessageContext(message,
|
||||
soapMessageFactory);
|
||||
assertTrue("handeRequest result must be true", interceptor
|
||||
.handleRequest(messageContext, null));
|
||||
|
||||
}
|
||||
|
||||
private SaajSoapMessage loadSaajMessage(String fileName)
|
||||
throws SOAPException, IOException {
|
||||
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||
mimeHeaders.addHeader("Content-Type", "text/xml");
|
||||
Resource resource = new ClassPathResource(fileName, getClass());
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
assertTrue("Could not load SAAJ message [" + resource + "]",
|
||||
resource.exists());
|
||||
is = resource.getInputStream();
|
||||
return new SaajSoapMessage(messageFactory.createMessage(
|
||||
mimeHeaders, is));
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,15 +82,6 @@ public abstract class Wss4jMessageInterceptorHeaderTestCase extends Wss4jTestCas
|
||||
interceptor.validateMessage(message, messageContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipValidationOnEmptyHeader() throws Exception {
|
||||
SoapMessage message = loadSoap11Message("noSecurityHeader-soap.xml");
|
||||
MessageContext messageContext = new DefaultMessageContext(message, getSoap11MessageFactory());
|
||||
interceptor.setSkipValidationIfNoHeaderPresent(true);
|
||||
boolean result = interceptor.handleRequest(messageContext, null);
|
||||
assertTrue("handeRequest result must be true", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreserveCustomHeaders() throws Exception {
|
||||
interceptor.setSecurementActions("UsernameToken");
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<SOAP-ENV:Header></SOAP-ENV:Header>
|
||||
<SOAP-ENV:Body>
|
||||
<tru:StockSymbol xmlns:tru="http://fabrikam123.com/payloads">QQQ</tru:StockSymbol>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>
|
||||
@@ -0,0 +1,8 @@
|
||||
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tru="http://fabrikam123.com/payloads">
|
||||
<SOAP-ENV:Header>
|
||||
<tru:DummyHeader/>
|
||||
</SOAP-ENV:Header>
|
||||
<SOAP-ENV:Body>
|
||||
<tru:StockSymbol>QQQ</tru:StockSymbol>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>
|
||||
Reference in New Issue
Block a user