use of org.apache.cxf.message.Message in project ddf by codice.
the class TestPepInterceptorInvalidSubject method testMessageInvalidSecurityAssertionToken.
// CHECKSTYLE.ON: VisibilityModifier
@Test
public void testMessageInvalidSecurityAssertionToken() throws SecurityServiceException {
PEPAuthorizingInterceptor interceptor = new PEPAuthorizingInterceptor();
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithInvalidSecurityAssertion = mock(Message.class);
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
PowerMockito.mockStatic(SecurityAssertionStore.class);
PowerMockito.mockStatic(SecurityLogger.class);
when(SecurityAssertionStore.getSecurityAssertion(messageWithInvalidSecurityAssertion)).thenReturn(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getSecurityToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
QName op = new QName("urn:catalog:query", "search", "ns1");
QName port = new QName("urn:catalog:query", "query-port", "ns1");
when(messageWithInvalidSecurityAssertion.get("javax.xml.ws.wsdl.operation")).thenReturn(op);
when(messageWithInvalidSecurityAssertion.get("javax.xml.ws.wsdl.port")).thenReturn(port);
Exchange mockExchange = mock(Exchange.class);
BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
when(messageWithInvalidSecurityAssertion.getExchange()).thenReturn(mockExchange);
when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(null);
when(mockSubject.isPermitted(isA(CollectionPermission.class))).thenReturn(false);
expectedExForInvalidSubject.expect(AccessDeniedException.class);
expectedExForInvalidSubject.expectMessage("Unauthorized");
// This should throw
interceptor.handleMessage(messageWithInvalidSecurityAssertion);
PowerMockito.verifyStatic();
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class TestPepInterceptorNullAssertion method testMessageNullSecurityAssertion.
@Test
public void testMessageNullSecurityAssertion() {
PEPAuthorizingInterceptor interceptor = new PEPAuthorizingInterceptor();
Message messageWithNullSecurityAssertion = mock(Message.class);
PowerMockito.mockStatic(SecurityAssertionStore.class);
PowerMockito.mockStatic(SecurityLogger.class);
when(SecurityAssertionStore.getSecurityAssertion(messageWithNullSecurityAssertion)).thenReturn(null);
// SecurityLogger is already stubbed out
expectedExForNullMessage.expect(AccessDeniedException.class);
expectedExForNullMessage.expectMessage("Unauthorized");
interceptor.handleMessage(messageWithNullSecurityAssertion);
PowerMockito.verifyStatic();
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class MetricsOutInterceptorTest method testHandleMessageWithNonClientMessageWithoutLatencyTimeRecorder.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithNonClientMessageWithoutLatencyTimeRecorder() {
// Setup
MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
Message mockMessage = mock(Message.class);
Exchange ex = new ExchangeImpl();
Bus mockBus = mock(Bus.class);
ex.put(Bus.class, mockBus);
when(mockBus.getId()).thenReturn("bus_id");
when(mockMessage.getExchange()).thenReturn(ex);
when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn("false");
// Perform test
outInterceptor.handleMessage(mockMessage);
// validate that there is not an instance of LatencyTimeRecorder on the
// exchange
assertNull(ex.get(LatencyTimeRecorder.class));
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class MetricsOutInterceptorTest method testHandleMessageWithNonClientMessageWithNullExchange.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithNonClientMessageWithNullExchange() {
// Setup
MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
Message mockMessage = mock(Message.class);
when(mockMessage.getExchange()).thenReturn(null);
when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("false");
when(mockMessage.get(Message.REQUESTOR_ROLE)).thenReturn("false");
// Perform test
outInterceptor.handleMessage(mockMessage);
// validate that there is not an instance of LatencyTimeRecorder on the
// exchange
verify(mockMessage, times(1)).getExchange();
}
use of org.apache.cxf.message.Message in project ddf by codice.
the class MetricsOutInterceptorTest method testHandleMessageWithPartialResponseMessage.
/**
* Test method for
* {@link ddf.metrics.interceptor.MetricsOutInterceptor#handleMessage(org.apache.cxf.message.Message)}
* .
*
* @throws InterruptedException
*/
@Test
public void testHandleMessageWithPartialResponseMessage() {
// Setup
MetricsOutInterceptor outInterceptor = new MetricsOutInterceptor();
Message mockMessage = mock(Message.class);
Exchange ex = new ExchangeImpl();
when(mockMessage.getExchange()).thenReturn(ex);
when(mockMessage.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn("true");
// Perform test
outInterceptor.handleMessage(mockMessage);
// validate that there is not an instance of LatencyTimeRecorder on the
// exchange
assertNull(ex.get(LatencyTimeRecorder.class));
}
Aggregations