-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: disallow access into ws interceptors
- Loading branch information
Showing
5 changed files
with
144 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...s-ws/src/test/java/org/citrusframework/ws/client/WebServiceEndpointConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.citrusframework.ws.client; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.MockitoAnnotations.openMocks; | ||
|
||
import org.citrusframework.ws.interceptor.LoggingClientInterceptor; | ||
import org.mockito.Mock; | ||
import org.springframework.ws.client.core.WebServiceTemplate; | ||
import org.springframework.ws.client.support.interceptor.ClientInterceptor; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
public class WebServiceEndpointConfigurationTest { | ||
|
||
@Mock | ||
private WebServiceTemplate webServiceTemplateMock; | ||
|
||
private AutoCloseable mockitoContext; | ||
|
||
private WebServiceEndpointConfiguration fixture; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
mockitoContext = openMocks(this); | ||
|
||
fixture = new WebServiceEndpointConfiguration(); | ||
fixture.setWebServiceTemplate(webServiceTemplateMock); | ||
} | ||
|
||
@AfterMethod | ||
public void tearDown() throws Exception { | ||
mockitoContext.close(); | ||
} | ||
|
||
@Test | ||
public void containsLoggingClientInterceptorByDefault() { | ||
assertThat(fixture.getInterceptors()) | ||
.hasSize(1) | ||
.satisfiesOnlyOnce(i -> assertThat(i).isInstanceOf(LoggingClientInterceptor.class)); | ||
|
||
verify(webServiceTemplateMock) | ||
.setInterceptors(fixture.getInterceptors().toArray(new ClientInterceptor[0])); | ||
} | ||
|
||
@Test | ||
public void setInterceptors_overridesDefaultInterceptor() { | ||
var clientInterceptor = mock(ClientInterceptor.class); | ||
|
||
fixture.setInterceptors(singletonList(clientInterceptor)); | ||
|
||
verifyFixtureContainsOnlyClientInterceptor(clientInterceptor); | ||
|
||
verify(webServiceTemplateMock) | ||
.setInterceptors(new ClientInterceptor[]{clientInterceptor}); | ||
} | ||
|
||
@Test | ||
public void setInterceptor_overridesDefaultInterceptor() { | ||
var clientInterceptor = mock(ClientInterceptor.class); | ||
|
||
fixture.setInterceptor(clientInterceptor); | ||
|
||
verifyFixtureContainsOnlyClientInterceptor(clientInterceptor); | ||
|
||
verify(webServiceTemplateMock) | ||
.setInterceptors(new ClientInterceptor[]{clientInterceptor}); | ||
} | ||
|
||
@Test | ||
public void addInterceptorAppendsToDefaultInterceptors() { | ||
var clientInterceptor = mock(ClientInterceptor.class); | ||
|
||
fixture.addInterceptor(clientInterceptor); | ||
|
||
assertThat(fixture.getInterceptors()) | ||
.hasSize(2) | ||
.satisfiesOnlyOnce(i -> assertThat(i).isInstanceOf(LoggingClientInterceptor.class)) | ||
.satisfiesOnlyOnce(i -> assertThat(i).isEqualTo(clientInterceptor)); | ||
|
||
verify(webServiceTemplateMock) | ||
.setInterceptors(fixture.getInterceptors().toArray(new ClientInterceptor[0])); | ||
} | ||
|
||
private void verifyFixtureContainsOnlyClientInterceptor(ClientInterceptor clientInterceptor) { | ||
assertThat(fixture.getInterceptors()) | ||
.hasSize(1) | ||
.satisfiesOnlyOnce(i -> assertThat(i).isEqualTo(clientInterceptor)); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
endpoints/citrus-ws/src/test/java/org/citrusframework/ws/client/WsTestUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.citrusframework.ws.client; | ||
|
||
import static org.citrusframework.util.ReflectionHelper.getField; | ||
|
||
import java.util.List; | ||
import org.springframework.ws.client.support.interceptor.ClientInterceptor; | ||
|
||
public final class WsTestUtils { | ||
|
||
@SuppressWarnings({"unchecked"}) | ||
public static List<ClientInterceptor> getInterceptors(WebServiceClient webServiceClient) throws NoSuchFieldException { | ||
return (List<ClientInterceptor>) getField( | ||
WebServiceEndpointConfiguration.class.getDeclaredField("interceptors"), | ||
webServiceClient.getEndpointConfiguration()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters