author
int64 658
755k
| date
stringlengths 19
19
| timezone
int64 -46,800
43.2k
| hash
stringlengths 40
40
| message
stringlengths 5
490
| mods
list | language
stringclasses 20
values | license
stringclasses 3
values | repo
stringlengths 5
68
| original_message
stringlengths 12
491
|
---|---|---|---|---|---|---|---|---|---|
686,936 | 01.09.2021 18:10:27 | -3,600 | 2cf7e2016053b96337c81fbc89907b1d2e04aa3e | Again extending wait timeout in webhooks test to avoid CI flakeyness | [
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"new_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"diff": "@@ -284,7 +284,7 @@ public class WebhooksAcceptanceTest {\n}\nprivate void waitForRequestToTargetServer() throws Exception {\n- assertTrue(\"Timed out waiting for target server to receive a request\", latch.await(5, SECONDS));\n+ assertTrue(\"Timed out waiting for target server to receive a request\", latch.await(10, SECONDS));\n}\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Again extending wait timeout in webhooks test to avoid CI flakeyness |
686,936 | 01.09.2021 19:44:14 | -3,600 | f78b842c3fdc6f5bfab28a97702937997f6bbda3 | Yet again extending wait timeout in webhooks test to avoid CI flakeyness | [
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"new_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"diff": "@@ -284,7 +284,7 @@ public class WebhooksAcceptanceTest {\n}\nprivate void waitForRequestToTargetServer() throws Exception {\n- assertTrue(\"Timed out waiting for target server to receive a request\", latch.await(10, SECONDS));\n+ assertTrue(\"Timed out waiting for target server to receive a request\", latch.await(20, SECONDS));\n}\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Yet again extending wait timeout in webhooks test to avoid CI flakeyness |
686,936 | 01.09.2021 19:55:03 | -3,600 | 4252e54d62c00b8aeb29a75b09c806275dc76eef | Added a CI step to archive the gradle test report | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -38,4 +38,9 @@ jobs:\n- name: Pre-generate API docs\nrun: ./gradlew classes testClasses -x generateApiDocs\n- name: Test WireMock\n- run: ./gradlew test --stacktrace --no-daemon\n+ run: ./gradlew check --stacktrace --no-daemon\n+ - name: Archive test report\n+ uses: actions/upload-artifact@v2\n+ with:\n+ name: gradle-test-report\n+ path: build/reports/tests\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added a CI step to archive the gradle test report |
686,936 | 01.09.2021 20:03:27 | -3,600 | 8bd13a8971c2c3532a129a7289417b1d5176998a | Added a matrix build suffix to the CI test report artifact name so they don't overwrite each other | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -42,5 +42,5 @@ jobs:\n- name: Archive test report\nuses: actions/upload-artifact@v2\nwith:\n- name: gradle-test-report\n+ name: gradle-test-report-${{ matrix.jdk }}\npath: build/reports/tests\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added a matrix build suffix to the CI test report artifact name so they don't overwrite each other |
686,936 | 01.09.2021 20:14:42 | -3,600 | ac8fa241bb3d1260d279d520d32b2fa1fa33856d | Added extra logging to webhooks test and support for adding a name prefix to the console notifier's output. Fixed naming of CI reports to use matrix OS rather than JDK version. | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -42,5 +42,5 @@ jobs:\n- name: Archive test report\nuses: actions/upload-artifact@v2\nwith:\n- name: gradle-test-report-${{ matrix.jdk }}\n+ name: gradle-test-report-${{ matrix.os }}\npath: build/reports/tests\n\\ No newline at end of file\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/ConsoleNotifier.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/ConsoleNotifier.java",
"diff": "@@ -25,9 +25,16 @@ import static java.lang.System.out;\npublic class ConsoleNotifier implements Notifier {\nprivate final boolean verbose;\n+ private final String prefix;\npublic ConsoleNotifier(boolean verbose) {\n+ this(null, verbose);\n+ }\n+\n+ public ConsoleNotifier(String name, boolean verbose) {\nthis.verbose = verbose;\n+ this.prefix = name != null ? \"[\" + name + \"] \" : \"\";\n+\nif (verbose) {\ninfo(\"Verbose logging enabled\");\n}\n@@ -51,9 +58,9 @@ public class ConsoleNotifier implements Notifier {\nt.printStackTrace(err);\n}\n- private static String formatMessage(String message) {\n+ private String formatMessage(String message) {\nDateFormat df = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss.SSS\");\nString date = df.format(new Date());\n- return String.format(\"%s %s\", date, message);\n+ return String.format(\"%s%s %s\", prefix, date, message);\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"new_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"diff": "@@ -2,7 +2,6 @@ package functional;\nimport com.github.tomakehurst.wiremock.client.WireMock;\nimport com.github.tomakehurst.wiremock.common.ConsoleNotifier;\n-import com.github.tomakehurst.wiremock.common.Json;\nimport com.github.tomakehurst.wiremock.http.RequestMethod;\nimport com.github.tomakehurst.wiremock.junit.WireMockRule;\nimport com.github.tomakehurst.wiremock.verification.LoggedRequest;\n@@ -12,6 +11,7 @@ import org.junit.Before;\nimport org.junit.Rule;\nimport org.junit.Test;\nimport org.wiremock.webhooks.Webhooks;\n+import testsupport.CompositeNotifier;\nimport testsupport.TestNotifier;\nimport testsupport.WireMockTestClient;\n@@ -25,7 +25,6 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options\nimport static com.github.tomakehurst.wiremock.http.RequestMethod.POST;\nimport static java.util.concurrent.TimeUnit.MILLISECONDS;\nimport static java.util.concurrent.TimeUnit.SECONDS;\n-import static org.apache.http.entity.ContentType.APPLICATION_JSON;\nimport static org.apache.http.entity.ContentType.TEXT_PLAIN;\nimport static org.hamcrest.MatcherAssert.assertThat;\nimport static org.hamcrest.Matchers.*;\n@@ -35,11 +34,12 @@ import static org.wiremock.webhooks.Webhooks.webhook;\npublic class WebhooksAcceptanceTest {\n@Rule\n- public WireMockRule targetServer = new WireMockRule(options().dynamicPort().notifier(new ConsoleNotifier(true)));\n+ public WireMockRule targetServer = new WireMockRule(options().dynamicPort().notifier(new ConsoleNotifier(\"Target\", true)));\nCountDownLatch latch;\n- TestNotifier notifier = new TestNotifier();\n+ TestNotifier testNotifier = new TestNotifier();\n+ CompositeNotifier notifier = new CompositeNotifier(testNotifier, new ConsoleNotifier(\"Main\", true));\nWireMockTestClient client;\n@Rule\n@@ -57,7 +57,7 @@ public class WebhooksAcceptanceTest {\n}\n});\nreset();\n- notifier.reset();\n+ testNotifier.reset();\ntargetServer.stubFor(any(anyUrl())\n.willReturn(aResponse().withStatus(200)));\nlatch = new CountDownLatch(1);\n@@ -96,7 +96,7 @@ public class WebhooksAcceptanceTest {\n.header(\"X-Multi\").values();\nassertThat(multiHeaderValues, hasItems(\"one\", \"two\"));\n- assertThat(notifier.getInfoMessages(), hasItem(allOf(\n+ assertThat(testNotifier.getInfoMessages(), hasItem(allOf(\ncontainsString(\"Webhook POST request to\"),\ncontainsString(\"/callback returned status\"),\ncontainsString(\"200\")\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "wiremock-webhooks-extension/src/test/java/testsupport/CompositeNotifier.java",
"diff": "+package testsupport;\n+\n+import com.github.tomakehurst.wiremock.common.Notifier;\n+\n+import java.util.Arrays;\n+import java.util.List;\n+\n+public class CompositeNotifier implements Notifier {\n+\n+ private final List<Notifier> notifiers;\n+\n+ public CompositeNotifier(Notifier... notifiers) {\n+ this(Arrays.asList(notifiers));\n+ }\n+\n+ public CompositeNotifier(List<Notifier> notifiers) {\n+ this.notifiers = notifiers;\n+ }\n+\n+ @Override\n+ public void info(String message) {\n+ notifiers.forEach(notifier -> notifier.info(message));\n+ }\n+\n+ @Override\n+ public void error(String message) {\n+ notifiers.forEach(notifier -> notifier.error(message));\n+ }\n+\n+ @Override\n+ public void error(String message, Throwable t) {\n+ notifiers.forEach(notifier -> notifier.error(message, t));\n+ }\n+}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added extra logging to webhooks test and support for adding a name prefix to the console notifier's output. Fixed naming of CI reports to use matrix OS rather than JDK version. |
686,936 | 01.09.2021 20:19:14 | -3,600 | 517da371e1b10223c9ffa9384f3b5a8121a719d9 | Added webhooks project build reports to CI archive | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -43,4 +43,6 @@ jobs:\nuses: actions/upload-artifact@v2\nwith:\nname: gradle-test-report-${{ matrix.os }}\n- path: build/reports/tests\n\\ No newline at end of file\n+ path: |\n+ build/reports/tests\n+ wiremock-webhooks-extension/build/reports/tests\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added webhooks project build reports to CI archive |
686,936 | 01.09.2021 20:25:09 | -3,600 | 838d4dfd4e3b55cb458e309c85a9e61374669e89 | Split archiving of core and webhooks test reports in CI | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -39,10 +39,13 @@ jobs:\nrun: ./gradlew classes testClasses -x generateApiDocs\n- name: Test WireMock\nrun: ./gradlew check --stacktrace --no-daemon\n- - name: Archive test report\n+ - name: Archive WireMock test report\nuses: actions/upload-artifact@v2\nwith:\n- name: gradle-test-report-${{ matrix.os }}\n- path: |\n- build/reports/tests\n- wiremock-webhooks-extension/build/reports/tests\n\\ No newline at end of file\n+ name: wiremock-core-test-report-${{ matrix.os }}\n+ path: build/reports/tests\n+ - name: Archive Webhooks test report\n+ uses: actions/upload-artifact@v2\n+ with:\n+ name: wiremock-webhooks-extension-test-report-${{ matrix.os }}\n+ path: wiremock-webhooks-extension/build/reports/tests\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Split archiving of core and webhooks test reports in CI |
686,936 | 02.09.2021 09:24:54 | -3,600 | 30ada0ed6a9d9c08cf92e948f91f848800790f49 | Integrated auto JVM proxy config with the new JUnit extension | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"diff": "package com.github.tomakehurst.wiremock.junit5;\nimport com.github.tomakehurst.wiremock.WireMockServer;\n-import com.github.tomakehurst.wiremock.client.MappingBuilder;\n-import com.github.tomakehurst.wiremock.client.VerificationException;\nimport com.github.tomakehurst.wiremock.client.WireMock;\nimport com.github.tomakehurst.wiremock.core.Options;\nimport com.github.tomakehurst.wiremock.core.WireMockConfiguration;\n+import com.github.tomakehurst.wiremock.http.JvmProxyConfigurer;\nimport com.github.tomakehurst.wiremock.junit.DslWrapper;\n-import com.github.tomakehurst.wiremock.verification.LoggedRequest;\n-import com.github.tomakehurst.wiremock.verification.NearMiss;\nimport org.junit.jupiter.api.extension.*;\nimport org.junit.platform.commons.support.AnnotationSupport;\n-import javax.swing.text.html.Option;\n-import java.util.List;\nimport java.util.Optional;\nimport static com.google.common.base.MoreObjects.firstNonNull;\n@@ -44,15 +39,19 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\nprivate WireMockServer wireMockServer;\nprivate boolean isNonStatic = false;\n+ private Boolean proxyMode;\n+\npublic WireMockExtension() {\nconfigureStaticDsl = true;\nfailOnUnmatchedRequests = false;\n}\n- public WireMockExtension(Options options, boolean configureStaticDsl, boolean failOnUnmatchedRequests) {\n+ // Intended to be called from the builder\n+ protected WireMockExtension(Options options, boolean configureStaticDsl, boolean failOnUnmatchedRequests, boolean proxyMode) {\nthis.options = options;\nthis.configureStaticDsl = configureStaticDsl;\nthis.failOnUnmatchedRequests = failOnUnmatchedRequests;\n+ this.proxyMode = proxyMode;\n}\npublic static Builder newInstance() {\n@@ -92,6 +91,15 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\n}\n}\n+ private void setAdditionalOptions(ExtensionContext extensionContext) {\n+ if (proxyMode == null) {\n+ proxyMode = extensionContext.getElement()\n+ .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, WireMockTest.class))\n+ .<Boolean>map(WireMockTest::proxyMode)\n+ .orElse(false);\n+ }\n+ }\n+\nprivate Options resolveOptions(ExtensionContext extensionContext) {\nreturn extensionContext.getElement()\n.flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, WireMockTest.class))\n@@ -101,8 +109,9 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\n}\nprivate Options buildOptionsFromWireMockTestAnnotation(WireMockTest annotation) {\n- WireMockConfiguration options = WireMockConfiguration.options();\n- options.port(annotation.httpPort());\n+ WireMockConfiguration options = WireMockConfiguration.options()\n+ .port(annotation.httpPort())\n+ .enableBrowserProxying(annotation.proxyMode());\nif (annotation.httpsEnabled()) {\noptions.httpsPort(annotation.httpsPort());\n@@ -124,6 +133,7 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\n@Override\npublic void beforeAll(ExtensionContext context) throws Exception {\nstartServerIfRequired(context);\n+ setAdditionalOptions(context);\n}\n@Override\n@@ -134,6 +144,12 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\n} else {\nresetToDefaultMappings();\n}\n+\n+ setAdditionalOptions(context);\n+\n+ if (proxyMode) {\n+ JvmProxyConfigurer.configureFor(wireMockServer);\n+ }\n}\n@Override\n@@ -150,6 +166,10 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\nif (isNonStatic) {\nstopServerIfRunning();\n}\n+\n+ if (proxyMode) {\n+ JvmProxyConfigurer.restorePrevious();\n+ }\n}\npublic WireMockRuntimeInfo getRuntimeInfo() {\n@@ -165,6 +185,7 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\nprivate Options options = WireMockConfiguration.wireMockConfig().dynamicPort();\nprivate boolean configureStaticDsl = false;\nprivate boolean failOnUnmatchedRequests = false;\n+ private boolean proxyMode = false;\npublic Builder options(Options options) {\nthis.options = options;\n@@ -181,8 +202,17 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\nreturn this;\n}\n+ public Builder proxyMode(boolean proxyMode) {\n+ this.proxyMode = proxyMode;\n+ return this;\n+ }\n+\npublic WireMockExtension build() {\n- return new WireMockExtension(options, configureStaticDsl, failOnUnmatchedRequests);\n+ if (proxyMode && !options.browserProxySettings().enabled() && (options instanceof WireMockConfiguration)) {\n+ ((WireMockConfiguration) options).enableBrowserProxying(true);\n+ }\n+\n+ return new WireMockExtension(options, configureStaticDsl, failOnUnmatchedRequests, proxyMode);\n}\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockTest.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockTest.java",
"diff": "@@ -32,4 +32,6 @@ public @interface WireMockTest {\nboolean httpsEnabled() default false;\nint httpsPort() default 0;\n+ boolean proxyMode() default false;\n+\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/JvmProxyConfigAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/JvmProxyConfigAcceptanceTest.java",
"diff": "@@ -47,6 +47,8 @@ public class JvmProxyConfigAcceptanceTest {\n@Test\npublic void configuresHttpsProxyingOnlyFromAWireMockServer() throws Exception {\n+ CloseableHttpClient httpClient = HttpClientFactory.createClient();\n+\nwireMockServer = new WireMockServer(wireMockConfig().dynamicPort().enableBrowserProxying(true));\nwireMockServer.start();\n@@ -56,7 +58,6 @@ public class JvmProxyConfigAcceptanceTest {\n.withHost(equalTo(\"example.com\"))\n.willReturn(ok(\"Proxied stuff\")));\n- CloseableHttpClient httpClient = HttpClientFactory.createClient();\ntry (CloseableHttpResponse response = httpClient.execute(new HttpGet(\"https://example.com/stuff\"))) {\nassertThat(EntityUtils.toString(response.getEntity()), is(\"Proxied stuff\"));\n}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionJvmProxyDeclarativeTest.java",
"diff": "+package com.github.tomakehurst.wiremock.junit5;\n+\n+import com.github.tomakehurst.wiremock.http.HttpClientFactory;\n+import org.apache.http.client.methods.CloseableHttpResponse;\n+import org.apache.http.client.methods.HttpGet;\n+import org.apache.http.impl.client.CloseableHttpClient;\n+import org.apache.http.util.EntityUtils;\n+import org.junit.jupiter.api.BeforeEach;\n+import org.junit.jupiter.api.Test;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+\n+@WireMockTest(proxyMode = true, httpsEnabled = true)\n+public class JUnitJupiterExtensionJvmProxyDeclarativeTest {\n+\n+ CloseableHttpClient client;\n+\n+ @BeforeEach\n+ void init() {\n+ client = HttpClientFactory.createClient();\n+ }\n+\n+ @Test\n+ void configures_jvm_proxy_and_enables_browser_proxying() throws Exception {\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"one.my.domain\"))\n+ .willReturn(ok(\"1\")));\n+\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"two.my.domain\"))\n+ .willReturn(ok(\"2\")));\n+\n+ assertThat(getContent(\"http://one.my.domain/things\"), is(\"1\"));\n+ assertThat(getContent(\"https://two.my.domain/things\"), is(\"2\"));\n+ }\n+\n+ private String getContent(String url) throws Exception {\n+ try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {\n+ return EntityUtils.toString(response.getEntity());\n+ }\n+ }\n+}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionJvmProxyNonStaticProgrammaticTest.java",
"diff": "+package com.github.tomakehurst.wiremock.junit5;\n+\n+import com.github.tomakehurst.wiremock.http.HttpClientFactory;\n+import org.apache.http.client.methods.CloseableHttpResponse;\n+import org.apache.http.client.methods.HttpGet;\n+import org.apache.http.impl.client.CloseableHttpClient;\n+import org.apache.http.util.EntityUtils;\n+import org.junit.jupiter.api.BeforeEach;\n+import org.junit.jupiter.api.Test;\n+import org.junit.jupiter.api.extension.RegisterExtension;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+\n+public class JUnitJupiterExtensionJvmProxyNonStaticProgrammaticTest {\n+\n+ @RegisterExtension\n+ WireMockExtension wm = WireMockExtension.newInstance()\n+ .options(wireMockConfig().dynamicPort().dynamicHttpsPort())\n+ .configureStaticDsl(true)\n+ .proxyMode(true)\n+ .build();\n+\n+ CloseableHttpClient client;\n+\n+ @BeforeEach\n+ void init() {\n+ client = HttpClientFactory.createClient();\n+ }\n+\n+ @Test\n+ void configures_jvm_proxy_and_enables_browser_proxying() throws Exception {\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"one.my.domain\"))\n+ .willReturn(ok(\"1\")));\n+\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"two.my.domain\"))\n+ .willReturn(ok(\"2\")));\n+\n+ assertThat(getContent(\"http://one.my.domain/things\"), is(\"1\"));\n+ assertThat(getContent(\"https://two.my.domain/things\"), is(\"2\"));\n+ }\n+\n+ private String getContent(String url) throws Exception {\n+ try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {\n+ return EntityUtils.toString(response.getEntity());\n+ }\n+ }\n+}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionJvmProxyStaticProgrammaticTest.java",
"diff": "+package com.github.tomakehurst.wiremock.junit5;\n+\n+import com.github.tomakehurst.wiremock.http.HttpClientFactory;\n+import org.apache.http.client.methods.CloseableHttpResponse;\n+import org.apache.http.client.methods.HttpGet;\n+import org.apache.http.impl.client.CloseableHttpClient;\n+import org.apache.http.util.EntityUtils;\n+import org.junit.jupiter.api.BeforeEach;\n+import org.junit.jupiter.api.Test;\n+import org.junit.jupiter.api.extension.RegisterExtension;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+\n+public class JUnitJupiterExtensionJvmProxyStaticProgrammaticTest {\n+\n+ @RegisterExtension\n+ static WireMockExtension wm = WireMockExtension.newInstance()\n+ .options(wireMockConfig().dynamicPort().dynamicHttpsPort())\n+ .configureStaticDsl(true)\n+ .proxyMode(true)\n+ .build();\n+\n+ CloseableHttpClient client;\n+\n+ @BeforeEach\n+ void init() {\n+ client = HttpClientFactory.createClient();\n+ }\n+\n+ @Test\n+ void configures_jvm_proxy_and_enables_browser_proxying() throws Exception {\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"one.my.domain\"))\n+ .willReturn(ok(\"1\")));\n+\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"two.my.domain\"))\n+ .willReturn(ok(\"2\")));\n+\n+ assertThat(getContent(\"http://one.my.domain/things\"), is(\"1\"));\n+ assertThat(getContent(\"https://two.my.domain/things\"), is(\"2\"));\n+ }\n+\n+ private String getContent(String url) throws Exception {\n+ try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {\n+ return EntityUtils.toString(response.getEntity());\n+ }\n+ }\n+}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Integrated auto JVM proxy config with the new JUnit extension |
686,936 | 02.09.2021 18:28:58 | -3,600 | 3174e6b23b829adae7b9eaebe128a7157fb6c050 | Documented multi-domain proxy mode for JUnit 4.x, Java and JUnit Jupiter | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/junit-jupiter.md",
"new_path": "docs-v2/_docs/junit-jupiter.md",
"diff": "@@ -154,3 +154,89 @@ By default, in either the declarative or programmatic form, if the WireMock inst\ntest run an assertion error will be thrown and the test will fail.\nThis behavior can be changed by calling `.failOnUnmatchedRequests(false)` on the extension builder when using the programmatic form.\n+\n+\n+## Proxy mode\n+The JUnit Jupiter extension can be configured to enable \"proxy mode\" which simplifies configuration and supports\n+[multi-domain mocking](/docs/multi-domain-mocking/).\n+\n+### Declarative\n+In declarative mode this is done by setting the `proxyMode = true` in the annotation declaration. Then, provided your app's\n+HTTP client honours the JVM's proxy system properties, you can specify different domain (host) names when creating stubs:\n+\n+```java\n+@WireMockTest(proxyMode = true)\n+public class JUnitJupiterExtensionJvmProxyDeclarativeTest {\n+\n+ CloseableHttpClient client;\n+\n+ @BeforeEach\n+ void init() {\n+ client = HttpClientBuilder.create()\n+ .useSystemProperties() // This must be enabled for auto proxy config\n+ .build();\n+ }\n+\n+ @Test\n+ void configures_jvm_proxy_and_enables_browser_proxying() throws Exception {\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"one.my.domain\"))\n+ .willReturn(ok(\"1\")));\n+\n+ stubFor(get(\"/things\")\n+ .withHost(equalTo(\"two.my.domain\"))\n+ .willReturn(ok(\"2\")));\n+\n+ assertThat(getContent(\"http://one.my.domain/things\"), is(\"1\"));\n+ assertThat(getContent(\"http://two.my.domain/things\"), is(\"2\"));\n+ }\n+\n+ private String getContent(String url) throws Exception {\n+ try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {\n+ return EntityUtils.toString(response.getEntity());\n+ }\n+ }\n+}\n+```\n+\n+### Programmatic\n+Proxy mode can be enabled via the extension builder when using the programmatic form:\n+\n+```java\n+public class JUnitJupiterProgrammaticProxyTest {\n+\n+ @RegisterExtension\n+ static WireMockExtension wm = WireMockExtension.newInstance()\n+ .proxyMode(true)\n+ .build();\n+\n+ CloseableHttpClient client;\n+\n+ @BeforeEach\n+ void init() {\n+ client = HttpClientBuilder.create()\n+ .useSystemProperties() // This must be enabled for auto proxy config\n+ .build();\n+ }\n+\n+ @Test\n+ void configures_jvm_proxy_and_enables_browser_proxying() throws Exception {\n+ wm.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"one.my.domain\"))\n+ .willReturn(ok(\"1\")));\n+\n+ wm.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"two.my.domain\"))\n+ .willReturn(ok(\"2\")));\n+\n+ assertThat(getContent(\"http://one.my.domain/things\"), is(\"1\"));\n+ assertThat(getContent(\"http://two.my.domain/things\"), is(\"2\"));\n+ }\n+\n+ private String getContent(String url) throws Exception {\n+ try (CloseableHttpResponse response = client.execute(new HttpGet(url))) {\n+ return EntityUtils.toString(response.getEntity());\n+ }\n+ }\n+}\n+```\n\\ No newline at end of file\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "docs-v2/_docs/multi-domain-mocking.md",
"diff": "+---\n+layout: docs\n+title: Multi-domain Mocking\n+toc_rank: 66\n+description: Using proxying to mock multiple domains in a single WireMock instance.\n+---\n+\n+A typical usage pattern is to run a WireMock instance per API you need to mock and configure your app to treat these instances\n+as endpoints.\n+\n+However, it's also possible to mock multiple APIs in a single instance via the use of the proxying and hostname matching features.\n+There are two advantages of this approach - lower overhead (memory, startup/shutdown time), and no need to modify each base URL in your app's\n+configuration. It can also avoid some of the headaches associated with binding to random ports.\n+\n+The key steps to enabling this configuration are:\n+\n+1. Enable browser (forward) proxying via `.enableBrowserProxying(true)` in the startup options.\n+2. Configure the JVM's proxy settings to point to the WireMock instance using `JvmProxyConfigurer`.\n+\n+The following sections detail how to achieve this in various deployment contexts.\n+\n+\n+## Configuring for JUnit Jupiter\n+The simplest way to enable this mode if you're using JUnit Jupiter it to toggle it on via the `WireMockExtension`. See the\n+[Junit Jupiter Proxy Mode](/docs/junit-jupiter/#proxy-mode) for details.\n+\n+## Configuring for JUnit 4.x\n+To use this mode with the JUnit 4.x rule we:\n+1. Create the rule as usual with browser proxying enabled.\n+2. Ensure our HTTP client (the one used by our app to talk to the API we're mocking) honours the system properties relating to proxy servers.\n+3. Set the proxy properties using `JvmProxyConfigurer` before each test case and unset them afterwards.\n+4. Specify the host name we're targeting when creating stubs.\n+\n+```java\n+public class MultiDomainJUnit4Test {\n+\n+ @Rule\n+ public WireMockRule wm = new WireMockRule(options()\n+ .dynamicPort()\n+ .enableBrowserProxying(true)\n+ );\n+\n+ HttpClient httpClient = HttpClientBuilder.create()\n+ .useSystemProperties() // This must be enabled for auto proxy config\n+ .build();\n+\n+ @Before\n+ public void init() {\n+ JvmProxyConfigurer.configureFor(wm);\n+ }\n+\n+ @After\n+ public void cleanup() {\n+ JvmProxyConfigurer.restorePrevious();\n+ }\n+\n+ @Test\n+ public void testViaProxy() throws Exception {\n+ wm.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.first.domain\"))\n+ .willReturn(ok(\"Domain 1\")));\n+\n+ wm.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.second.domain\"))\n+ .willReturn(ok(\"Domain 2\")));\n+\n+ HttpResponse response = httpClient.execute(new HttpGet(\"http://my.first.domain/things\"));\n+ String responseBody = EntityUtils.toString(response.getEntity());\n+ assertEquals(\"Domain 1\", responseBody);\n+\n+ response = httpClient.execute(new HttpGet(\"http://my.second.domain/things\"));\n+ responseBody = EntityUtils.toString(response.getEntity());\n+ assertEquals(\"Domain 2\", responseBody);\n+ }\n+}\n+```\n+\n+## Configuring for other Java\n+To use this mode from Java code we:\n+1. Create and start a `WireMockServer` instance with browser proxying enabled.\n+2. Ensure our HTTP client (the one used by our app to talk to the API we're mocking) honours the system properties relating to proxy servers\n+3. Set the proxy properties using `JvmProxyConfigurer` before each bit of work and unset them afterwards.\n+4. Specify the host name we're targeting when creating stubs.\n+\n+```java\n+public void testViaProxyUsingServer() throws Exception {\n+ WireMockServer wireMockServer = new WireMockServer(options()\n+ .dynamicPort()\n+ .enableBrowserProxying(true)\n+ );\n+ wireMockServer.start();\n+\n+ HttpClient httpClient = HttpClientBuilder.create()\n+ .useSystemProperties() // This must be enabled for auto proxy config\n+ .build();\n+\n+ JvmProxyConfigurer.configureFor(wireMockServer);\n+\n+ wireMockServer.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.first.domain\"))\n+ .willReturn(ok(\"Domain 1\")));\n+\n+ wireMockServer.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.second.domain\"))\n+ .willReturn(ok(\"Domain 2\")));\n+\n+ HttpResponse response = httpClient.execute(new HttpGet(\"http://my.first.domain/things\"));\n+ String responseBody = EntityUtils.toString(response.getEntity()); // Should == Domain 1\n+\n+ response = httpClient.execute(new HttpGet(\"http://my.second.domain/things\"));\n+ responseBody = EntityUtils.toString(response.getEntity()); // Should == Domain 2\n+\n+ wireMockServer.stop();\n+ JvmProxyConfigurer.restorePrevious();\n+}\n+```\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/ignored/JUnit5ProxyTest.java",
"diff": "+package ignored;\n+\n+import com.github.tomakehurst.wiremock.WireMockServer;\n+import com.github.tomakehurst.wiremock.http.JvmProxyConfigurer;\n+import com.github.tomakehurst.wiremock.junit.WireMockRule;\n+import org.apache.http.HttpResponse;\n+import org.apache.http.client.HttpClient;\n+import org.apache.http.client.methods.HttpGet;\n+import org.apache.http.impl.client.HttpClientBuilder;\n+import org.apache.http.util.EntityUtils;\n+import org.junit.After;\n+import org.junit.Before;\n+import org.junit.Rule;\n+import org.junit.Test;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;\n+import static org.junit.Assert.assertEquals;\n+\n+public class JUnit5ProxyTest {\n+\n+ @Rule\n+ public WireMockRule wm = new WireMockRule(options().dynamicPort().enableBrowserProxying(true));\n+\n+ HttpClient httpClient = HttpClientBuilder.create()\n+ .useSystemProperties() // This must be enabled for auto-configuration of proxy settings to work\n+ .build();\n+\n+ @Before\n+ public void init() {\n+ JvmProxyConfigurer.configureFor(wm);\n+ }\n+\n+ @After\n+ public void cleanup() {\n+ JvmProxyConfigurer.restorePrevious();\n+ }\n+\n+ @Test\n+ public void testViaProxyUsingRule() throws Exception {\n+ wm.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.first.domain\"))\n+ .willReturn(ok(\"Domain 1\")));\n+\n+ wm.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.second.domain\"))\n+ .willReturn(ok(\"Domain 2\")));\n+\n+ HttpResponse response = httpClient.execute(new HttpGet(\"http://my.first.domain/things\"));\n+ String responseBody = EntityUtils.toString(response.getEntity());\n+ assertEquals(\"Domain 1\", responseBody);\n+\n+ response = httpClient.execute(new HttpGet(\"http://my.second.domain/things\"));\n+ responseBody = EntityUtils.toString(response.getEntity());\n+ assertEquals(\"Domain 2\", responseBody);\n+ }\n+\n+ @Test\n+ public void testViaProxyUsingServer() throws Exception {\n+ WireMockServer wireMockServer = new WireMockServer(options().dynamicPort().enableBrowserProxying(true));\n+ wireMockServer.start();\n+ JvmProxyConfigurer.configureFor(wireMockServer);\n+\n+ wireMockServer.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.first.domain\"))\n+ .willReturn(ok(\"Domain 1\")));\n+\n+ wireMockServer.stubFor(get(\"/things\")\n+ .withHost(equalTo(\"my.second.domain\"))\n+ .willReturn(ok(\"Domain 2\")));\n+\n+ HttpResponse response = httpClient.execute(new HttpGet(\"http://my.first.domain/things\"));\n+ String responseBody = EntityUtils.toString(response.getEntity());\n+ assertEquals(\"Domain 1\", responseBody);\n+\n+ response = httpClient.execute(new HttpGet(\"http://my.second.domain/things\"));\n+ responseBody = EntityUtils.toString(response.getEntity());\n+ assertEquals(\"Domain 2\", responseBody);\n+\n+ wireMockServer.stop();\n+ JvmProxyConfigurer.restorePrevious();\n+ }\n+}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Documented multi-domain proxy mode for JUnit 4.x, Java and JUnit Jupiter |
686,936 | 06.09.2021 18:05:06 | -3,600 | 18c4aa0575b0c880e67af8f4305a10f5a0e4ba76 | Added separate Windows report publish steps in CI | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -39,6 +39,20 @@ jobs:\nrun: ./gradlew classes testClasses -x generateApiDocs\n- name: Test WireMock\nrun: ./gradlew check --stacktrace --no-daemon\n+\n+ - name: Archive WireMock test report - Windows\n+ if: ${{ contains(matrix.os, 'windows') }}\n+ uses: actions/upload-artifact@v2\n+ with:\n+ name: wiremock-core-test-report-${{ matrix.os }}\n+ path: build\\reports\\tests\n+ - name: Archive Webhooks test report - Windows\n+ if: ${{ contains(matrix.os, 'windows') }}\n+ uses: actions/upload-artifact@v2\n+ with:\n+ name: wiremock-webhooks-extension-test-report-${{ matrix.os }}\n+ path: wiremock-webhooks-extension\\build\\reports\\tests\n+\n- name: Archive WireMock test report\nuses: actions/upload-artifact@v2\nwith:\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added separate Windows report publish steps in CI |
686,936 | 06.09.2021 18:13:49 | -3,600 | a8ef3f2c56b1834ca587b619a5547a7d52224268 | Prevent *nix report publishing on Windows in CI | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -40,6 +40,10 @@ jobs:\n- name: Test WireMock\nrun: ./gradlew check --stacktrace --no-daemon\n+ - name: List reports dir - Windows\n+ if: ${{ contains(matrix.os, 'windows') }}\n+ run: dir build\\reports\\tests\n+\n- name: Archive WireMock test report - Windows\nif: ${{ contains(matrix.os, 'windows') }}\nuses: actions/upload-artifact@v2\n@@ -54,11 +58,13 @@ jobs:\npath: wiremock-webhooks-extension\\build\\reports\\tests\n- name: Archive WireMock test report\n+ if: ${{ !contains(matrix.os, 'windows') }}\nuses: actions/upload-artifact@v2\nwith:\nname: wiremock-core-test-report-${{ matrix.os }}\npath: build/reports/tests\n- name: Archive Webhooks test report\n+ if: ${{ !contains(matrix.os, 'windows') }}\nuses: actions/upload-artifact@v2\nwith:\nname: wiremock-webhooks-extension-test-report-${{ matrix.os }}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Prevent *nix report publishing on Windows in CI |
686,936 | 06.09.2021 18:32:20 | -3,600 | b372ea9eaf6a83ca620c8eaa2732fdad8fd863d9 | Marked CI test report publishing jobs as always() so that they run on failure | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -40,31 +40,14 @@ jobs:\n- name: Test WireMock\nrun: ./gradlew check --stacktrace --no-daemon\n- - name: List reports dir - Windows\n- if: ${{ contains(matrix.os, 'windows') }}\n- run: dir build\\reports\\tests\n-\n- - name: Archive WireMock test report - Windows\n- if: ${{ contains(matrix.os, 'windows') }}\n- uses: actions/upload-artifact@v2\n- with:\n- name: wiremock-core-test-report-${{ matrix.os }}\n- path: build\\reports\\tests\n- - name: Archive Webhooks test report - Windows\n- if: ${{ contains(matrix.os, 'windows') }}\n- uses: actions/upload-artifact@v2\n- with:\n- name: wiremock-webhooks-extension-test-report-${{ matrix.os }}\n- path: wiremock-webhooks-extension\\build\\reports\\tests\n-\n- - name: Archive WireMock test report\n- if: ${{ !contains(matrix.os, 'windows') }}\n+ - name: Archive WireMock test report - ${{ matrix.os }}\n+ if: always()\nuses: actions/upload-artifact@v2\nwith:\nname: wiremock-core-test-report-${{ matrix.os }}\npath: build/reports/tests\n- - name: Archive Webhooks test report\n- if: ${{ !contains(matrix.os, 'windows') }}\n+ - name: Archive Webhooks test report - ${{ matrix.os }}\n+ if: always()\nuses: actions/upload-artifact@v2\nwith:\nname: wiremock-webhooks-extension-test-report-${{ matrix.os }}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Marked CI test report publishing jobs as always() so that they run on failure |
686,936 | 06.09.2021 18:48:44 | -3,600 | c2ba8fe82492dc5a663dcd3a2b9a3b565eef42f5 | Removed redundant console notifier from within TestNotifier (since we can now use CompositeNotifier). Dumped console messages in flakey webhooks test case for CI debugging. | [
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"new_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"diff": "@@ -17,6 +17,7 @@ import testsupport.WireMockTestClient;\nimport java.util.List;\nimport java.util.concurrent.CountDownLatch;\n+import java.util.stream.Collectors;\nimport static com.github.tomakehurst.wiremock.client.WireMock.any;\nimport static com.github.tomakehurst.wiremock.client.WireMock.equalTo;\n@@ -96,6 +97,8 @@ public class WebhooksAcceptanceTest {\n.header(\"X-Multi\").values();\nassertThat(multiHeaderValues, hasItems(\"one\", \"two\"));\n+ System.out.println(\"All info notifications:\\n\" + String.join(\"\\n\", testNotifier.getInfoMessages()));\n+\nassertThat(testNotifier.getInfoMessages(), hasItem(allOf(\ncontainsString(\"Webhook POST request to\"),\ncontainsString(\"/callback returned status\"),\n"
},
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/testsupport/TestNotifier.java",
"new_path": "wiremock-webhooks-extension/src/test/java/testsupport/TestNotifier.java",
"diff": "*/\npackage testsupport;\n-import com.github.tomakehurst.wiremock.common.ConsoleNotifier;\nimport com.github.tomakehurst.wiremock.common.LocalNotifier;\nimport com.github.tomakehurst.wiremock.common.Notifier;\n@@ -29,8 +28,6 @@ public class TestNotifier implements Notifier {\nprivate Notifier previousNotifier;\n- private final ConsoleNotifier consoleNotifier = new ConsoleNotifier(true);\n-\npublic TestNotifier() {\nthis.info = new ArrayList<>();\nthis.error = new ArrayList<>();\n@@ -50,19 +47,16 @@ public class TestNotifier implements Notifier {\n@Override\npublic void info(String message) {\nthis.info.add(message);\n- consoleNotifier.info(message);\n}\n@Override\npublic void error(String message) {\nthis.error.add(message);\n- consoleNotifier.error(message);\n}\n@Override\npublic void error(String message, Throwable t) {\nthis.error.add(message);\n- consoleNotifier.error(message, t);\n}\npublic List<String> getInfoMessages() { return info; }\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Removed redundant console notifier from within TestNotifier (since we can now use CompositeNotifier). Dumped console messages in flakey webhooks test case for CI debugging. |
686,936 | 06.09.2021 19:37:21 | -3,600 | 64f4566df2dee095339a8b1ffab19e62ff4c523d | Added some clarity to debug message in flakey webhooks test | [
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"new_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"diff": "@@ -97,7 +97,7 @@ public class WebhooksAcceptanceTest {\n.header(\"X-Multi\").values();\nassertThat(multiHeaderValues, hasItems(\"one\", \"two\"));\n- System.out.println(\"All info notifications:\\n\" + String.join(\"\\n\", testNotifier.getInfoMessages()));\n+ System.out.println(\"All info notifications:\\n\" + testNotifier.getInfoMessages().stream().map(message -> message.replace(\"\\n\", \"\\n>>> \")).collect(Collectors.joining(\"\\n>>> \")));\nassertThat(testNotifier.getInfoMessages(), hasItem(allOf(\ncontainsString(\"Webhook POST request to\"),\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added some clarity to debug message in flakey webhooks test |
686,936 | 06.09.2021 19:52:31 | -3,600 | f989c1e638cb6e6ba055c74c1fcf925470488089 | Attempted at fixing race condition in webhooks acceptance test | [
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"new_path": "wiremock-webhooks-extension/src/test/java/functional/WebhooksAcceptanceTest.java",
"diff": "@@ -2,8 +2,11 @@ package functional;\nimport com.github.tomakehurst.wiremock.client.WireMock;\nimport com.github.tomakehurst.wiremock.common.ConsoleNotifier;\n+import com.github.tomakehurst.wiremock.core.Admin;\n+import com.github.tomakehurst.wiremock.extension.PostServeAction;\nimport com.github.tomakehurst.wiremock.http.RequestMethod;\nimport com.github.tomakehurst.wiremock.junit.WireMockRule;\n+import com.github.tomakehurst.wiremock.stubbing.ServeEvent;\nimport com.github.tomakehurst.wiremock.verification.LoggedRequest;\nimport com.google.common.base.Stopwatch;\nimport org.apache.http.entity.StringEntity;\n@@ -34,10 +37,26 @@ import static org.wiremock.webhooks.Webhooks.webhook;\npublic class WebhooksAcceptanceTest {\n+ CountDownLatch latch;\n+\n@Rule\n- public WireMockRule targetServer = new WireMockRule(options().dynamicPort().notifier(new ConsoleNotifier(\"Target\", true)));\n+ public WireMockRule targetServer = new WireMockRule(options()\n+ .dynamicPort()\n+ .extensions(new PostServeAction() {\n+ @Override\n+ public void doGlobalAction(ServeEvent serveEvent, Admin admin) {\n+ if (serveEvent.getRequest().getUrl().startsWith(\"/callback\")) {\n+ latch.countDown();\n+ }\n+ }\n- CountDownLatch latch;\n+ @Override\n+ public String getName() {\n+ return \"test-latch\";\n+ }\n+ })\n+ .notifier(new ConsoleNotifier(\"Target\", true))\n+ );\nTestNotifier testNotifier = new TestNotifier();\nCompositeNotifier notifier = new CompositeNotifier(testNotifier, new ConsoleNotifier(\"Main\", true));\n@@ -52,11 +71,6 @@ public class WebhooksAcceptanceTest {\n@Before\npublic void init() {\n- targetServer.addMockServiceRequestListener((request, response) -> {\n- if (request.getUrl().startsWith(\"/callback\")) {\n- latch.countDown();\n- }\n- });\nreset();\ntestNotifier.reset();\ntargetServer.stubFor(any(anyUrl())\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Attempted at fixing race condition in webhooks acceptance test |
686,936 | 07.09.2021 10:32:53 | -3,600 | 13abf9b6f6be0afe90c093f447ad645be7353655 | Minor JUnit Jupiter doc tweaks | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/junit-jupiter.md",
"new_path": "docs-v2/_docs/junit-jupiter.md",
"diff": "@@ -7,7 +7,7 @@ description: Running WireMock with the JUnit 5 Jupiter test framework.\nThe JUnit Jupiter extension simplifies running of one or more WireMock instances in a Jupiter test class.\n-It supports two modes of operation - declarative (simple, not configurable) and programmatic (less simple, configurable).\n+It supports two modes of operation - declarative (simple, limited configuration options) and programmatic (less simple, very configurable).\nThese are both explained in detail below.\n## Basic usage - declarative\n@@ -33,6 +33,7 @@ public class DeclarativeWireMockTest {\n// Info such as port numbers is also available\nint port = wmRuntimeInfo.getHttpPort();\n+ // Do some testing...\n}\n}\n```\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Minor JUnit Jupiter doc tweaks |
686,936 | 07.09.2021 12:02:57 | -3,600 | e5fa5d8c5d3d2f1c58680b4ef2b5099f593e78c8 | Fixed Gradle builds so that only maven central is pushed to on release and both the main project and the extension are pushed | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -405,7 +405,7 @@ jar.dependsOn generateApiDocs\nsignThinJarPublication.dependsOn writeThinJarPom\ntask release {\n- dependsOn clean, jar, shadowJar, publish, addGitTag\n+ dependsOn clean, jar, shadowJar, publishAllPublicationsToMavenRepository, addGitTag\n}\ntask 'bump-patch-version' {\n"
},
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/build.gradle",
"new_path": "wiremock-webhooks-extension/build.gradle",
"diff": "@@ -93,3 +93,7 @@ publishing {\n}\npublish.dependsOn shadowJar\n+\n+task release {\n+ dependsOn clean, shadowJar, publishAllPublicationsToMavenRepository\n+}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed Gradle builds so that only maven central is pushed to on release and both the main project and the extension are pushed |
686,936 | 30.09.2021 17:50:29 | -3,600 | c4ece200f318a35a12f281cfc6bb2903800d904f | Simplified JUnit 5 nested test bug fix | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"diff": "@@ -26,6 +26,8 @@ import org.junit.platform.commons.support.AnnotationSupport;\nimport java.util.Optional;\n+import static com.google.common.base.MoreObjects.firstNonNull;\n+\npublic class WireMockExtension extends DslWrapper implements ParameterResolver, BeforeEachCallback, BeforeAllCallback, AfterEachCallback, AfterAllCallback {\nprivate static final Options DEFAULT_OPTIONS = WireMockConfiguration.options().dynamicPort();\n@@ -76,21 +78,8 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\n}\nprivate void startServerIfRequired(ExtensionContext extensionContext) {\n- if (wireMockServer == null) {\n- startNewServer(resolveOptions(extensionContext));\n- } else if (!wireMockServer.isRunning()) {\n- Optional<WireMockTest> annotation = findWireMockTestAnnotation(extensionContext);\n-\n- if (annotation.isPresent()) {\n- startNewServer(buildOptionsFromWireMockTestAnnotation(annotation.get()));\n- } else {\n- wireMockServer.start();\n- }\n- }\n- }\n-\n- private void startNewServer(Options options) {\n- wireMockServer = new WireMockServer(options);\n+ if (wireMockServer == null || !wireMockServer.isRunning()) {\n+ wireMockServer = new WireMockServer(resolveOptions(extensionContext));\nwireMockServer.start();\nthis.admin = wireMockServer;\n@@ -100,27 +89,25 @@ public class WireMockExtension extends DslWrapper implements ParameterResolver,\nWireMock.configureFor(new WireMock(this));\n}\n}\n+ }\nprivate void setAdditionalOptions(ExtensionContext extensionContext) {\nif (proxyMode == null) {\n- proxyMode = findWireMockTestAnnotation(extensionContext)\n+ proxyMode = extensionContext.getElement()\n+ .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, WireMockTest.class))\n.<Boolean>map(WireMockTest::proxyMode)\n.orElse(false);\n}\n}\nprivate Options resolveOptions(ExtensionContext extensionContext) {\n- return findWireMockTestAnnotation(extensionContext)\n+ return extensionContext.getElement()\n+ .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, WireMockTest.class))\n.<Options>map(this::buildOptionsFromWireMockTestAnnotation)\n.orElse(Optional.ofNullable(this.options)\n.orElse(DEFAULT_OPTIONS));\n}\n- private Optional<WireMockTest> findWireMockTestAnnotation(ExtensionContext extensionContext) {\n- return extensionContext.getElement()\n- .flatMap(annotatedElement -> AnnotationSupport.findAnnotation(annotatedElement, WireMockTest.class));\n- }\n-\nprivate Options buildOptionsFromWireMockTestAnnotation(WireMockTest annotation) {\nWireMockConfiguration options = WireMockConfiguration.options()\n.port(annotation.httpPort())\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JunitJupiterExtensionDeclarativeWithNestedTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JunitJupiterExtensionDeclarativeWithNestedTest.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.junit5;\n-import org.junit.jupiter.api.Disabled;\nimport org.junit.jupiter.api.Nested;\nimport org.junit.jupiter.api.Test;\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Simplified JUnit 5 nested test bug fix |
686,936 | 01.10.2021 14:38:34 | -3,600 | e128e056c7a071ca6543c62c25b96c9618a8bfe3 | Updated build.gradle POM generator for new GitHub SCM URLs | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -142,9 +142,9 @@ allprojects {\ndescription 'A web service test double for all occasions'\nurl 'http://wiremock.org'\nscm {\n- connection 'https://tomakehurst@github.com/tomakehurst/wiremock.git'\n- developerConnection 'https://tomakehurst@github.com/tomakehurst/wiremock.git'\n- url 'https://tomakehurst@github.com/tomakehurst/wiremock.git'\n+ connection 'https://github.com/wiremock/wiremock.git'\n+ developerConnection 'https://github.com/wiremock/wiremock.git'\n+ url 'https://github.com/wiremock/wiremock'\n}\nlicenses {\nlicense {\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Updated build.gradle POM generator for new GitHub SCM URLs |
686,936 | 01.10.2021 16:13:43 | -3,600 | b796707ab0e050814ddb1c2afeb2b2a21e2f6d65 | Fixed and - incorrect zoning of date/times in response templating when truncating | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/DateTimeParser.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/DateTimeParser.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.common;\n+import com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.RenderableDate;\n+\nimport java.time.*;\nimport java.time.format.DateTimeFormatter;\nimport java.time.temporal.ChronoField;\n@@ -113,9 +115,13 @@ public class DateTimeParser {\nreturn null;\n}\n- public Date parseDate(String dateTimeString) {\n+ public RenderableDate parseDate(String dateTimeString) {\nif (isUnix || isEpoch) {\n- return Date.from(parseZonedDateTime(dateTimeString).toInstant());\n+ return new RenderableDate(\n+ Date.from(parseZonedDateTime(dateTimeString).toInstant()),\n+ null,\n+ null\n+ );\n}\nif (dateTimeFormatter == null) {\n@@ -123,15 +129,19 @@ public class DateTimeParser {\n}\nfinal TemporalAccessor parseResult = dateTimeFormatter.parse(dateTimeString);\n- if (parseResult.query(TemporalQueries.zone()) != null) {\n- return Date.from(Instant.from(parseResult));\n- }\n+ final ZoneId timezoneId = parseResult.query(TemporalQueries.zone());\n+\n+ Date date;\n- if (parseResult.query(TemporalQueries.localTime()) != null) {\n- return Date.from(LocalDateTime.from(parseResult).toInstant(UTC));\n+ if (timezoneId != null) {\n+ date = Date.from(Instant.from(parseResult));\n+ } else if (parseResult.query(TemporalQueries.localTime()) != null) {\n+ date = Date.from(LocalDateTime.from(parseResult).toInstant(UTC));\n+ } else {\n+ date = Date.from(LocalDate.from(parseResult).atStartOfDay(UTC).toInstant());\n}\n- return Date.from(LocalDate.from(parseResult).atStartOfDay(UTC).toInstant());\n+ return new RenderableDate(date, null, timezoneId);\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/DateTimeTruncation.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/DateTimeTruncation.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.common;\n+import com.github.tomakehurst.wiremock.extension.responsetemplating.helpers.RenderableDate;\n+\n+import java.text.SimpleDateFormat;\n+import java.time.ZoneId;\nimport java.time.ZoneOffset;\nimport java.time.ZonedDateTime;\nimport java.time.temporal.TemporalAdjusters;\n@@ -49,8 +53,23 @@ public enum DateTimeTruncation {\n}\npublic Date truncate(Date input) {\n- final ZonedDateTime zonedInput = input.toInstant().atZone(UTC);\n- return Date.from(truncate(zonedInput).toInstant());\n+ ZoneId zoneId = getTimezone(input);\n+ final ZonedDateTime zonedInput = input.toInstant().atZone(zoneId);\n+ final Date date = Date.from(truncate(zonedInput).toInstant());\n+ return new RenderableDate(date, null, zoneId);\n+ }\n+\n+ private static ZoneId getTimezone(Date date) {\n+ if (date instanceof RenderableDate) {\n+ RenderableDate renderableDate = (RenderableDate) date;\n+ if (renderableDate.getTimezone() != null) {\n+ return renderableDate.getTimezone();\n+ }\n+\n+ return ZoneId.systemDefault();\n+ }\n+\n+ return UTC;\n}\n@Override\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/HandlebarsCurrentDateHelper.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/HandlebarsCurrentDateHelper.java",
"diff": "@@ -19,6 +19,7 @@ import com.github.jknack.handlebars.Options;\nimport com.github.tomakehurst.wiremock.common.DateTimeOffset;\nimport java.io.IOException;\n+import java.time.ZoneId;\nimport java.util.Date;\npublic class HandlebarsCurrentDateHelper extends HandlebarsHelper<Date> {\n@@ -29,11 +30,22 @@ public class HandlebarsCurrentDateHelper extends HandlebarsHelper<Date> {\nString offset = options.hash(\"offset\", null);\nString timezone = options.hash(\"timezone\", null);\n- Date date = context != null ? context : new Date();\n+ ZoneId zoneId;\n+ Date date;\n+\n+ if (context instanceof RenderableDate) {\n+ date = context;\n+ RenderableDate renderableDate = (RenderableDate) context;\n+ zoneId = renderableDate.getTimezone();\n+ } else {\n+ date = context != null ? context : new Date();\n+ zoneId = timezone != null ? ZoneId.of(timezone) : null;\n+ }\n+\nif (offset != null) {\ndate = DateTimeOffset.fromString(offset).shift(date);\n}\n- return new RenderableDate(date, format, timezone);\n+ return new RenderableDate(date, format, zoneId);\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/ParseDateHelper.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/ParseDateHelper.java",
"diff": "@@ -19,10 +19,7 @@ import com.github.jknack.handlebars.Options;\nimport com.github.tomakehurst.wiremock.common.DateTimeParser;\nimport java.io.IOException;\n-import java.time.LocalDate;\n-import java.time.LocalDateTime;\nimport java.time.format.DateTimeParseException;\n-import java.util.Date;\nimport java.util.List;\nimport static com.github.tomakehurst.wiremock.common.DateTimeParser.ZONED_PARSERS;\n@@ -39,16 +36,16 @@ public class ParseDateHelper extends HandlebarsHelper<String> {\nparseOrNull(dateTimeString, DateTimeParser.forFormat(format));\n}\n- private static Date parseOrNull(String dateTimeString) {\n+ private static RenderableDate parseOrNull(String dateTimeString) {\nreturn parseOrNull(dateTimeString, (DateTimeParser) null);\n}\n- private static Date parseOrNull(String dateTimeString, DateTimeParser parser) {\n+ private static RenderableDate parseOrNull(String dateTimeString, DateTimeParser parser) {\nfinal List<DateTimeParser> parsers = parser != null ? singletonList(parser) : ZONED_PARSERS;\nreturn parseOrNull(dateTimeString, parsers);\n}\n- private static Date parseOrNull(String dateTimeString, List<DateTimeParser> parsers) {\n+ private static RenderableDate parseOrNull(String dateTimeString, List<DateTimeParser> parsers) {\nif (parsers.isEmpty()) {\nreturn null;\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/RenderableDate.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/RenderableDate.java",
"diff": "@@ -18,6 +18,7 @@ package com.github.tomakehurst.wiremock.extension.responsetemplating.helpers;\nimport com.fasterxml.jackson.databind.util.ISO8601Utils;\nimport java.text.SimpleDateFormat;\n+import java.time.ZoneId;\nimport java.util.Date;\nimport java.util.TimeZone;\n@@ -25,12 +26,20 @@ public class RenderableDate extends Date {\nprivate static final long DIVIDE_MILLISECONDS_TO_SECONDS = 1000L;\nprivate final String format;\n- private final String timezoneName;\n+ private final ZoneId timezone;\n- public RenderableDate(Date date, String format, String timezone) {\n+ public RenderableDate(Date date, String format, ZoneId timezone) {\nsuper(date.getTime());\nthis.format = format;\n- this.timezoneName = timezone;\n+ this.timezone = timezone;\n+ }\n+\n+ public String getFormat() {\n+ return format;\n+ }\n+\n+ public ZoneId getTimezone() {\n+ return timezone;\n}\n@Override\n@@ -47,15 +56,15 @@ public class RenderableDate extends Date {\nreturn formatCustom();\n}\n- return timezoneName != null ?\n- ISO8601Utils.format(this, false, TimeZone.getTimeZone(timezoneName)) :\n+ return timezone != null ?\n+ ISO8601Utils.format(this, false, TimeZone.getTimeZone(timezone)) :\nISO8601Utils.format(this, false);\n}\nprivate String formatCustom() {\nSimpleDateFormat dateFormat = new SimpleDateFormat(format);\n- if (timezoneName != null) {\n- TimeZone zone = TimeZone.getTimeZone(timezoneName);\n+ if (timezone != null) {\n+ TimeZone zone = TimeZone.getTimeZone(timezone);\ndateFormat.setTimeZone(zone);\n}\nreturn dateFormat.format(this);\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/extension/responsetemplating/ResponseTemplateTransformerTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/extension/responsetemplating/ResponseTemplateTransformerTest.java",
"diff": "@@ -33,6 +33,7 @@ import java.io.IOException;\nimport java.time.Instant;\nimport java.time.LocalDate;\nimport java.time.ZonedDateTime;\n+import java.time.temporal.ChronoUnit;\nimport java.time.temporal.TemporalAdjusters;\nimport java.util.HashSet;\nimport java.util.List;\n@@ -42,6 +43,7 @@ import java.util.concurrent.ThreadLocalRandom;\nimport static com.github.tomakehurst.wiremock.client.WireMock.*;\nimport static com.github.tomakehurst.wiremock.matching.MockRequest.mockRequest;\nimport static com.github.tomakehurst.wiremock.testsupport.NoFileSource.noFileSource;\n+import static java.time.temporal.ChronoUnit.DAYS;\nimport static org.hamcrest.Matchers.*;\nimport static org.junit.Assert.assertNotNull;\nimport static org.hamcrest.MatcherAssert.assertThat;\n@@ -1047,13 +1049,25 @@ public class ResponseTemplateTransformerTest {\n}\n@Test\n- public void canTruncateARenderableDate() {\n+ public void canTruncateARenderableDateToFirstOfMonth() {\nString result = transform(\"{{date (truncateDate (now) 'first day of month') format='yyyy-MM-dd'}}\");\nString expectedDate = ZonedDateTime.now().with(TemporalAdjusters.firstDayOfMonth()).toLocalDate().toString();\nassertThat(result, is(expectedDate));\n}\n+ @Test\n+ public void canTruncateARenderableDateToFirstHourOfDay() {\n+ String result = transform(\"{{date (truncateDate (now) 'first hour of day') format='yyyy-MM-dd\\\\'T\\\\'HH:mm'}}\");\n+\n+ String expectedDate = ZonedDateTime.now().truncatedTo(DAYS).toLocalDateTime().toString();\n+\n+ System.out.println(System.getProperty(\"user.timezone\"));\n+ System.out.println(\"expected: \" + expectedDate + \", actual: \" + result);\n+\n+ assertThat(result, is(expectedDate));\n+ }\n+\nprivate Integer transformToInt(String responseBodyTemplate) {\nreturn Integer.parseInt(transform(responseBodyTemplate));\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed #1608 and #1585 - incorrect zoning of date/times in response templating when truncating |
686,996 | 01.10.2021 18:24:28 | -10,800 | 6ef156668a25ff9f175a8c11debaa31ca68d0f1c | prevent applying scientific notation and rounding to big numbers by ObjectMapper | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/Json.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/Json.java",
"diff": "@@ -21,9 +21,11 @@ import java.io.IOException;\nimport java.util.Map;\nimport com.fasterxml.jackson.annotation.JsonInclude;\n+import com.fasterxml.jackson.core.JsonGenerator;\nimport com.fasterxml.jackson.core.JsonParser;\nimport com.fasterxml.jackson.core.JsonProcessingException;\nimport com.fasterxml.jackson.core.type.TypeReference;\n+import com.fasterxml.jackson.databind.DeserializationFeature;\nimport com.fasterxml.jackson.databind.JsonNode;\nimport com.fasterxml.jackson.databind.ObjectMapper;\nimport com.fasterxml.jackson.databind.ObjectWriter;\n@@ -41,6 +43,8 @@ public final class Json {\nobjectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);\nobjectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);\nobjectMapper.configure(JsonParser.Feature.IGNORE_UNDEFINED, true);\n+ objectMapper.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true);\n+ objectMapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);\nreturn objectMapper;\n}\n};\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/MappingsAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/MappingsAcceptanceTest.java",
"diff": "@@ -145,7 +145,7 @@ public class MappingsAcceptanceTest extends AcceptanceTestBase {\npublic void readsJsonMapping() {\nWireMockResponse response = testClient.get(\"/testjsonmapping\");\nassertThat(response.statusCode(), is(200));\n- assertThat(response.content(), is(\"{\\\"key\\\":\\\"value\\\",\\\"array\\\":[1,2,3]}\"));\n+ assertThat(response.content(), is(\"{\\\"key\\\":\\\"value\\\",\\\"array\\\":[1,2,3],\\\"bignumber\\\":1234567890.12}\"));\n}\n@Test\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/resources/test-file-root/mappings/testjsonmapping.json",
"new_path": "src/test/resources/test-file-root/mappings/testjsonmapping.json",
"diff": "\"status\": 200,\n\"jsonBody\": {\n\"key\": \"value\",\n- \"array\": [1, 2, 3]\n+ \"array\": [1, 2, 3],\n+ \"bignumber\": 1234567890.12\n},\n\"headers\": {\n\"Content-Type\": \"application/json\"\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | #1612 prevent applying scientific notation and rounding to big numbers by ObjectMapper (#1613) |
686,936 | 01.10.2021 16:37:36 | -3,600 | 87fe6cca95925a873c20b2389bdf310e4e99b9a2 | Upgraded to Jetty 9.4.44.v20210927 | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -23,7 +23,7 @@ group = 'com.github.tomakehurst'\ndef versions = [\nhandlebars : '4.2.1',\n- jetty : '9.4.43.v20210629',\n+ jetty : '9.4.44.v20210927',\nguava : '31.0.1-jre',\njackson : '2.13.0',\nxmlUnit : '2.8.2',\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/TrailingSlashFilter.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/TrailingSlashFilter.java",
"diff": "@@ -65,11 +65,19 @@ public class TrailingSlashFilter implements Filter {\n}\nprivate String getPathPartFromLocation(String location) throws IOException {\n+ if (isRelativePath(location)) {\n+ return location;\n+ }\n+\nURL url = new URL(location);\nreturn url.getPath();\n}\n}\n+ private static boolean isRelativePath(String location) {\n+ return location.matches(\"^/[^/]{1}.*\");\n+ }\n+\nprivate String getRequestPathFrom(HttpServletRequest httpServletRequest) throws ServletException {\ntry {\nString fullPath = new URI(URLEncoder.encode(httpServletRequest.getRequestURI(), \"utf-8\")).getPath();\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Upgraded to Jetty 9.4.44.v20210927 |
686,936 | 06.10.2021 15:32:38 | -3,600 | 9e80ce73216850d6c06e1bcd2b51f9ea41086caa | Switched the stub persistent field to a Boolean object and tweaked the retrieval logic so that it can be stored as non-null and false | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/client/BasicMappingBuilder.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/client/BasicMappingBuilder.java",
"diff": "@@ -44,7 +44,7 @@ class BasicMappingBuilder implements ScenarioMappingBuilder {\nprivate String newScenarioState;\nprivate UUID id = UUID.randomUUID();\nprivate String name;\n- private boolean isPersistent = false;\n+ private Boolean isPersistent = null;\nprivate List<PostServeActionDefinition> postServeActions = newArrayList();\nprivate Metadata metadata;\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/StubMapping.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/StubMapping.java",
"diff": "@@ -41,7 +41,7 @@ public class StubMapping {\nprivate UUID uuid = UUID.randomUUID();\nprivate String name;\n- private boolean persistent;\n+ private Boolean persistent;\nprivate RequestPattern request;\nprivate ResponseDefinition response;\n@@ -102,15 +102,15 @@ public class StubMapping {\n}\npublic boolean shouldBePersisted() {\n- return persistent;\n+ return persistent != null && persistent;\n}\npublic Boolean isPersistent() {\n- return persistent ? true : null;\n+ return persistent;\n}\npublic void setPersistent(Boolean persistent) {\n- this.persistent = persistent != null && persistent;\n+ this.persistent = persistent;\n}\npublic RequestPattern getRequest() {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/StubMappingPersistenceAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/StubMappingPersistenceAcceptanceTest.java",
"diff": "@@ -39,6 +39,7 @@ import static com.github.tomakehurst.wiremock.testsupport.WireMatchers.hasFileCo\nimport static com.google.common.base.Charsets.UTF_8;\nimport static org.hamcrest.Matchers.is;\nimport static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.notNullValue;\npublic class StubMappingPersistenceAcceptanceTest {\n@@ -208,6 +209,16 @@ public class StubMappingPersistenceAcceptanceTest {\nassertThat(mappingFilePath.toFile().exists(), is(false));\n}\n+ @Test\n+ public void preservesPersistentFlagFalseValue() {\n+ UUID id = wm.stubFor(get(\"/no-persist\").persistent(false)).getId();\n+\n+ StubMapping retrivedStub = wm.getSingleStubMapping(id);\n+\n+ assertThat(retrivedStub.isPersistent(), notNullValue());\n+ assertThat(retrivedStub.isPersistent(), is(false));\n+ }\n+\nprivate void writeMappingFile(String name, MappingBuilder stubBuilder) throws IOException {\nbyte[] json = Json.write(stubBuilder.build()).getBytes(UTF_8);\nFiles.write(mappingsDir.resolve(name), json);\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Switched the stub persistent field to a Boolean object and tweaked the retrieval logic so that it can be stored as non-null and false |
686,994 | 11.10.2021 15:21:15 | -7,200 | eda4d2aa9206d6e24751fab8ad91f3c9a4320e08 | Publish test results from forks | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -56,18 +56,3 @@ jobs:\npath: |\nwiremock-webhooks-extension/build/reports/tests/test\nwiremock-webhooks-extension/build/test-results/test\n-\n- publish-test-results:\n- name: \"Publish Unit Test Results\"\n- needs: build\n- runs-on: ubuntu-latest\n- # the build job might be skipped, we don't need to run this job then\n- if: success() || failure()\n-\n- steps:\n- - name: Download Artifacts\n- uses: actions/download-artifact@v2\n- - name: Publish Unit Test Results\n- uses: EnricoMi/publish-unit-test-result-action/composite@v1\n- with:\n- files: '**/*.xml'\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": ".github/workflows/publish-test-results.yml",
"diff": "+name: Publish Test Results\n+\n+on:\n+ workflow_run:\n+ workflows: [\"CI\"]\n+ types:\n+ - completed\n+\n+jobs:\n+ unit-test-results:\n+ name: Unit Test Results\n+ runs-on: ubuntu-latest\n+ if: github.event.workflow_run.conclusion != 'skipped'\n+\n+ steps:\n+ - name: Download and Extract Artifacts\n+ env:\n+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}\n+ run: |\n+ mkdir -p artifacts && cd artifacts\n+\n+ artifacts_url=${{ github.event.workflow_run.artifacts_url }}\n+\n+ gh api \"$artifacts_url\" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact\n+ do\n+ IFS=$'\\t' read name url <<< \"$artifact\"\n+ gh api $url > \"$name.zip\"\n+ unzip -d \"$name\" \"$name.zip\"\n+ done\n+\n+ - name: Publish Unit Test Results\n+ uses: EnricoMi/publish-unit-test-result-action@v1\n+ with:\n+ commit: ${{ github.event.workflow_run.head_sha }}\n+ event_file: artifacts/Event File/event.json\n+ event_name: ${{ github.event.workflow_run.event }}\n+ files: \"artifacts/**/*.xml\"\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Publish test results from forks (#1631) |
686,936 | 10.10.2021 19:28:16 | -3,600 | 327ce027126fbb8fff9badb8a8c8e5241398800e | Added Sonarqube Gradle and Actions config | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -37,7 +37,29 @@ jobs:\nnode-version: 8.12.0\n- name: Pre-generate API docs\nrun: ./gradlew classes testClasses -x generateApiDocs\n+\n+ - name: Cache SonarCloud packages\n+ uses: actions/cache@v1\n+ with:\n+ path: ~/.sonar/cache\n+ key: ${{ runner.os }}-sonar\n+ restore-keys: ${{ runner.os }}-sonar\n+ - name: Cache Gradle packages\n+ uses: actions/cache@v1\n+ with:\n+ path: ~/.gradle/caches\n+ key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}\n+ restore-keys: ${{ runner.os }}-gradle\n+\n+ - name: Test WireMock with Sonarqube\n+ if: ${{ matrix.os == 'ubuntu-latest' && matrix.jdk == 11 }}\n+ env:\n+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any\n+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}\n+ run: ./gradlew check sonarqube --stacktrace --no-daemon\n+\n- name: Test WireMock\n+ if: ${{ !(matrix.os == 'ubuntu-latest' && matrix.jdk == 11) }}\nrun: ./gradlew check --stacktrace --no-daemon\n- name: Archive WireMock test report - ${{ matrix.os }} JDK ${{ matrix.jdk }}\n"
},
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -17,6 +17,8 @@ plugins {\nid 'eclipse'\nid 'project-report'\nid 'com.github.johnrengelman.shadow' version '6.1.0'\n+ id \"org.sonarqube\" version \"3.3\"\n+ id 'jacoco'\n}\ngroup = 'com.github.tomakehurst'\n@@ -190,6 +192,12 @@ allprojects {\n}\n}\n+ jacocoTestReport {\n+ reports {\n+ xml.enabled true\n+ }\n+ }\n+ test.finalizedBy jacocoTestReport\n}\njava {\n@@ -395,6 +403,14 @@ task release {\ndependsOn clean, jar, shadowJar, publishAllPublicationsToMavenRepository, addGitTag\n}\n+sonarqube {\n+ properties {\n+ property \"sonar.projectKey\", \"wiremock_wiremock\"\n+ property \"sonar.organization\", \"wiremock\"\n+ property \"sonar.host.url\", \"https://sonarcloud.io\"\n+ }\n+}\n+\ntask 'bump-patch-version' {\ndoLast {\ndef filesWithVersion = [\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added Sonarqube Gradle and Actions config |
686,936 | 15.10.2021 07:53:29 | -3,600 | 7c7a2a74e69f929d47eccbf435ec35673b7c82f6 | Retrict sonarqube to push only as the credentials aren't available to pull requests | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -52,14 +52,14 @@ jobs:\nrestore-keys: ${{ runner.os }}-gradle\n- name: Test WireMock with Sonarqube\n- if: ${{ matrix.os == 'ubuntu-latest' && matrix.jdk == 11 }}\n+ if: ${{ matrix.os == 'ubuntu-latest' && matrix.jdk == 11 && github.event_name == 'push' }}\nenv:\nGITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any\nSONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}\nrun: ./gradlew check sonarqube --stacktrace --no-daemon\n- name: Test WireMock\n- if: ${{ !(matrix.os == 'ubuntu-latest' && matrix.jdk == 11) }}\n+ if: ${{ !(matrix.os == 'ubuntu-latest' && matrix.jdk == 11 && github.event_name == 'push') }}\nrun: ./gradlew check --stacktrace --no-daemon\n- name: Archive WireMock test report - ${{ matrix.os }} JDK ${{ matrix.jdk }}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Retrict sonarqube to push only as the credentials aren't available to pull requests |
686,994 | 15.10.2021 14:48:27 | -7,200 | 12be0442fb8c903ae11ae49b8e270b5cb55ee7d1 | Resolve merge conflicts & rename violation store file | [
{
"change_type": "RENAME",
"old_path": "src/test/resources/frozen/978ef757-03ab-4f46-9cc7-583f3112305c",
"new_path": "src/test/resources/frozen/do-not-throw-generic-exception",
"diff": "@@ -7,8 +7,8 @@ Method <com.github.tomakehurst.wiremock.common.AbstractFileSource.writeTextFileA\nMethod <com.github.tomakehurst.wiremock.common.ClasspathFileSource.assertExistsAndIsDirectory()> calls constructor <java.lang.RuntimeException.<init>(java.lang.String)> in (ClasspathFileSource.java:212)\nMethod <com.github.tomakehurst.wiremock.common.ClasspathFileSource.assertExistsAndIsDirectory()> calls constructor <java.lang.RuntimeException.<init>(java.lang.String)> in (ClasspathFileSource.java:214)\nMethod <com.github.tomakehurst.wiremock.common.ClasspathFileSource.getZipEntryUri(java.lang.String)> calls constructor <java.lang.RuntimeException.<init>(java.lang.String)> in (ClasspathFileSource.java:114)\n-Method <com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAsByteArrayAndCloseStream(org.apache.http.HttpResponse)> calls constructor <java.lang.RuntimeException.<init>(java.lang.Throwable)> in (HttpClientUtils.java:51)\n-Method <com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAsStringAndCloseStream(org.apache.http.HttpResponse)> calls constructor <java.lang.RuntimeException.<init>(java.lang.Throwable)> in (HttpClientUtils.java:36)\n+Method <com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAsByteArrayAndCloseStream(org.apache.hc.core5.http.ClassicHttpResponse)> calls constructor <java.lang.RuntimeException.<init>(java.lang.Throwable)> in (HttpClientUtils.java:52)\n+Method <com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAsStringAndCloseStream(org.apache.hc.core5.http.ClassicHttpResponse)> calls constructor <java.lang.RuntimeException.<init>(java.lang.Throwable)> in (HttpClientUtils.java:37)\nMethod <com.github.tomakehurst.wiremock.common.StreamSources$3.getStream()> calls constructor <java.lang.RuntimeException.<init>(java.lang.Throwable)> in (StreamSources.java:51)\nMethod <com.github.tomakehurst.wiremock.http.Response.getBody()> calls constructor <java.lang.RuntimeException.<init>(java.lang.Throwable)> in (Response.java:112)\nMethod <com.github.tomakehurst.wiremock.jetty9.JettyHttpServer.start()> calls constructor <java.lang.RuntimeException.<init>(java.lang.String)> in (JettyHttpServer.java:208)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/resources/frozen/stored.rules",
"new_path": "src/test/resources/frozen/stored.rules",
"diff": "-#Mon Oct 11 02:33:15 AEDT 2021\n-no\\ classes\\ should\\ throw\\ generic\\ exceptions=978ef757-03ab-4f46-9cc7-583f3112305c\n#Fri Oct 15 19:25:52 AEDT 2021\n+no\\ classes\\ should\\ throw\\ generic\\ exceptions=do-not-throw-generic-exception\nshould\\ use\\ all\\ non\\ public\\ methods,\\ because\\ unused\\ methods\\ should\\ be\\ removed=unused-methods\nClassRule\\ should\\ not\\ be\\ used,\\ because\\ we\\ want\\ to\\ migrate\\ to\\ JUnit\\ Jupiter=do-not-use-classrule\nRule\\ should\\ not\\ be\\ used,\\ because\\ we\\ want\\ to\\ migrate\\ to\\ JUnit\\ Jupiter=do-not-use-rule\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Resolve merge conflicts & rename violation store file (#1650) |
686,936 | 15.10.2021 15:45:44 | -3,600 | d4b6307efdfa15b15ee791abc81547136985506a | Moved the sonarqube task into the allprojects build block in the hope that this will allow coverage reports to be published for the webhooks sub-project | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -198,6 +198,14 @@ allprojects {\n}\n}\ntest.finalizedBy jacocoTestReport\n+\n+ sonarqube {\n+ properties {\n+ property \"sonar.projectKey\", \"wiremock_wiremock\"\n+ property \"sonar.organization\", \"wiremock\"\n+ property \"sonar.host.url\", \"https://sonarcloud.io\"\n+ }\n+ }\n}\njava {\n@@ -400,14 +408,6 @@ task release {\ndependsOn clean, jar, shadowJar, publishAllPublicationsToMavenRepository, addGitTag\n}\n-sonarqube {\n- properties {\n- property \"sonar.projectKey\", \"wiremock_wiremock\"\n- property \"sonar.organization\", \"wiremock\"\n- property \"sonar.host.url\", \"https://sonarcloud.io\"\n- }\n-}\n-\ntask 'bump-patch-version' {\ndoLast {\ndef filesWithVersion = [\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Moved the sonarqube task into the allprojects build block in the hope that this will allow coverage reports to be published for the webhooks sub-project |
686,955 | 21.10.2021 01:17:05 | -32,400 | 8e78b3a48126d91fe50245b4963a51680fe343b8 | testCompile -> testImplementation in docs | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/download-and-installation.md",
"new_path": "docs-v2/_docs/download-and-installation.md",
"diff": "@@ -74,25 +74,25 @@ Java 7 standalone (deprecated):\nJava 8:\n```groovy\n-testCompile \"com.github.tomakehurst:wiremock-jre8:{{ site.wiremock_version }}\"\n+testImplementation \"com.github.tomakehurst:wiremock:{{ site.wiremock_version }}\"\n```\nJava 8 standalone:\n```groovy\n-testCompile \"com.github.tomakehurst:wiremock-jre8-standalone:{{ site.wiremock_version }}\"\n+testImplementation \"com.github.tomakehurst:wiremock-standalone:{{ site.wiremock_version }}\"\n```\nJava 7 (deprecated):\n```groovy\n-testCompile \"com.github.tomakehurst:wiremock:2.27.2\"\n+testImplementation \"com.github.tomakehurst:wiremock-jre8:{{ site.wiremock_version }}\"\n```\nJava 7 standalone (deprecated):\n```groovy\n-testCompile \"com.github.tomakehurst:wiremock-standalone:2.27.2\"\n+testImplementation \"com.github.tomakehurst:wiremock-jre8-standalone:{{ site.wiremock_version }}\"\n```\n## Direct download\n"
},
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/getting-started.md",
"new_path": "docs-v2/_docs/getting-started.md",
"diff": "@@ -26,7 +26,7 @@ To add the standard WireMock JAR as a project dependency, put the following in t\n### Gradle\n```groovy\n-testCompile \"com.github.tomakehurst:wiremock-jre8:{{ site.wiremock_version }}\"\n+testImplementation \"com.github.tomakehurst:wiremock-jre8:{{ site.wiremock_version }}\"\n```\nWireMock is also shipped in Java 7 and standalone versions, both of which work better in certain contexts.\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | testCompile -> testImplementation in docs (#1086)
Co-authored-by: Tom Akehurst <t.m.akehurst@googlemail.com> |
686,982 | 21.10.2021 16:55:31 | -7,200 | 01178a8b2719c7633beebd3a4e3e7ea3b95a89eb | Recognize multipart/related and multipart/mixed | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WireMockHttpServletRequestAdapter.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WireMockHttpServletRequestAdapter.java",
"diff": "@@ -286,7 +286,7 @@ public class WireMockHttpServletRequestAdapter implements Request {\n@Override\npublic boolean isMultipart() {\nString header = getHeader(\"Content-Type\");\n- return (header != null && header.contains(\"multipart/form-data\"));\n+ return (header != null && header.contains(\"multipart/\"));\n}\n@Override\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/MultipartBodyMatchingAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/MultipartBodyMatchingAcceptanceTest.java",
"diff": "@@ -87,21 +87,68 @@ public class MultipartBodyMatchingAcceptanceTest extends AcceptanceTestBase {\nassertThat(response.getStatusLine().getStatusCode(), is(404));\n}\n+ /**\n+ * @see <a href=\"https://github.com/tomakehurst/wiremock/issues/1047\">#1047</a>\n+ */\n@Test\n- public void doesNotFailWithMultipartMixedRequest() throws Exception {\n+ public void acceptsAMultipartMixedRequestContainingATextAndAFilePart() throws Exception {\nstubFor(post(\"/multipart-mixed\")\n+ .withMultipartRequestBody(aMultipart()\n+ .withName(\"text\")\n+ .withBody(containing(\"hello\")))\n+ .withMultipartRequestBody(aMultipart()\n+ .withName(\"file\")\n+ .withBody(binaryEqualTo(\"ABCD\".getBytes())))\n.willReturn(ok())\n);\nHttpUriRequest request = RequestBuilder\n.post(wireMockServer.baseUrl() + \"/multipart-mixed\")\n- .setHeader(\"Content-Type\", \"multipart/mixed; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\")\n- .setEntity(new StringEntity(\"\", ContentType.create(\"multipart/mixed\")))\n+ .setEntity(MultipartEntityBuilder.create()\n+ .setMimeSubtype(\"mixed\")\n+ .addTextBody(\"text\", \"hello\")\n+ .addBinaryBody(\"file\", \"ABCD\".getBytes())\n+ .build()\n+ )\n.build();\nHttpResponse response = httpClient.execute(request);\n- assertThat(response.getStatusLine().getStatusCode(), is(200));\n+ assertThat(\n+ EntityUtils.toString(response.getEntity()),\n+ response.getStatusLine().getStatusCode(), is(200));\n+ }\n+\n+ /**\n+ * @see <a href=\"https://github.com/tomakehurst/wiremock/issues/1047\">#1047</a>\n+ */\n+ @Test\n+ public void acceptsAMultipartRelatedRequestContainingATextAndAFilePart() throws Exception {\n+ stubFor(post(\"/multipart-related\")\n+ .withMultipartRequestBody(aMultipart()\n+ .withName(\"text\")\n+ .withBody(containing(\"hello\")))\n+ .withMultipartRequestBody(aMultipart()\n+ .withName(\"file\")\n+ .withBody(binaryEqualTo(\"ABCD\".getBytes())))\n+ .willReturn(ok())\n+ );\n+\n+ HttpUriRequest request = RequestBuilder\n+ .post(wireMockServer.baseUrl() + \"/multipart-related\")\n+ .setEntity(MultipartEntityBuilder.create()\n+ .setMimeSubtype(\"related\")\n+ .addTextBody(\"text\", \"hello\")\n+ .addBinaryBody(\"file\", \"ABCD\".getBytes())\n+ .build()\n+ )\n+ .build();\n+\n+ HttpResponse response = httpClient.execute(request);\n+\n+ assertThat(\n+ EntityUtils.toString(response.getEntity()),\n+ response.getStatusLine().getStatusCode(), is(200));\n}\n// https://github.com/tomakehurst/wiremock/issues/1179\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Recognize multipart/related and multipart/mixed (#1415) |
686,936 | 22.10.2021 15:11:56 | -3,600 | 5303f8db65dd9b8165dab2d88d2b7441c6e3959f | Removed dependence on Conscrypt for ALPN and HTTP/2 | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -40,13 +40,10 @@ dependencies {\ncompile \"org.eclipse.jetty:jetty-proxy:$versions.jetty\"\ncompile \"org.eclipse.jetty.http2:http2-server:$versions.jetty\"\ncompile \"org.eclipse.jetty:jetty-alpn-server:$versions.jetty\"\n- compile \"org.eclipse.jetty:jetty-alpn-conscrypt-server:$versions.jetty\", {\n- exclude group: 'org.conscrypt'\n- }\n- compile \"org.eclipse.jetty:jetty-alpn-conscrypt-client:$versions.jetty\", {\n- exclude group: 'org.conscrypt'\n- }\n- compile 'org.conscrypt:conscrypt-openjdk-uber:2.5.2'\n+ compile \"org.eclipse.jetty:jetty-alpn-java-server:$versions.jetty\"\n+ compile \"org.eclipse.jetty:jetty-alpn-openjdk8-server:$versions.jetty\"\n+ compile \"org.eclipse.jetty:jetty-alpn-java-client:$versions.jetty\"\n+ compile \"org.eclipse.jetty:jetty-alpn-openjdk8-client:$versions.jetty\"\ncompile \"com.google.guava:guava:$versions.guava\"\ncompile \"com.fasterxml.jackson.core:jackson-core:$versions.jackson\",\n@@ -278,6 +275,7 @@ shadowJar {\nrelocate \"org.antlr\", \"wiremock.org.antlr\"\nrelocate \"javax.servlet\", \"wiremock.javax.servlet\"\nrelocate \"org.checkerframework\", \"wiremock.org.checkerframework\"\n+ relocate \"org.hamcrest\", \"wiremock.org.hamcrest\"\ndependencies {\nexclude(dependency('junit:junit'))\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/jetty94/SslContexts.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/jetty94/SslContexts.java",
"diff": "@@ -43,7 +43,6 @@ public class SslContexts {\nsslContextFactory.setKeyManagerPassword(httpsSettings.keyManagerPassword());\nsetupClientAuth(sslContextFactory, httpsSettings);\nsslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);\n- sslContextFactory.setProvider(\"Conscrypt\");\nreturn sslContextFactory;\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/Http2ClientFactory.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/Http2ClientFactory.java",
"diff": "@@ -26,7 +26,6 @@ public class Http2ClientFactory {\npublic static HttpClient create() {\nSslContextFactory sslContextFactory = new SslContextFactory.Client(true);\n- sslContextFactory.setProvider(\"Conscrypt\");\nHttpClientTransport transport = new HttpClientTransportOverHTTP2(\nnew HTTP2Client());\nHttpClient httpClient = new HttpClient(transport, sslContextFactory);\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Removed dependence on Conscrypt for ALPN and HTTP/2 |
686,990 | 18.05.2021 10:59:11 | -7,200 | c03ee51d2688b28689155d731984d91daa71ceb1 | Leave optimize factories loading enabled by default, for backwards compatibility
Remove no longer used org.mortbay.log.class system property setting | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/xml/XmlDocument.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/xml/XmlDocument.java",
"diff": "package com.github.tomakehurst.wiremock.common.xml;\nimport com.github.tomakehurst.wiremock.common.ListOrSingle;\n-import org.custommonkey.xmlunit.SimpleNamespaceContext;\n-import org.custommonkey.xmlunit.jaxp13.XMLUnitNamespaceContext2Jaxp13;\nimport org.w3c.dom.Document;\nimport org.w3c.dom.NodeList;\nimport org.xmlunit.util.Convert;\nimport javax.xml.XMLConstants;\nimport javax.xml.namespace.NamespaceContext;\n-import javax.xml.transform.Transformer;\nimport javax.xml.transform.dom.DOMSource;\n-import javax.xml.transform.stream.StreamResult;\nimport javax.xml.xpath.XPath;\nimport javax.xml.xpath.XPathExpressionException;\n-import java.io.StringWriter;\nimport java.util.HashMap;\n-import java.util.Iterator;\nimport java.util.Map;\n-import static com.github.tomakehurst.wiremock.common.Exceptions.throwUnchecked;\nimport static javax.xml.xpath.XPathConstants.NODESET;\npublic class XmlDocument extends XmlNode {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/Options.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/Options.java",
"diff": "@@ -41,6 +41,7 @@ public interface Options {\nint DEFAULT_PORT = 8080;\nint DYNAMIC_PORT = 0;\n+ int DEFAULT_TIMEOUT = 300_000;\nint DEFAULT_CONTAINER_THREADS = 25;\nString DEFAULT_BIND_ADDRESS = \"0.0.0.0\";\n@@ -79,4 +80,6 @@ public interface Options {\nboolean getGzipDisabled();\nboolean getStubRequestLoggingDisabled();\nboolean getStubCorsEnabled();\n+ long timeout();\n+ boolean getDisableOptimizeXmlFactoriesLoading();\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"diff": "@@ -38,6 +38,7 @@ import com.google.common.base.Optional;\nimport com.google.common.base.Predicate;\nimport com.google.common.collect.FluentIterable;\nimport com.google.common.collect.ImmutableList;\n+import org.apache.commons.lang3.mutable.MutableBoolean;\nimport java.util.Collections;\nimport java.util.List;\n@@ -56,6 +57,7 @@ public class WireMockApp implements StubServer, Admin {\npublic static final String FILES_ROOT = \"__files\";\npublic static final String ADMIN_CONTEXT_ROOT = \"/__admin\";\npublic static final String MAPPINGS_ROOT = \"mappings\";\n+ private static final MutableBoolean FACTORIES_LOADING_OPTIMIZED = new MutableBoolean(false);\nprivate final Scenarios scenarios;\nprivate final StubMappings stubMappings;\n@@ -71,11 +73,12 @@ public class WireMockApp implements StubServer, Admin {\nprivate Options options;\n- static {\n+ public WireMockApp(Options options, Container container) {\n+ if (!options.getDisableOptimizeXmlFactoriesLoading() && FACTORIES_LOADING_OPTIMIZED.isFalse()) {\nXml.optimizeFactoriesLoading();\n+ FACTORIES_LOADING_OPTIMIZED.setTrue();\n}\n- public WireMockApp(Options options, Container container) {\nthis.options = options;\nFileSource fileSource = options.filesRoot();\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"diff": "@@ -54,6 +54,8 @@ import static java.util.Collections.emptyList;\npublic class WireMockConfiguration implements Options {\n+ private long timeout = DEFAULT_TIMEOUT;\n+ private boolean disableOptimizeXmlFactoriesLoading = false;\nprivate int portNumber = DEFAULT_PORT;\nprivate boolean httpDisabled = false;\nprivate String bindAddress = DEFAULT_BIND_ADDRESS;\n@@ -129,6 +131,11 @@ public class WireMockConfiguration implements Options {\nreturn wireMockConfig();\n}\n+ public WireMockConfiguration timeout(int timeout) {\n+ this.timeout = timeout;\n+ return this;\n+ }\n+\npublic WireMockConfiguration port(int portNumber) {\nthis.portNumber = portNumber;\nreturn this;\n@@ -582,6 +589,21 @@ public class WireMockConfiguration implements Options {\nreturn stubCorsEnabled;\n}\n+ @Override\n+ public long timeout() {\n+ return timeout;\n+ }\n+\n+ @Override\n+ public boolean getDisableOptimizeXmlFactoriesLoading() {\n+ return disableOptimizeXmlFactoriesLoading;\n+ }\n+\n+ public WireMockConfiguration disableOptimizeXmlFactoriesLoading(boolean disableOptimizeXmlFactoriesLoading) {\n+ this.disableOptimizeXmlFactoriesLoading = disableOptimizeXmlFactoriesLoading;\n+ return this;\n+ }\n+\n@Override\npublic BrowserProxySettings browserProxySettings() {\nKeyStoreSettings keyStoreSettings = caKeyStoreSettings != null ?\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/jetty9/JettyHttpServer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/jetty9/JettyHttpServer.java",
"diff": "@@ -31,6 +31,7 @@ import org.apache.commons.lang3.ArrayUtils;\nimport org.eclipse.jetty.http.MimeTypes;\nimport org.eclipse.jetty.io.NetworkTrafficListener;\nimport org.eclipse.jetty.server.*;\n+import org.eclipse.jetty.server.handler.AbstractHandler;\nimport org.eclipse.jetty.server.handler.HandlerCollection;\nimport org.eclipse.jetty.server.handler.HandlerWrapper;\nimport org.eclipse.jetty.servlet.DefaultServlet;\n@@ -41,6 +42,8 @@ import org.eclipse.jetty.servlets.CrossOriginFilter;\nimport org.eclipse.jetty.util.ssl.SslContextFactory;\nimport javax.servlet.DispatcherType;\n+import javax.servlet.http.HttpServletRequest;\n+import javax.servlet.http.HttpServletResponse;\nimport java.lang.reflect.Method;\nimport java.net.Socket;\nimport java.nio.ByteBuffer;\n@@ -57,7 +60,6 @@ public class JettyHttpServer implements HttpServer {\nprivate static final int DEFAULT_ACCEPTORS = 3;\nstatic {\n- System.setProperty(\"org.eclipse.jetty.server.HttpChannelState.DEFAULT_TIMEOUT\", \"300000\");\nSystem.setProperty(\"org.eclipse.jetty.http.HttpGenerator.STRICT\", \"true\");\n}\n@@ -102,7 +104,13 @@ public class JettyHttpServer implements HttpServer {\napplyAdditionalServerConfiguration(jettyServer, options);\n- jettyServer.setHandler(createHandler(options, adminRequestHandler, stubRequestHandler));\n+ final HandlerCollection handlers = createHandler(options, adminRequestHandler, stubRequestHandler);\n+ jettyServer.setHandler(new HandlerCollection(ArrayUtils.insert(0, handlers.getHandlers(), new AbstractHandler() {\n+ @Override\n+ public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) {\n+ baseRequest.getHttpChannel().getState().setTimeout(options.timeout());\n+ }\n+ })));\nfinalizeSetup(options);\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WarConfiguration.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WarConfiguration.java",
"diff": "@@ -200,6 +200,16 @@ public class WarConfiguration implements Options {\nreturn false;\n}\n+ @Override\n+ public long timeout() {\n+ return 0;\n+ }\n+\n+ @Override\n+ public boolean getDisableOptimizeXmlFactoriesLoading() {\n+ return false;\n+ }\n+\n@Override\npublic BrowserProxySettings browserProxySettings() {\nreturn BrowserProxySettings.DISABLED;\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"diff": "@@ -23,7 +23,6 @@ import com.github.tomakehurst.wiremock.core.Options;\nimport com.github.tomakehurst.wiremock.core.WireMockApp;\nimport com.github.tomakehurst.wiremock.extension.Extension;\nimport com.github.tomakehurst.wiremock.extension.ExtensionLoader;\n-import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer;\nimport com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;\nimport com.github.tomakehurst.wiremock.http.CaseInsensitiveKey;\nimport com.github.tomakehurst.wiremock.http.HttpServerFactory;\n@@ -70,6 +69,7 @@ public class CommandLineOptions implements Options {\nprivate static final String PROXY_ALL = \"proxy-all\";\nprivate static final String PRESERVE_HOST_HEADER = \"preserve-host-header\";\nprivate static final String PROXY_VIA = \"proxy-via\";\n+ private static final String TIMEOUT = \"timeout\";\nprivate static final String PORT = \"port\";\nprivate static final String DISABLE_HTTP = \"disable-http\";\nprivate static final String BIND_ADDRESS = \"bind-address\";\n@@ -113,6 +113,7 @@ public class CommandLineOptions implements Options {\nprivate static final String HTTPS_CA_KEYSTORE = \"ca-keystore\";\nprivate static final String HTTPS_CA_KEYSTORE_PASSWORD = \"ca-keystore-password\";\nprivate static final String HTTPS_CA_KEYSTORE_TYPE = \"ca-keystore-type\";\n+ private static final String DISABLE_OPTIMIZE_XML_FACTORIES_LOADING = \"disable-optimize-xml-factories-loading\";\nprivate static final String LOAD_RESOURCES_FROM_CLASSPATH = \"load-resources-from-classpath\";\nprivate final OptionSet optionSet;\n@@ -131,6 +132,8 @@ public class CommandLineOptions implements Options {\noptionParser.accepts(HTTPS_PORT, \"If this option is present WireMock will enable HTTPS on the specified port\").withRequiredArg();\noptionParser.accepts(BIND_ADDRESS, \"The IP to listen connections\").withRequiredArg();\noptionParser.accepts(CONTAINER_THREADS, \"The number of container threads\").withRequiredArg();\n+ optionParser.accepts(TIMEOUT, \"The default global timeout.\");\n+ optionParser.accepts(DISABLE_OPTIMIZE_XML_FACTORIES_LOADING, \"Whether to disable optimize XML factories loading or not.\");\noptionParser.accepts(REQUIRE_CLIENT_CERT, \"Make the server require a trusted client certificate to enable a connection\");\noptionParser.accepts(HTTPS_TRUSTSTORE_TYPE, \"The HTTPS trust store type\").withRequiredArg().defaultsTo(\"JKS\");\noptionParser.accepts(HTTPS_TRUSTSTORE_PASSWORD, \"Password for the trust store\").withRequiredArg().defaultsTo(\"password\");\n@@ -614,6 +617,16 @@ public class CommandLineOptions implements Options {\nreturn optionSet.has(ENABLE_STUB_CORS);\n}\n+ @Override\n+ public long timeout() {\n+ return optionSet.has(TIMEOUT) ? Long.parseLong((String)optionSet.valueOf(TIMEOUT)) : DEFAULT_TIMEOUT;\n+ }\n+\n+ @Override\n+ public boolean getDisableOptimizeXmlFactoriesLoading() {\n+ return optionSet.has(DISABLE_OPTIMIZE_XML_FACTORIES_LOADING);\n+ }\n+\n@SuppressWarnings(\"unchecked\")\n@Override\npublic BrowserProxySettings browserProxySettings() {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/WireMockServerRunner.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/WireMockServerRunner.java",
"diff": "@@ -42,10 +42,6 @@ public class WireMockServerRunner {\n\"| $$/ \\\\ $$| $$| $$ | $$$$$$$| $$ \\\\/ | $$| $$$$$$/| $$$$$$$| $$ \\\\ $$\\n\" +\n\"|__/ \\\\__/|__/|__/ \\\\_______/|__/ |__/ \\\\______/ \\\\_______/|__/ \\\\__/\";\n- static {\n- System.setProperty(\"org.mortbay.log.class\", \"com.github.tomakehurst.wiremock.jetty.LoggerAdapter\");\n- }\n-\nprivate WireMockServer wireMockServer;\npublic void run(String... args) {\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Leave optimize factories loading enabled by default, for backwards compatibility
Remove no longer used org.mortbay.log.class system property setting |
686,990 | 18.05.2021 13:12:57 | -7,200 | 88f7167d0df049cc5b449571351f993a7b87d03f | For Also add an option to enable/disable Jetty strict HTTP header handling | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/Options.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/Options.java",
"diff": "@@ -82,4 +82,5 @@ public interface Options {\nboolean getStubCorsEnabled();\nlong timeout();\nboolean getDisableOptimizeXmlFactoriesLoading();\n+ boolean getDisableStrictHttpHeaders();\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"diff": "@@ -114,6 +114,7 @@ public class WireMockConfiguration implements Options {\nprivate String permittedSystemKeys = null;\nprivate boolean stubCorsEnabled = false;\n+ private boolean disableStrictHttpHeaders;\nprivate MappingsSource getMappingsSource() {\nif (mappingsSource == null) {\n@@ -604,6 +605,16 @@ public class WireMockConfiguration implements Options {\nreturn this;\n}\n+ @Override\n+ public boolean getDisableStrictHttpHeaders() {\n+ return disableStrictHttpHeaders;\n+ }\n+\n+ public WireMockConfiguration disableStrictHttpHeaders(boolean disableStrictHttpHeaders) {\n+ this.disableStrictHttpHeaders = disableStrictHttpHeaders;\n+ return this;\n+ }\n+\n@Override\npublic BrowserProxySettings browserProxySettings() {\nKeyStoreSettings keyStoreSettings = caKeyStoreSettings != null ?\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/jetty9/JettyHttpServer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/jetty9/JettyHttpServer.java",
"diff": "@@ -28,6 +28,7 @@ import com.google.common.base.Optional;\nimport com.google.common.collect.ImmutableMap;\nimport com.google.common.io.Resources;\nimport org.apache.commons.lang3.ArrayUtils;\n+import org.apache.commons.lang3.mutable.MutableBoolean;\nimport org.eclipse.jetty.http.MimeTypes;\nimport org.eclipse.jetty.io.NetworkTrafficListener;\nimport org.eclipse.jetty.server.*;\n@@ -58,10 +59,7 @@ public class JettyHttpServer implements HttpServer {\nprivate static final String FILES_URL_MATCH = String.format(\"/%s/*\", WireMockApp.FILES_ROOT);\nprivate static final String[] GZIPPABLE_METHODS = new String[] { \"POST\", \"PUT\", \"PATCH\", \"DELETE\" };\nprivate static final int DEFAULT_ACCEPTORS = 3;\n-\n- static {\n- System.setProperty(\"org.eclipse.jetty.http.HttpGenerator.STRICT\", \"true\");\n- }\n+ private static final MutableBoolean STRICT_HTTP_HEADERS_APPLIED = new MutableBoolean(false);\nprivate final Server jettyServer;\nprivate final ServerConnector httpConnector;\n@@ -74,6 +72,11 @@ public class JettyHttpServer implements HttpServer {\nAdminRequestHandler adminRequestHandler,\nStubRequestHandler stubRequestHandler\n) {\n+ if (!options.getDisableStrictHttpHeaders() && STRICT_HTTP_HEADERS_APPLIED.isFalse()) {\n+ System.setProperty(\"org.eclipse.jetty.http.HttpGenerator.STRICT\", String.valueOf(true));\n+ STRICT_HTTP_HEADERS_APPLIED.setTrue();\n+ }\n+\njettyServer = createServer(options);\nNetworkTrafficListenerAdapter networkTrafficListenerAdapter = new NetworkTrafficListenerAdapter(options.networkTrafficListener());\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WarConfiguration.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WarConfiguration.java",
"diff": "@@ -210,6 +210,11 @@ public class WarConfiguration implements Options {\nreturn false;\n}\n+ @Override\n+ public boolean getDisableStrictHttpHeaders() {\n+ return false;\n+ }\n+\n@Override\npublic BrowserProxySettings browserProxySettings() {\nreturn BrowserProxySettings.DISABLED;\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"diff": "@@ -114,6 +114,7 @@ public class CommandLineOptions implements Options {\nprivate static final String HTTPS_CA_KEYSTORE_PASSWORD = \"ca-keystore-password\";\nprivate static final String HTTPS_CA_KEYSTORE_TYPE = \"ca-keystore-type\";\nprivate static final String DISABLE_OPTIMIZE_XML_FACTORIES_LOADING = \"disable-optimize-xml-factories-loading\";\n+ private static final String DISABLE_STRICT_HTTP_HEADERS = \"disable-strict-http-headers\";\nprivate static final String LOAD_RESOURCES_FROM_CLASSPATH = \"load-resources-from-classpath\";\nprivate final OptionSet optionSet;\n@@ -134,6 +135,7 @@ public class CommandLineOptions implements Options {\noptionParser.accepts(CONTAINER_THREADS, \"The number of container threads\").withRequiredArg();\noptionParser.accepts(TIMEOUT, \"The default global timeout.\");\noptionParser.accepts(DISABLE_OPTIMIZE_XML_FACTORIES_LOADING, \"Whether to disable optimize XML factories loading or not.\");\n+ optionParser.accepts(DISABLE_STRICT_HTTP_HEADERS, \"Whether to disable strict HTTP header handling of Jetty or not.\");\noptionParser.accepts(REQUIRE_CLIENT_CERT, \"Make the server require a trusted client certificate to enable a connection\");\noptionParser.accepts(HTTPS_TRUSTSTORE_TYPE, \"The HTTPS trust store type\").withRequiredArg().defaultsTo(\"JKS\");\noptionParser.accepts(HTTPS_TRUSTSTORE_PASSWORD, \"Password for the trust store\").withRequiredArg().defaultsTo(\"password\");\n@@ -627,6 +629,11 @@ public class CommandLineOptions implements Options {\nreturn optionSet.has(DISABLE_OPTIMIZE_XML_FACTORIES_LOADING);\n}\n+ @Override\n+ public boolean getDisableStrictHttpHeaders() {\n+ return optionSet.has(DISABLE_STRICT_HTTP_HEADERS);\n+ }\n+\n@SuppressWarnings(\"unchecked\")\n@Override\npublic BrowserProxySettings browserProxySettings() {\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | For #1420 Also add an option to enable/disable Jetty strict HTTP header handling |
686,936 | 22.10.2021 15:30:57 | -3,600 | a8f8f40999eafecea03a83a86ff5ac14daeab1a5 | Improved configuration property name and refactored construction of async timeout handler | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"diff": "@@ -54,7 +54,7 @@ import static java.util.Collections.emptyList;\npublic class WireMockConfiguration implements Options {\n- private long timeout = DEFAULT_TIMEOUT;\n+ private long asyncResponseTimeout = DEFAULT_TIMEOUT;\nprivate boolean disableOptimizeXmlFactoriesLoading = false;\nprivate int portNumber = DEFAULT_PORT;\nprivate boolean httpDisabled = false;\n@@ -133,7 +133,7 @@ public class WireMockConfiguration implements Options {\n}\npublic WireMockConfiguration timeout(int timeout) {\n- this.timeout = timeout;\n+ this.asyncResponseTimeout = timeout;\nreturn this;\n}\n@@ -592,7 +592,7 @@ public class WireMockConfiguration implements Options {\n@Override\npublic long timeout() {\n- return timeout;\n+ return asyncResponseTimeout;\n}\n@Override\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/jetty9/JettyHttpServer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/jetty9/JettyHttpServer.java",
"diff": "@@ -108,12 +108,7 @@ public class JettyHttpServer implements HttpServer {\napplyAdditionalServerConfiguration(jettyServer, options);\nfinal HandlerCollection handlers = createHandler(options, adminRequestHandler, stubRequestHandler);\n- jettyServer.setHandler(new HandlerCollection(ArrayUtils.insert(0, handlers.getHandlers(), new AbstractHandler() {\n- @Override\n- public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) {\n- baseRequest.getHttpChannel().getState().setTimeout(options.timeout());\n- }\n- })));\n+ jettyServer.setHandler(handlers);\nfinalizeSetup(options);\n}\n@@ -137,7 +132,13 @@ public class JettyHttpServer implements HttpServer {\n);\nHandlerCollection handlers = new HandlerCollection();\n- handlers.setHandlers(ArrayUtils.addAll(extensionHandlers(), adminContext));\n+ AbstractHandler asyncTimeoutSettingHandler = new AbstractHandler() {\n+ @Override\n+ public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) {\n+ baseRequest.getHttpChannel().getState().setTimeout(options.timeout());\n+ }\n+ };\n+ handlers.setHandlers(ArrayUtils.addAll(extensionHandlers(), adminContext, asyncTimeoutSettingHandler));\nif (options.getGzipDisabled()) {\nhandlers.addHandler(mockServiceContext);\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Improved configuration property name and refactored construction of async timeout handler |
686,936 | 25.10.2021 12:11:00 | -3,600 | 8ee917047d8a8e8828c7af65c387084eca534fd8 | Fixed JUnit 4 archunit error introduced by merge | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/http/ResponseDefinitionTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/http/ResponseDefinitionTest.java",
"diff": "@@ -2,7 +2,7 @@ package com.github.tomakehurst.wiremock.http;\nimport com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;\nimport com.github.tomakehurst.wiremock.matching.MockRequest;\n-import org.junit.Test;\n+import org.junit.jupiter.api.Test;\nimport static org.hamcrest.CoreMatchers.equalTo;\nimport static org.hamcrest.MatcherAssert.assertThat;\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed JUnit 4 archunit error introduced by merge |
686,936 | 25.10.2021 13:39:07 | -3,600 | e15928df01dbe42da88158a12adcef93d64c477e | Fixed test failure introduced with Apache client 5 whereby UTF8 characters in the URL are incorrectly rendered. Also fixed HTTPS client cert exception assertion. | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/HttpsAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/HttpsAcceptanceTest.java",
"diff": "@@ -22,6 +22,7 @@ import com.github.tomakehurst.wiremock.core.WireMockConfiguration;\nimport com.github.tomakehurst.wiremock.http.Fault;\nimport com.github.tomakehurst.wiremock.http.HttpClientFactory;\nimport com.google.common.io.Resources;\n+import org.apache.hc.client5.http.HttpHostConnectException;\nimport org.apache.hc.client5.http.classic.methods.HttpGet;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\nimport org.apache.hc.client5.http.impl.classic.HttpClients;\n@@ -215,11 +216,7 @@ public class HttpsAcceptanceTest {\ncontentFor(url(\"/https-test\")); // this lacks the required client certificate\nfail(\"Expected a SocketException, SSLHandshakeException or SSLException to be thrown\");\n} catch (Exception e) {\n- assertThat(e.getClass().getName(), Matchers.anyOf(\n- is(SocketException.class.getName()),\n- is(SSLHandshakeException.class.getName()),\n- is(SSLException.class.getName())\n- ));\n+ assertThat(e, Matchers.instanceOf(HttpHostConnectException.class));\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/testsupport/WireMockTestClient.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/testsupport/WireMockTestClient.java",
"diff": "@@ -23,6 +23,7 @@ import org.apache.hc.client5.http.impl.auth.BasicScheme;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\nimport org.apache.hc.client5.http.impl.classic.HttpClientBuilder;\nimport org.apache.hc.client5.http.impl.classic.HttpClients;\n+import org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory;\nimport org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;\nimport org.apache.hc.client5.http.protocol.HttpClientContext;\nimport org.apache.hc.client5.http.ssl.NoopHostnameVerifier;\n@@ -31,6 +32,7 @@ import org.apache.hc.core5.http.ClassicHttpResponse;\nimport org.apache.hc.core5.http.ContentType;\nimport org.apache.hc.core5.http.HttpEntity;\nimport org.apache.hc.core5.http.HttpHost;\n+import org.apache.hc.core5.http.config.CharCodingConfig;\nimport org.apache.hc.core5.http.io.entity.InputStreamEntity;\nimport org.apache.hc.core5.http.io.entity.StringEntity;\nimport org.apache.hc.core5.ssl.SSLContexts;\n@@ -50,6 +52,7 @@ import static com.google.common.base.Strings.isNullOrEmpty;\nimport static java.net.HttpURLConnection.HTTP_CREATED;\nimport static java.net.HttpURLConnection.HTTP_NO_CONTENT;\nimport static java.net.HttpURLConnection.HTTP_OK;\n+import static java.nio.charset.StandardCharsets.UTF_8;\nimport static org.apache.hc.core5.http.ContentType.APPLICATION_JSON;\nimport static org.apache.hc.core5.http.ContentType.APPLICATION_XML;\nimport static org.apache.hc.core5.http.ContentType.DEFAULT_BINARY;\n@@ -317,6 +320,10 @@ public class WireMockTestClient {\n.disableCookieManagement()\n.disableRedirectHandling()\n.disableContentCompression()\n+ .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()\n+ .setConnectionFactory(new ManagedHttpClientConnectionFactory(null, CharCodingConfig.custom().setCharset(UTF_8).build(), null))\n+ .build()\n+ )\n.build();\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "wiremock-webhooks-extension/src/test/java/testsupport/WireMockTestClient.java",
"new_path": "wiremock-webhooks-extension/src/test/java/testsupport/WireMockTestClient.java",
"diff": "@@ -25,11 +25,14 @@ import org.apache.hc.client5.http.impl.auth.BasicScheme;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\nimport org.apache.hc.client5.http.impl.classic.HttpClientBuilder;\nimport org.apache.hc.client5.http.impl.classic.HttpClients;\n+import org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory;\n+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;\nimport org.apache.hc.client5.http.protocol.HttpClientContext;\nimport org.apache.hc.core5.http.ClassicHttpResponse;\nimport org.apache.hc.core5.http.ContentType;\nimport org.apache.hc.core5.http.HttpEntity;\nimport org.apache.hc.core5.http.HttpHost;\n+import org.apache.hc.core5.http.config.CharCodingConfig;\nimport org.apache.hc.core5.http.io.entity.InputStreamEntity;\nimport org.apache.hc.core5.http.io.entity.StringEntity;\n@@ -43,6 +46,7 @@ import static com.google.common.base.Strings.isNullOrEmpty;\nimport static java.net.HttpURLConnection.HTTP_CREATED;\nimport static java.net.HttpURLConnection.HTTP_NO_CONTENT;\nimport static java.net.HttpURLConnection.HTTP_OK;\n+import static java.nio.charset.StandardCharsets.UTF_8;\nimport static org.apache.hc.core5.http.ContentType.APPLICATION_JSON;\npublic class WireMockTestClient {\n@@ -275,6 +279,10 @@ public class WireMockTestClient {\n.disableCookieManagement()\n.disableRedirectHandling()\n.disableContentCompression()\n+ .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()\n+ .setConnectionFactory(new ManagedHttpClientConnectionFactory(null, CharCodingConfig.custom().setCharset(UTF_8).build(), null))\n+ .build()\n+ )\n.build();\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed test failure introduced with Apache client 5 whereby UTF8 characters in the URL are incorrectly rendered. Also fixed HTTPS client cert exception assertion. |
686,936 | 25.10.2021 13:41:57 | -3,600 | 97d1cbf8ac3a39b4fc738ba76f642fab89faabe3 | Forced the main Apache client to UTF8 for good measure | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/HttpClientFactory.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/HttpClientFactory.java",
"diff": "@@ -26,12 +26,14 @@ import org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy;\nimport org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\nimport org.apache.hc.client5.http.impl.classic.HttpClientBuilder;\n+import org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory;\nimport org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;\nimport org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;\nimport org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;\nimport org.apache.hc.client5.http.ssl.NoopHostnameVerifier;\nimport org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;\nimport org.apache.hc.core5.http.HttpHost;\n+import org.apache.hc.core5.http.config.CharCodingConfig;\nimport org.apache.hc.core5.util.TextUtils;\nimport org.apache.hc.core5.util.TimeValue;\nimport org.apache.hc.core5.util.Timeout;\n@@ -49,6 +51,7 @@ import static com.github.tomakehurst.wiremock.common.LocalNotifier.notifier;\nimport static com.github.tomakehurst.wiremock.common.ProxySettings.NO_PROXY;\nimport static com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings.NO_STORE;\nimport static com.github.tomakehurst.wiremock.http.RequestMethod.*;\n+import static java.nio.charset.StandardCharsets.UTF_8;\nimport static org.apache.commons.lang3.StringUtils.isEmpty;\npublic class HttpClientFactory {\n@@ -75,6 +78,7 @@ public class HttpClientFactory {\n.setMaxConnPerRoute(maxConnections)\n.setMaxConnTotal(maxConnections)\n.setValidateAfterInactivity(TimeValue.ofSeconds(5)) // TODO Verify duration\n+ .setConnectionFactory(new ManagedHttpClientConnectionFactory(null, CharCodingConfig.custom().setCharset(UTF_8).build(), null))\n.build())\n.setDefaultRequestConfig(RequestConfig.custom()\n.setResponseTimeout(Timeout.ofMilliseconds(timeoutMilliseconds))\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Forced the main Apache client to UTF8 for good measure |
686,936 | 25.10.2021 13:51:37 | -3,600 | 26730bbcf2aa26eccaaf38dda1345a73640e766c | Fixed HTTPS client certificate test exception assertion | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/HttpsAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/HttpsAcceptanceTest.java",
"diff": "@@ -31,7 +31,10 @@ import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuil\nimport org.apache.hc.client5.http.ssl.NoopHostnameVerifier;\nimport org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;\nimport org.apache.hc.client5.http.ssl.TrustSelfSignedStrategy;\n-import org.apache.hc.core5.http.*;\n+import org.apache.hc.core5.http.ClassicHttpResponse;\n+import org.apache.hc.core5.http.HttpResponse;\n+import org.apache.hc.core5.http.MalformedChunkCodingException;\n+import org.apache.hc.core5.http.NoHttpResponseException;\nimport org.apache.hc.core5.http.io.entity.EntityUtils;\nimport org.apache.hc.core5.ssl.SSLContexts;\nimport org.hamcrest.Matchers;\n@@ -40,6 +43,9 @@ import org.junit.jupiter.api.Test;\nimport org.junit.jupiter.api.condition.DisabledOnOs;\nimport org.junit.jupiter.api.condition.OS;\n+import javax.net.ssl.SSLContext;\n+import javax.net.ssl.SSLException;\n+import javax.net.ssl.SSLHandshakeException;\nimport java.io.FileInputStream;\nimport java.io.IOException;\nimport java.net.SocketException;\n@@ -48,24 +54,12 @@ import java.security.KeyStoreException;\nimport java.security.NoSuchAlgorithmException;\nimport java.security.cert.CertificateException;\n-import javax.net.ssl.SSLContext;\n-import javax.net.ssl.SSLException;\n-import javax.net.ssl.SSLHandshakeException;\n-\n-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;\n-import static com.github.tomakehurst.wiremock.client.WireMock.get;\n-import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;\n-import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\nimport static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n-import static com.github.tomakehurst.wiremock.testsupport.TestFiles.KEY_STORE_PATH;\n-import static com.github.tomakehurst.wiremock.testsupport.TestFiles.TRUST_STORE_PASSWORD;\n-import static com.github.tomakehurst.wiremock.testsupport.TestFiles.TRUST_STORE_PATH;\n+import static com.github.tomakehurst.wiremock.testsupport.TestFiles.*;\nimport static org.hamcrest.MatcherAssert.assertThat;\n-import static org.hamcrest.Matchers.instanceOf;\n-import static org.hamcrest.Matchers.is;\n-import static org.junit.jupiter.api.Assertions.assertThrows;\n-import static org.junit.jupiter.api.Assertions.assertTrue;\n-import static org.junit.jupiter.api.Assertions.fail;\n+import static org.hamcrest.Matchers.*;\n+import static org.junit.jupiter.api.Assertions.*;\npublic class HttpsAcceptanceTest {\n@@ -216,7 +210,12 @@ public class HttpsAcceptanceTest {\ncontentFor(url(\"/https-test\")); // this lacks the required client certificate\nfail(\"Expected a SocketException, SSLHandshakeException or SSLException to be thrown\");\n} catch (Exception e) {\n- assertThat(e, Matchers.instanceOf(HttpHostConnectException.class));\n+ assertThat(e.getClass().getName(), Matchers.anyOf(\n+ is(HttpHostConnectException.class.getName()),\n+ is(SSLHandshakeException.class.getName()),\n+ is(SSLException.class.getName()),\n+ is(SocketException.class.getName())\n+ ));\n}\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed HTTPS client certificate test exception assertion |
686,936 | 25.10.2021 15:38:00 | -3,600 | 699c1e849d4f220686e72bd5780ce8dca502874a | Added ability to verify requests using a custom matcher | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"diff": "@@ -87,9 +87,11 @@ public class WireMockApp implements StubServer, Admin {\nthis.defaultMappingsLoader = options.mappingsLoader();\nthis.mappingsSaver = options.mappingsSaver();\nglobalSettingsHolder = new GlobalSettingsHolder();\n- requestJournal = options.requestJournalDisabled() ? new DisabledRequestJournal() : new InMemoryRequestJournal(options.maxRequestJournalEntries());\n+\nMap<String, RequestMatcherExtension> customMatchers = options.extensionsOfType(RequestMatcherExtension.class);\n+ requestJournal = options.requestJournalDisabled() ? new DisabledRequestJournal() : new InMemoryRequestJournal(options.maxRequestJournalEntries(), customMatchers);\n+\nscenarios = new Scenarios();\nstubMappings = new InMemoryStubMappings(\nscenarios,\n@@ -121,7 +123,7 @@ public class WireMockApp implements StubServer, Admin {\nthis.defaultMappingsLoader = defaultMappingsLoader;\nthis.mappingsSaver = mappingsSaver;\nglobalSettingsHolder = new GlobalSettingsHolder();\n- requestJournal = requestJournalDisabled ? new DisabledRequestJournal() : new InMemoryRequestJournal(maxRequestJournalEntries);\n+ requestJournal = requestJournalDisabled ? new DisabledRequestJournal() : new InMemoryRequestJournal(maxRequestJournalEntries, requestMatchers);\nscenarios = new Scenarios();\nstubMappings = new InMemoryStubMappings(scenarios, requestMatchers, transformers, rootFileSource, Collections.<StubLifecycleListener>emptyList());\nthis.container = container;\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/matching/RequestPattern.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/matching/RequestPattern.java",
"diff": "@@ -471,10 +471,14 @@ public class RequestPattern implements NamedValueMatcher<Request> {\n}\npublic static Predicate<Request> thatMatch(final RequestPattern pattern) {\n+ return thatMatch(pattern, Collections.emptyMap());\n+ }\n+\n+ public static Predicate<Request> thatMatch(final RequestPattern pattern, final Map<String, RequestMatcherExtension> customMatchers) {\nreturn new Predicate<Request>() {\n@Override\npublic boolean apply(Request request) {\n- return pattern.match(request).isExactMatch();\n+ return pattern.match(request, customMatchers).isExactMatch();\n}\n};\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/verification/InMemoryRequestJournal.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/verification/InMemoryRequestJournal.java",
"diff": "package com.github.tomakehurst.wiremock.verification;\nimport com.github.tomakehurst.wiremock.common.Json;\n+import com.github.tomakehurst.wiremock.matching.RequestMatcherExtension;\nimport com.github.tomakehurst.wiremock.matching.RequestPattern;\nimport com.github.tomakehurst.wiremock.matching.StringValuePattern;\nimport com.github.tomakehurst.wiremock.stubbing.ServeEvent;\n@@ -27,6 +28,7 @@ import com.google.common.collect.FluentIterable;\nimport com.google.common.collect.ImmutableList;\nimport java.util.List;\n+import java.util.Map;\nimport java.util.Queue;\nimport java.util.UUID;\nimport java.util.concurrent.ConcurrentLinkedQueue;\n@@ -40,22 +42,24 @@ public class InMemoryRequestJournal implements RequestJournal {\nprivate final Queue<ServeEvent> serveEvents = new ConcurrentLinkedQueue<ServeEvent>();\nprivate final Optional<Integer> maxEntries;\n+ private final Map<String, RequestMatcherExtension> customMatchers;\n- public InMemoryRequestJournal(Optional<Integer> maxEntries) {\n+ public InMemoryRequestJournal(Optional<Integer> maxEntries, Map<String, RequestMatcherExtension> customMatchers) {\nif (maxEntries.isPresent() && maxEntries.get() < 0) {\nthrow new IllegalArgumentException(\"Maximum number of entries of journal must be greater than zero\");\n}\nthis.maxEntries = maxEntries;\n+ this.customMatchers = customMatchers;\n}\n@Override\npublic int countRequestsMatching(RequestPattern requestPattern) {\n- return size(filter(getRequests(), thatMatch(requestPattern)));\n+ return size(filter(getRequests(), thatMatch(requestPattern, customMatchers)));\n}\n@Override\npublic List<LoggedRequest> getRequestsMatching(RequestPattern requestPattern) {\n- return ImmutableList.copyOf(filter(getRequests(), thatMatch(requestPattern)));\n+ return ImmutableList.copyOf(filter(getRequests(), thatMatch(requestPattern, customMatchers)));\n}\n@Override\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/VerificationAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/VerificationAcceptanceTest.java",
"diff": "@@ -802,6 +802,40 @@ public class VerificationAcceptanceTest {\nassertThat(serveEvents.get(0).getRequest().getUrl(), is(\"/without-metadata\"));\n}\n+ @Test\n+ public void verifiesRequestsViaRequestMatcherExtension() {\n+ setupServer(options().extensions(new PathContainsParamRequestMatcher()));\n+\n+ testClient.get(\"/local-request-matcher-ext-this\");\n+ testClient.get(\"/local-request-matcher-ext-that\");\n+\n+ wireMockServer.verify(2, requestMadeFor(\"path-contains-param\", Parameters.one(\"path\", \"local-request-matcher-ext\")));\n+ }\n+\n+ @Test\n+ public void verifiesRequestsViaRequestMatcherExtensionRemotely() {\n+ setupServer(options().extensions(new PathContainsParamRequestMatcher()));\n+\n+ testClient.get(\"/remote-request-matcher-ext-this\");\n+ testClient.get(\"/remote-request-matcher-ext-that\");\n+\n+ verify(2, requestMadeFor(\"path-contains-param\", Parameters.one(\"path\", \"remote-request-matcher-ext\")));\n+ }\n+\n+ }\n+\n+ public static class PathContainsParamRequestMatcher extends RequestMatcherExtension {\n+\n+ @Override\n+ public MatchResult match(Request request, Parameters parameters) {\n+ String pathSegment = parameters.getString(\"path\");\n+ return MatchResult.of(request.getUrl().contains(pathSegment));\n+ }\n+\n+ @Override\n+ public String getName() {\n+ return \"path-contains-param\";\n+ }\n}\n@Nested\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/verification/InMemoryRequestJournalTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/verification/InMemoryRequestJournalTest.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.verification;\n+import com.github.tomakehurst.wiremock.extension.Parameters;\n+import com.github.tomakehurst.wiremock.matching.RequestMatcherExtension;\nimport com.github.tomakehurst.wiremock.stubbing.ServeEvent;\nimport com.google.common.base.Optional;\n+import com.google.common.collect.ImmutableMap;\nimport org.junit.jupiter.api.BeforeEach;\nimport org.junit.jupiter.api.Test;\n-import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;\n-import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;\n+import java.util.Collections;\n+import java.util.Map;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.matching.RequestMatcherExtension.ALWAYS;\nimport static com.github.tomakehurst.wiremock.matching.RequestPattern.everything;\nimport static com.github.tomakehurst.wiremock.testsupport.MockRequestBuilder.aRequest;\nimport static com.github.tomakehurst.wiremock.verification.LoggedRequest.createFrom;\n-import static org.hamcrest.Matchers.is;\nimport static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\npublic class InMemoryRequestJournalTest {\n+ static final Map<String, RequestMatcherExtension> NO_CUSTOM_MATCHERS = Collections.emptyMap();\n+\nprivate ServeEvent serveEvent1, serveEvent2, serveEvent3;\n@BeforeEach\n@@ -41,7 +49,7 @@ public class InMemoryRequestJournalTest {\n@Test\npublic void returnsAllLoggedRequestsWhenNoJournalSizeLimit() {\n- RequestJournal journal = new InMemoryRequestJournal(Optional.<Integer>absent());\n+ RequestJournal journal = new InMemoryRequestJournal(Optional.<Integer>absent(), NO_CUSTOM_MATCHERS);\njournal.requestReceived(serveEvent1);\njournal.requestReceived(serveEvent1);\n@@ -57,7 +65,7 @@ public class InMemoryRequestJournalTest {\n.withUrl(\"/for/logging\")\n.build());\n- RequestJournal journal = new InMemoryRequestJournal(Optional.of(1));\n+ RequestJournal journal = new InMemoryRequestJournal(Optional.of(1), NO_CUSTOM_MATCHERS);\njournal.requestReceived(ServeEvent.of(loggedRequest, null));\nassertThat(journal.countRequestsMatching(everything()), is(1));\njournal.reset();\n@@ -66,7 +74,7 @@ public class InMemoryRequestJournalTest {\n@Test\npublic void discardsOldRequestsWhenJournalSizeIsLimited() throws Exception {\n- RequestJournal journal = new InMemoryRequestJournal(Optional.of(2));\n+ RequestJournal journal = new InMemoryRequestJournal(Optional.of(2), NO_CUSTOM_MATCHERS);\njournal.requestReceived(serveEvent1);\njournal.requestReceived(serveEvent2);\n@@ -79,6 +87,20 @@ public class InMemoryRequestJournalTest {\nassertOnlyLastTwoRequestsLeft(journal);\n}\n+ @Test\n+ public void matchesRequestWithCustomMatcherDefinition() throws Exception {\n+ RequestJournal journal = new InMemoryRequestJournal(Optional.<Integer>absent(), ImmutableMap.of(ALWAYS.getName(), ALWAYS));\n+\n+ journal.requestReceived(serveEvent1);\n+ journal.requestReceived(serveEvent2);\n+\n+ assertThat(journal.countRequestsMatching(requestMadeFor(ALWAYS.getName(), Parameters.empty()).build()), is(2));\n+ assertThat(journal.countRequestsMatching(requestMadeFor(\"not-existing\", Parameters.empty()).build()), is(0));\n+\n+ assertThat(journal.getRequestsMatching(requestMadeFor(ALWAYS.getName(), Parameters.empty()).build()).size(), is(2));\n+ assertThat(journal.getRequestsMatching(requestMadeFor(\"not-existing\", Parameters.empty()).build()).size(), is(0));\n+ }\n+\nprivate void assertOnlyLastTwoRequestsLeft(RequestJournal journal) {\nassertThat(journal.countRequestsMatching(getRequestedFor(urlEqualTo(\"/logging1\")).build()), is(0));\nassertThat(journal.countRequestsMatching(getRequestedFor(urlEqualTo(\"/logging2\")).build()), is(1));\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added ability to verify requests using a custom matcher
Co-authored-by: Modestas Vainius <modestas@vainius.eu> |
687,015 | 01.11.2021 12:12:32 | 14,400 | 392408e238bf508dc5f23d461c5ba9d480413822 | fix for bug 1012 - Wiremock recorder space before the Target URL | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/ResponseDefinition.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/ResponseDefinition.java",
"diff": "@@ -124,7 +124,7 @@ public class ResponseDefinition {\nthis.fixedDelayMilliseconds = fixedDelayMilliseconds;\nthis.delayDistribution = delayDistribution;\nthis.chunkedDribbleDelay = chunkedDribbleDelay;\n- this.proxyBaseUrl = proxyBaseUrl;\n+ this.proxyBaseUrl = proxyBaseUrl == null ? null : proxyBaseUrl.trim();\nthis.proxyUrlPrefixToRemove = proxyUrlPrefixToRemove;\nthis.fault = fault;\nthis.transformers = transformers;\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/http/ResponseDefinitionTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/http/ResponseDefinitionTest.java",
"diff": "@@ -51,4 +51,39 @@ public class ResponseDefinitionTest {\nassertThat(response.getProxyUrl(), equalTo(\"http://my.proxy.url\"));\n}\n+\n+ @Test\n+ public void getProxyUrlGivesBackTheProxyUrlWhenProxiedUrlBeginWithWhiteSpace() {\n+ ResponseDefinition response = ResponseDefinitionBuilder.responseDefinition()\n+ .proxiedFrom(\" http://my.proxy.url\")\n+ .build();\n+\n+ response.setOriginalRequest(MockRequest.mockRequest().url(\"/path\"));\n+\n+ assertThat(response.getProxyUrl(), equalTo(\"http://my.proxy.url/path\"));\n+ }\n+\n+ @Test\n+ public void getProxyUrlGivesBackTheProxyUrlWhenProxiedUrlEndWithWhiteSpace() {\n+ ResponseDefinition response = ResponseDefinitionBuilder.responseDefinition()\n+ .proxiedFrom(\"http://my.proxy.url \")\n+ .build();\n+\n+ response.setOriginalRequest(MockRequest.mockRequest().url(\"/path\"));\n+\n+ assertThat(response.getProxyUrl(), equalTo(\"http://my.proxy.url/path\"));\n+\n+ }\n+\n+ @Test\n+ public void getProxyUrlGivesBackTheProxyUrlWhenProxiedFromUrlNull() {\n+ ResponseDefinition response = ResponseDefinitionBuilder.responseDefinition()\n+ .build();\n+\n+ response.setOriginalRequest(MockRequest.mockRequest().url(\"/path\"));\n+\n+ assertThat(response.getProxyUrl(), equalTo(\"null/path\"));\n+\n+ }\n+\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | fix for bug 1012 - Wiremock recorder space before the Target URL (#1682) |
686,936 | 02.11.2021 12:35:00 | 0 | 326f4e0148f17269a26f5bb542d6bacc20eb240f | Closes - added the ability to fetch serve events for a specific stub ID | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/admin/model/ServeEventQuery.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/admin/model/ServeEventQuery.java",
"diff": "@@ -19,35 +19,72 @@ import com.fasterxml.jackson.annotation.JsonProperty;\nimport com.github.tomakehurst.wiremock.http.QueryParameter;\nimport com.github.tomakehurst.wiremock.http.Request;\nimport com.github.tomakehurst.wiremock.stubbing.ServeEvent;\n+import com.github.tomakehurst.wiremock.stubbing.StubMapping;\nimport java.util.List;\n+import java.util.UUID;\n+import java.util.function.Predicate;\nimport static java.util.stream.Collectors.toList;\npublic class ServeEventQuery {\n- public static final ServeEventQuery ALL = new ServeEventQuery(false);\n- public static final ServeEventQuery ALL_UNMATCHED = new ServeEventQuery(true);\n+ public static final ServeEventQuery ALL = new ServeEventQuery(false, null);\n+ public static final ServeEventQuery ALL_UNMATCHED = new ServeEventQuery(true, null);\n+\n+ public static ServeEventQuery forStubMapping(StubMapping stubMapping) {\n+ return new ServeEventQuery(false, stubMapping.getId());\n+ }\n+\n+ public static ServeEventQuery forStubMapping(UUID stubMappingId) {\n+ return new ServeEventQuery(false, stubMappingId);\n+ }\npublic static ServeEventQuery fromRequest(Request request) {\nfinal QueryParameter unmatchedParameter = request.queryParameter(\"unmatched\");\nboolean unmatched = unmatchedParameter.isPresent() && unmatchedParameter.containsValue(\"true\");\n- return new ServeEventQuery(unmatched);\n+\n+ final QueryParameter stubParameter = request.queryParameter(\"matchingStub\");\n+ UUID stubMappingId = stubParameter.isPresent() ? UUID.fromString(stubParameter.firstValue()) : null;\n+\n+ return new ServeEventQuery(unmatched, stubMappingId);\n}\nprivate final boolean onlyUnmatched;\n+ private final UUID stubMappingId;\n- public ServeEventQuery(@JsonProperty(\"onlyUnmatched\") boolean onlyUnmatched) {\n+ public ServeEventQuery(\n+ @JsonProperty(\"onlyUnmatched\") boolean onlyUnmatched,\n+ @JsonProperty(\"stubMappingId\") UUID stubMappingId\n+ ) {\nthis.onlyUnmatched = onlyUnmatched;\n+ this.stubMappingId = stubMappingId;\n}\npublic boolean isOnlyUnmatched() {\nreturn onlyUnmatched;\n}\n+ public UUID getStubMappingId() {\n+ return stubMappingId;\n+ }\n+\npublic List<ServeEvent> filter(List<ServeEvent> events) {\n- return onlyUnmatched ?\n- events.stream().filter(serveEvent -> !serveEvent.getWasMatched()).collect(toList()) :\n- events;\n+ if (!onlyUnmatched && stubMappingId == null) {\n+ return events;\n+ }\n+\n+ final Predicate<ServeEvent> matchPredicate = onlyUnmatched ?\n+ serveEvent -> !serveEvent.getWasMatched() :\n+ serveEvent -> true;\n+\n+ final Predicate<ServeEvent> stubPredicate = stubMappingId != null ?\n+ serveEvent -> serveEvent.getWasMatched() && serveEvent.getStubMapping().getId().equals(stubMappingId) :\n+ serveEvent -> true;\n+\n+ return events.stream()\n+ .filter(matchPredicate)\n+ .filter(stubPredicate)\n+ .collect(toList());\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/client/HttpAdminClient.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/client/HttpAdminClient.java",
"diff": "@@ -213,10 +213,17 @@ public class HttpAdminClient implements Admin {\n@Override\npublic GetServeEventsResult getServeEvents(ServeEventQuery query) {\n+ final QueryParams queryParams = new QueryParams();\n+ queryParams.add(\"unmatched\", String.valueOf(query.isOnlyUnmatched()));\n+\n+ if (query.getStubMappingId() != null) {\n+ queryParams.add(\"matchingStub\", query.getStubMappingId().toString());\n+ }\n+\nreturn executeRequest(\nadminRoutes.requestSpecForTask(GetAllRequestsTask.class),\nPathParams.empty(),\n- QueryParams.single(\"unmatched\", String.valueOf(query.isOnlyUnmatched())),\n+ queryParams,\nnull,\nGetServeEventsResult.class\n);\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"diff": "@@ -1033,6 +1033,26 @@ public class AdminApiTest extends AcceptanceTestBase {\nassertThat(json, jsonPartMatches(\"requests\", hasSize(2)));\n}\n+ @Test\n+ public void getsAllServeEventsMatchingASpecificStub() {\n+ wm.stubFor(get(\"/one\").willReturn(ok()));\n+ StubMapping stub2 = wm.stubFor(get(\"/two\").willReturn(ok()));\n+\n+ testClient.get(\"/two\");\n+ testClient.get(\"/one\");\n+ testClient.get(\"/one\");\n+ testClient.get(\"/two\");\n+\n+ WireMockResponse response = testClient.get(\"/__admin/requests?matchingStub=\" + stub2.getId());\n+\n+ assertThat(response.statusCode(), is(200));\n+\n+ String json = response.content();\n+ assertThat(json, jsonPartEquals(\"requests[0].request.url\", \"/two\"));\n+ assertThat(json, jsonPartEquals(\"requests[1].request.url\", \"/two\"));\n+ assertThat(json, jsonPartMatches(\"requests\", hasSize(2)));\n+ }\n+\npublic static class TestExtendedSettingsData {\npublic String name;\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ServeEventLogAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ServeEventLogAcceptanceTest.java",
"diff": "@@ -22,6 +22,7 @@ import com.github.tomakehurst.wiremock.common.Encoding;\nimport com.github.tomakehurst.wiremock.http.RequestMethod;\nimport com.github.tomakehurst.wiremock.junit.Stubbing;\nimport com.github.tomakehurst.wiremock.stubbing.ServeEvent;\n+import com.github.tomakehurst.wiremock.stubbing.StubMapping;\nimport com.github.tomakehurst.wiremock.testsupport.MappingJsonSamples;\nimport com.github.tomakehurst.wiremock.verification.LoggedRequest;\nimport org.apache.hc.core5.http.ContentType;\n@@ -186,6 +187,23 @@ public class ServeEventLogAcceptanceTest extends AcceptanceTestBase {\nassertThat(serveEvents.get(1).getRequest().getUrl(), is(\"/no-match\"));\n}\n+ @Test\n+ public void getsAllServeEventsThatMatchedStubId() {\n+ wm.stubFor(get(\"/one\").willReturn(ok()));\n+ StubMapping stub2 = wm.stubFor(get(\"/two\").willReturn(ok()));\n+\n+ testClient.get(\"/two\");\n+ testClient.get(\"/one\");\n+ testClient.get(\"/one\");\n+ testClient.get(\"/two\");\n+\n+ List<ServeEvent> serveEvents = getAllServeEvents(ServeEventQuery.forStubMapping(stub2));\n+\n+ assertThat(serveEvents.size(), is(2));\n+ assertThat(serveEvents.get(0).getRequest().getUrl(), is(\"/two\"));\n+ assertThat(serveEvents.get(1).getRequest().getUrl(), is(\"/two\"));\n+ }\n+\nprivate Matcher<LoggedRequest> withUrl(final String url) {\nreturn new TypeSafeMatcher<LoggedRequest>() {\n@Override\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Closes #956 - added the ability to fetch serve events for a specific stub ID |
686,936 | 02.11.2021 14:03:39 | 0 | abbcaa8f29aaa6ba7e8190dddcfb5e398f297758 | Added validation of stubMappingId parameter when querying serve events | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/admin/model/ServeEventQuery.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/admin/model/ServeEventQuery.java",
"diff": "package com.github.tomakehurst.wiremock.admin.model;\nimport com.fasterxml.jackson.annotation.JsonProperty;\n+import com.github.tomakehurst.wiremock.common.Errors;\n+import com.github.tomakehurst.wiremock.common.InvalidInputException;\n+import com.github.tomakehurst.wiremock.common.InvalidParameterException;\nimport com.github.tomakehurst.wiremock.http.QueryParameter;\nimport com.github.tomakehurst.wiremock.http.Request;\nimport com.github.tomakehurst.wiremock.stubbing.ServeEvent;\n@@ -45,11 +48,21 @@ public class ServeEventQuery {\nboolean unmatched = unmatchedParameter.isPresent() && unmatchedParameter.containsValue(\"true\");\nfinal QueryParameter stubParameter = request.queryParameter(\"matchingStub\");\n- UUID stubMappingId = stubParameter.isPresent() ? UUID.fromString(stubParameter.firstValue()) : null;\n+ UUID stubMappingId = toUuid(stubParameter);\nreturn new ServeEventQuery(unmatched, stubMappingId);\n}\n+ private static UUID toUuid(QueryParameter parameter) {\n+ try {\n+ return parameter.isPresent() ?\n+ UUID.fromString(parameter.firstValue()) :\n+ null;\n+ } catch (IllegalArgumentException e) {\n+ throw new InvalidParameterException(Errors.single(15, \"Query parameter \" + parameter.key() + \" value '\" + parameter.firstValue() + \"' is not a valid UUID\"));\n+ }\n+ }\n+\nprivate final boolean onlyUnmatched;\nprivate final UUID stubMappingId;\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/InvalidParameterException.java",
"diff": "+/*\n+ * Copyright (C) 2011 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.common;\n+\n+public class InvalidParameterException extends ClientError {\n+\n+ public InvalidParameterException(Errors errors) {\n+ super(errors);\n+ }\n+\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/AdminRequestHandler.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/AdminRequestHandler.java",
"diff": "@@ -21,6 +21,7 @@ import com.github.tomakehurst.wiremock.admin.AdminUriTemplate;\nimport com.github.tomakehurst.wiremock.admin.NotFoundException;\nimport com.github.tomakehurst.wiremock.admin.model.PathParams;\nimport com.github.tomakehurst.wiremock.common.InvalidInputException;\n+import com.github.tomakehurst.wiremock.common.InvalidParameterException;\nimport com.github.tomakehurst.wiremock.common.NotPermittedException;\nimport com.github.tomakehurst.wiremock.common.Urls;\nimport com.github.tomakehurst.wiremock.core.Admin;\n@@ -89,8 +90,10 @@ public class AdminRequestHandler extends AbstractRequestHandler {\n);\n} catch (NotFoundException e) {\nreturn ServeEvent.forUnmatchedRequest(LoggedRequest.createFrom(request));\n+ } catch (InvalidParameterException ipe) {\n+ return ServeEvent.forBadRequest(LoggedRequest.createFrom(request), ipe.getErrors());\n} catch (InvalidInputException iie) {\n- return ServeEvent.forBadRequest(LoggedRequest.createFrom(request), iie.getErrors());\n+ return ServeEvent.forBadRequestEntity(LoggedRequest.createFrom(request), iie.getErrors());\n} catch (NotPermittedException npe) {\nreturn ServeEvent.forNotAllowedRequest(LoggedRequest.createFrom(request), npe.getErrors());\n} catch (Throwable t) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/ResponseDefinition.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/ResponseDefinition.java",
"diff": "@@ -169,6 +169,14 @@ public class ResponseDefinition {\n}\npublic static ResponseDefinition badRequest(Errors errors) {\n+ return ResponseDefinitionBuilder.responseDefinition()\n+ .withStatus(400)\n+ .withHeader(CONTENT_TYPE, \"application/json\")\n+ .withBody(Json.write(errors))\n+ .build();\n+ }\n+\n+ public static ResponseDefinition badRequestEntity(Errors errors) {\nreturn ResponseDefinitionBuilder.responseDefinition()\n.withStatus(422)\n.withHeader(CONTENT_TYPE, \"application/json\")\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/ServeEvent.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/ServeEvent.java",
"diff": "@@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore;\nimport com.fasterxml.jackson.annotation.JsonProperty;\nimport com.github.tomakehurst.wiremock.common.Errors;\nimport com.github.tomakehurst.wiremock.common.Timing;\n-import com.github.tomakehurst.wiremock.extension.Parameters;\nimport com.github.tomakehurst.wiremock.extension.PostServeActionDefinition;\nimport com.github.tomakehurst.wiremock.http.LoggedResponse;\nimport com.github.tomakehurst.wiremock.http.Response;\n@@ -31,7 +30,6 @@ import com.google.common.base.Predicate;\nimport java.util.Collections;\nimport java.util.List;\n-import java.util.Map;\nimport java.util.UUID;\nimport java.util.concurrent.atomic.AtomicReference;\n@@ -72,6 +70,10 @@ public class ServeEvent {\nreturn new ServeEvent(request, null, ResponseDefinition.badRequest(errors));\n}\n+ public static ServeEvent forBadRequestEntity(LoggedRequest request, Errors errors) {\n+ return new ServeEvent(request, null, ResponseDefinition.badRequestEntity(errors));\n+ }\n+\npublic static ServeEvent forNotAllowedRequest(LoggedRequest request, Errors errors) {\nreturn new ServeEvent(request, null, ResponseDefinition.notPermitted(errors));\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"diff": "@@ -1053,6 +1053,22 @@ public class AdminApiTest extends AcceptanceTestBase {\nassertThat(json, jsonPartMatches(\"requests\", hasSize(2)));\n}\n+ @Test\n+ public void returnsSensibleErrorIfStubIdNotValid() {\n+ WireMockResponse response = testClient.get(\"/__admin/requests?matchingStub=not-a-valid-uuid\");\n+\n+ assertThat(response.statusCode(), is(400));\n+ assertThat(response.content(), jsonPartEquals(\"errors[0].title\", \"Query parameter matchingStub value 'not-a-valid-uuid' is not a valid UUID\"));\n+ }\n+\n+ @Test\n+ public void returnsSensibleErrorIfStubIdIsNull() {\n+ WireMockResponse response = testClient.get(\"/__admin/requests?matchingStub=\");\n+\n+ assertThat(response.statusCode(), is(400));\n+ assertThat(response.content(), jsonPartEquals(\"errors[0].title\", \"Query parameter matchingStub value '' is not a valid UUID\"));\n+ }\n+\npublic static class TestExtendedSettingsData {\npublic String name;\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added validation of stubMappingId parameter when querying serve events |
686,936 | 02.11.2021 14:29:49 | 0 | b73fee872666ede8ba10ab32b687be426e9446e3 | Added documentation for serve event querying by unmatched and specific stub | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/verifying.md",
"new_path": "docs-v2/_docs/verifying.md",
"diff": "@@ -157,11 +157,34 @@ And via the HTTP API by sending a `GET` to `http://<host>:<port>/__admin/request\n}\n```\n+### Filtering events\n+\nOptionally the results can be filtered to those occuring after a specififed (ISO8601) date-time. Also, the result set can optionally be limited in size\ne.g. to return the most recent three results after the 7th of June 2016 12pm send:\n`GET http://localhost:8080/__admin/requests?since=2016-06-06T12:00:00&limit=3`\n+Results can also be filtered to include only unmatched requests via a query parameter:\n+\n+`GET http://localhost:8080/__admin/requests?unmatched=true`\n+\n+In Java:\n+\n+```java\n+List<ServeEvent> serveEvents = getAllServeEvents(ServeEventQuery.ALL_UNMATCHED);\n+```\n+\n+Likewise, the results can be filtered to include only requests matching a specific stub ID:\n+\n+`GET http://localhost:8080/__admin/requests?matchingStub=59651373-6deb-4707-847c-9e8caf63266e`\n+\n+In Java:\n+\n+```java\n+List<ServeEvent> serveEvents =\n+ getAllServeEvents(ServeEventQuery.forStubMapping(myStubId));\n+```\n+\n### Criteria queries\nThe request journal can also be queried, taking a request pattern as the filter criteria. In Java:\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added documentation for serve event querying by unmatched and specific stub |
686,936 | 02.11.2021 14:31:06 | 0 | fccc59f929fa2773fcdd072d66c78b25e582c66c | Moved validate gradle wrapper action to its own workflow to reduce overhead of running it in each matrix job, and likelihood of timeouts | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -22,8 +22,6 @@ jobs:\nsteps:\n- uses: actions/checkout@v2\n- - name: Validate Gradle wrapper\n- uses: gradle/wrapper-validation-action@v1\n- name: Set up JDK\nuses: actions/setup-java@v2\nwith:\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": ".github/workflows/validate-gradle-wrapper.yml",
"diff": "+# This workflow will build a Java project with Gradle\n+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle\n+\n+name: Validate Gradle wrapper\n+\n+on:\n+ pull_request:\n+ branches: [ master ]\n+\n+jobs:\n+ validate:\n+ name: Validate Gradle wrapper\n+ runs-on: ubuntu-latest\n+ steps:\n+ - uses: actions/checkout@v2\n+ - name: Validate Gradle wrapper\n+ uses: gradle/wrapper-validation-action@v1\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Moved validate gradle wrapper action to its own workflow to reduce overhead of running it in each matrix job, and likelihood of timeouts |
686,936 | 02.11.2021 16:21:18 | 0 | 6f6b1086adce659ca830fa24e51a9ae46e057e45 | Closes - fall back to HTTPS 1.1 only when no ALPN provider can be loaded | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/jetty94/Jetty94HttpServer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/jetty94/Jetty94HttpServer.java",
"diff": "@@ -86,16 +86,26 @@ public class Jetty94HttpServer extends JettyHttpServer {\nHttpConnectionFactory http = new HttpConnectionFactory(httpConfig);\nHTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpConfig);\n+ ConnectionFactory[] connectionFactories;\n+ try {\nALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();\nSslConnectionFactory ssl = new SslConnectionFactory(http2SslContextFactory, alpn.getProtocol());\n- ConnectionFactory[] connectionFactories = {\n+ connectionFactories = new ConnectionFactory[]{\nssl,\nalpn,\nh2,\nhttp\n};\n+ } catch (IllegalStateException e) {\n+ SslConnectionFactory ssl = new SslConnectionFactory(http2SslContextFactory, http.getProtocol());\n+\n+ connectionFactories = new ConnectionFactory[] {\n+ ssl,\n+ http\n+ };\n+ }\nreturn createServerConnector(\nbindAddress,\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Closes #1688 - fall back to HTTPS 1.1 only when no ALPN provider can be loaded |
686,936 | 04.11.2021 12:16:50 | 0 | b64cdbe0efdfe3a9bfcd036d656a6947b8842a36 | Fixed merge typo in JettySettingsTest | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/common/JettySettingsTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/common/JettySettingsTest.java",
"diff": "@@ -32,7 +32,7 @@ public class JettySettingsTest {\n.withAcceptQueueSize(number)\n.withRequestHeaderSize(number)\n.withResponseHeaderSize(number)\n- .withStopTimeout(longNumber);\n+ .withStopTimeout(longNumber)\n.withIdleTimeout(longNumber);\nJettySettings jettySettings = builder.build();\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed merge typo in JettySettingsTest |
686,936 | 22.11.2021 14:48:43 | 0 | bf048fac8ad6b4d5ca845fbe049e04a0af13ceac | Closes - proper support for subclassing of the JUnit5 WireMockExtension | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -88,6 +88,7 @@ dependencies {\ntestImplementation \"junit:junit:4.13\"\ntestImplementation(\"org.junit.jupiter:junit-jupiter:$versions.junitJupiter\")\n+ testImplementation(\"org.junit.platform:junit-platform-testkit\")\ntestRuntimeOnly(\"org.junit.vintage:junit-vintage-engine\")\ntestImplementation(\"org.junit.platform:junit-platform-launcher\")\ntestImplementation 'org.mockito:mockito-junit-jupiter:4.0.0'\n"
},
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/junit-jupiter.md",
"new_path": "docs-v2/_docs/junit-jupiter.md",
"diff": "@@ -241,3 +241,52 @@ public class JUnitJupiterProgrammaticProxyTest {\n}\n}\n```\n+\n+## Subclassing the extension\n+\n+Like the JUnit 4.x rule, `WireMockExtension` can be subclassed in order to extend its behaviour by hooking into its lifecycle events.\n+This can also be a good approach for creating a domain-specific API mock, by adding methods to stub and verify specific calls.\n+\n+```java\n+public class MyMockApi extends WireMockExtension {\n+\n+ public MyMockApi(WireMockExtension.Builder builder) {\n+ super(builder);\n+ }\n+\n+ @Override\n+ protected void onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ // Do things before any tests have run\n+ }\n+\n+ @Override\n+ protected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ // Do things before each test\n+ }\n+\n+ @Override\n+ protected void onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ // Do things after each test\n+ }\n+\n+ @Override\n+ protected void onAfterAll(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ // Do things after all tests have run\n+ }\n+}\n+```\n+\n+Note the constructor, which takes the extension's builder as its parameter. By making this public, you can pass an instance\n+of the builder in when constructing your extension as follows:\n+\n+```java\n+ @RegisterExtension\n+ static MyMockApi myMockApi =\n+ new MyMockApi(\n+ WireMockExtension.extensionOptions()\n+ .options(wireMockConfig().dynamicPort().dynamicHttpsPort())\n+ .configureStaticDsl(true));\n+```\n+\n+This will ensure that all parameters from the builder will be set as they would if you had constructed an instance of\n+`WireMockExtension` from it.\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"diff": "@@ -39,6 +39,7 @@ public class WireMockExtension extends DslWrapper\nprivate Options options;\nprivate WireMockServer wireMockServer;\n+ private WireMockRuntimeInfo runtimeInfo;\nprivate boolean isNonStatic = false;\nprivate Boolean proxyMode;\n@@ -48,8 +49,14 @@ public class WireMockExtension extends DslWrapper\nfailOnUnmatchedRequests = false;\n}\n- // Intended to be called from the builder\n- protected WireMockExtension(\n+ protected WireMockExtension(Builder builder) {\n+ this.options = builder.options;\n+ this.configureStaticDsl = builder.configureStaticDsl;\n+ this.failOnUnmatchedRequests = builder.failOnUnmatchedRequests;\n+ this.proxyMode = builder.proxyMode;\n+ }\n+\n+ private WireMockExtension(\nOptions options,\nboolean configureStaticDsl,\nboolean failOnUnmatchedRequests,\n@@ -60,10 +67,22 @@ public class WireMockExtension extends DslWrapper\nthis.proxyMode = proxyMode;\n}\n+ public static Builder extensionOptions() {\n+ return newInstance();\n+ }\n+\npublic static Builder newInstance() {\nreturn new Builder();\n}\n+ protected void onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n+\n+ protected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n+\n+ protected void onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n+\n+ protected void onAfterAll(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n+\n@Override\npublic boolean supportsParameter(\nfinal ParameterContext parameterContext, final ExtensionContext extensionContext)\n@@ -77,7 +96,7 @@ public class WireMockExtension extends DslWrapper\nthrows ParameterResolutionException {\nif (parameterIsWireMockRuntimeInfo(parameterContext)) {\n- return new WireMockRuntimeInfo(wireMockServer);\n+ return runtimeInfo;\n}\nreturn null;\n@@ -88,6 +107,8 @@ public class WireMockExtension extends DslWrapper\nwireMockServer = new WireMockServer(resolveOptions(extensionContext));\nwireMockServer.start();\n+ runtimeInfo = new WireMockRuntimeInfo(wireMockServer);\n+\nthis.admin = wireMockServer;\nthis.stubbing = wireMockServer;\n@@ -147,6 +168,8 @@ public class WireMockExtension extends DslWrapper\npublic void beforeAll(ExtensionContext context) throws Exception {\nstartServerIfRequired(context);\nsetAdditionalOptions(context);\n+\n+ onBeforeAll(runtimeInfo);\n}\n@Override\n@@ -163,11 +186,15 @@ public class WireMockExtension extends DslWrapper\nif (proxyMode) {\nJvmProxyConfigurer.configureFor(wireMockServer);\n}\n+\n+ onBeforeEach(runtimeInfo);\n}\n@Override\npublic void afterAll(ExtensionContext context) throws Exception {\nstopServerIfRunning();\n+\n+ onAfterAll(runtimeInfo);\n}\n@Override\n@@ -183,6 +210,8 @@ public class WireMockExtension extends DslWrapper\nif (proxyMode) {\nJvmProxyConfigurer.restorePrevious();\n}\n+\n+ onAfterEach(runtimeInfo);\n}\npublic WireMockRuntimeInfo getRuntimeInfo() {\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionSubclassingTest.java",
"diff": "+/*\n+ * Copyright (C) 2021 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.junit5;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n+import static com.github.tomakehurst.wiremock.junit5.WireMockExtension.extensionOptions;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;\n+\n+import com.github.tomakehurst.wiremock.http.HttpClientFactory;\n+import org.apache.hc.client5.http.classic.methods.HttpGet;\n+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\n+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;\n+import org.junit.jupiter.api.*;\n+import org.junit.jupiter.api.extension.RegisterExtension;\n+import org.junit.platform.testkit.engine.EngineTestKit;\n+import org.junit.platform.testkit.engine.Events;\n+\n+public class JUnitJupiterExtensionSubclassingTest {\n+\n+ @Test\n+ void executes_all_lifecycle_callbacks() {\n+ Events testEvents =\n+ EngineTestKit.engine(\"junit-jupiter\")\n+ .selectors(selectClass(TestClass.class))\n+ .execute()\n+ .testEvents();\n+\n+ testEvents.assertStatistics(stats -> stats.succeeded(1));\n+\n+ assertThat(MyWireMockExtension.beforeAllCalled, is(true));\n+ assertThat(MyWireMockExtension.beforeEachCalled, is(true));\n+ assertThat(MyWireMockExtension.afterEachCalled, is(true));\n+ assertThat(MyWireMockExtension.afterAllCalled, is(true));\n+ }\n+\n+ public static class TestClass {\n+\n+ CloseableHttpClient client;\n+\n+ @RegisterExtension\n+ static MyWireMockExtension wm =\n+ new MyWireMockExtension(\n+ extensionOptions()\n+ .options(wireMockConfig().dynamicPort().dynamicHttpsPort())\n+ .configureStaticDsl(true));\n+\n+ @BeforeEach\n+ void initEach() {\n+ client = HttpClientFactory.createClient();\n+ }\n+\n+ @Test\n+ void respects_config_passed_via_builder() throws Exception {\n+ assertThat(MyWireMockExtension.beforeAllCalled, is(true));\n+ assertThat(MyWireMockExtension.beforeEachCalled, is(true));\n+ assertThat(MyWireMockExtension.afterEachCalled, is(false));\n+ assertThat(MyWireMockExtension.afterAllCalled, is(false));\n+\n+ stubFor(get(\"/ping\").willReturn(ok()));\n+\n+ try (CloseableHttpResponse response =\n+ client.execute(new HttpGet(\"https://localhost:\" + wm.getHttpsPort() + \"/ping\"))) {\n+ assertThat(response.getCode(), is(200));\n+ }\n+ }\n+ }\n+\n+ public static class MyWireMockExtension extends WireMockExtension {\n+\n+ public static boolean beforeAllCalled = false;\n+ public static boolean beforeEachCalled = false;\n+ public static boolean afterEachCalled = false;\n+ public static boolean afterAllCalled = false;\n+\n+ public MyWireMockExtension(WireMockExtension.Builder builder) {\n+ super(builder);\n+ }\n+\n+ @Override\n+ protected void onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ beforeAllCalled = true;\n+ }\n+\n+ @Override\n+ protected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ beforeEachCalled = true;\n+ }\n+\n+ @Override\n+ protected void onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ afterEachCalled = true;\n+ }\n+\n+ @Override\n+ protected void onAfterAll(WireMockRuntimeInfo wireMockRuntimeInfo) {\n+ afterAllCalled = true;\n+ }\n+ }\n+}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Closes #1614 - proper support for subclassing of the JUnit5 WireMockExtension |
686,936 | 22.11.2021 15:04:18 | 0 | e6a3c8758f10d8e0d1d340dd69bd56c7f09b3979 | Attempt at fixing flakey JUnit5 subclassing test | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionSubclassingTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionSubclassingTest.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.junit5;\n-import static com.github.tomakehurst.wiremock.client.WireMock.*;\n-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n-import static com.github.tomakehurst.wiremock.junit5.WireMockExtension.extensionOptions;\n-import static org.hamcrest.MatcherAssert.assertThat;\n-import static org.hamcrest.Matchers.is;\n-import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;\n-\nimport com.github.tomakehurst.wiremock.http.HttpClientFactory;\nimport org.apache.hc.client5.http.classic.methods.HttpGet;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;\n-import org.junit.jupiter.api.*;\n+import org.junit.jupiter.api.BeforeEach;\n+import org.junit.jupiter.api.Test;\nimport org.junit.jupiter.api.extension.RegisterExtension;\nimport org.junit.platform.testkit.engine.EngineTestKit;\nimport org.junit.platform.testkit.engine.Events;\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n+import static com.github.tomakehurst.wiremock.junit5.WireMockExtension.extensionOptions;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;\n+\npublic class JUnitJupiterExtensionSubclassingTest {\n+ @BeforeEach\n+ public void beforeEach() {\n+ MyWireMockExtension.reset();\n+ }\n+\n@Test\nvoid executes_all_lifecycle_callbacks() {\nEvents testEvents =\n@@ -51,7 +57,7 @@ public class JUnitJupiterExtensionSubclassingTest {\npublic static class TestClass {\n- CloseableHttpClient client;\n+ CloseableHttpClient client = HttpClientFactory.createClient();\n@RegisterExtension\nstatic MyWireMockExtension wm =\n@@ -60,11 +66,6 @@ public class JUnitJupiterExtensionSubclassingTest {\n.options(wireMockConfig().dynamicPort().dynamicHttpsPort())\n.configureStaticDsl(true));\n- @BeforeEach\n- void initEach() {\n- client = HttpClientFactory.createClient();\n- }\n-\n@Test\nvoid respects_config_passed_via_builder() throws Exception {\nassertThat(MyWireMockExtension.beforeAllCalled, is(true));\n@@ -111,5 +112,12 @@ public class JUnitJupiterExtensionSubclassingTest {\nprotected void onAfterAll(WireMockRuntimeInfo wireMockRuntimeInfo) {\nafterAllCalled = true;\n}\n+\n+ public static void reset() {\n+ beforeAllCalled = false;\n+ beforeEachCalled = false;\n+ afterEachCalled = false;\n+ afterAllCalled = false;\n+ }\n}\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Attempt at fixing flakey JUnit5 subclassing test |
686,936 | 22.11.2021 17:58:13 | 0 | 2a2bc78a381f0a4c88c683fe29230e5f0854bc63 | Further attempt at fixing flakey JUnit5 subclassing test by moving test class to an excluded folder, since there seems to be a JUnit engine bug causing this to be run more than once (sometimes) | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionSubclassingTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/junit5/JUnitJupiterExtensionSubclassingTest.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.junit5;\n-import com.github.tomakehurst.wiremock.http.HttpClientFactory;\n-import org.apache.hc.client5.http.classic.methods.HttpGet;\n-import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\n-import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;\n+import ignored.JupiterExtensionTestClass;\nimport org.junit.jupiter.api.BeforeEach;\nimport org.junit.jupiter.api.Test;\n-import org.junit.jupiter.api.extension.RegisterExtension;\nimport org.junit.platform.testkit.engine.EngineTestKit;\nimport org.junit.platform.testkit.engine.Events;\n-import static com.github.tomakehurst.wiremock.client.WireMock.*;\n-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n-import static com.github.tomakehurst.wiremock.junit5.WireMockExtension.extensionOptions;\nimport static org.hamcrest.MatcherAssert.assertThat;\nimport static org.hamcrest.Matchers.is;\nimport static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;\n@@ -43,7 +36,7 @@ public class JUnitJupiterExtensionSubclassingTest {\nvoid executes_all_lifecycle_callbacks() {\nEvents testEvents =\nEngineTestKit.engine(\"junit-jupiter\")\n- .selectors(selectClass(TestClass.class))\n+ .selectors(selectClass(JupiterExtensionTestClass.class))\n.execute()\n.testEvents();\n@@ -55,33 +48,6 @@ public class JUnitJupiterExtensionSubclassingTest {\nassertThat(MyWireMockExtension.afterAllCalled, is(true));\n}\n- public static class TestClass {\n-\n- CloseableHttpClient client = HttpClientFactory.createClient();\n-\n- @RegisterExtension\n- static MyWireMockExtension wm =\n- new MyWireMockExtension(\n- extensionOptions()\n- .options(wireMockConfig().dynamicPort().dynamicHttpsPort())\n- .configureStaticDsl(true));\n-\n- @Test\n- void respects_config_passed_via_builder() throws Exception {\n- assertThat(MyWireMockExtension.beforeAllCalled, is(true));\n- assertThat(MyWireMockExtension.beforeEachCalled, is(true));\n- assertThat(MyWireMockExtension.afterEachCalled, is(false));\n- assertThat(MyWireMockExtension.afterAllCalled, is(false));\n-\n- stubFor(get(\"/ping\").willReturn(ok()));\n-\n- try (CloseableHttpResponse response =\n- client.execute(new HttpGet(\"https://localhost:\" + wm.getHttpsPort() + \"/ping\"))) {\n- assertThat(response.getCode(), is(200));\n- }\n- }\n- }\n-\npublic static class MyWireMockExtension extends WireMockExtension {\npublic static boolean beforeAllCalled = false;\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/ignored/JupiterExtensionTestClass.java",
"diff": "+package ignored;\n+\n+import com.github.tomakehurst.wiremock.http.HttpClientFactory;\n+import com.github.tomakehurst.wiremock.junit5.JUnitJupiterExtensionSubclassingTest;\n+import org.apache.hc.client5.http.classic.methods.HttpGet;\n+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\n+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;\n+import org.junit.jupiter.api.Test;\n+import org.junit.jupiter.api.extension.RegisterExtension;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\n+import static com.github.tomakehurst.wiremock.junit5.WireMockExtension.extensionOptions;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+\n+public class JupiterExtensionTestClass {\n+\n+ CloseableHttpClient client = HttpClientFactory.createClient();\n+\n+ @RegisterExtension\n+ static JUnitJupiterExtensionSubclassingTest.MyWireMockExtension wm =\n+ new JUnitJupiterExtensionSubclassingTest.MyWireMockExtension(\n+ extensionOptions()\n+ .options(wireMockConfig().dynamicPort().dynamicHttpsPort())\n+ .configureStaticDsl(true));\n+\n+ @Test\n+ void respects_config_passed_via_builder() throws Exception {\n+ assertThat(JUnitJupiterExtensionSubclassingTest.MyWireMockExtension.beforeAllCalled, is(true));\n+ assertThat(JUnitJupiterExtensionSubclassingTest.MyWireMockExtension.beforeEachCalled, is(true));\n+ assertThat(JUnitJupiterExtensionSubclassingTest.MyWireMockExtension.afterEachCalled, is(false));\n+ assertThat(JUnitJupiterExtensionSubclassingTest.MyWireMockExtension.afterAllCalled, is(false));\n+\n+ stubFor(get(\"/ping\").willReturn(ok()));\n+\n+ try (CloseableHttpResponse response =\n+ client.execute(new HttpGet(\"https://localhost:\" + wm.getHttpsPort() + \"/ping\"))) {\n+ assertThat(response.getCode(), is(200));\n+ }\n+ }\n+}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Further attempt at fixing flakey JUnit5 subclassing test by moving test class to an excluded folder, since there seems to be a JUnit engine bug causing this to be run more than once (sometimes) |
686,936 | 22.11.2021 18:48:18 | 0 | 6180a2779ba912ab930f1b6c5627ef7eae10ed7a | Added some Javadoc to WireMock extension and made JUnit lifecycle methods final to clearly indicate that the on* methods should be overridden by subclasses. | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/junit5/WireMockExtension.java",
"diff": "@@ -25,6 +25,11 @@ import java.util.Optional;\nimport org.junit.jupiter.api.extension.*;\nimport org.junit.platform.commons.support.AnnotationSupport;\n+/**\n+ * JUnit Jupiter extension that manages a WireMock server instance's lifecycle and configuration.\n+ *\n+ * See http://wiremock.org/docs/junit-jupiter/ for full documentation.\n+ */\npublic class WireMockExtension extends DslWrapper\nimplements ParameterResolver,\nBeforeEachCallback,\n@@ -49,6 +54,14 @@ public class WireMockExtension extends DslWrapper\nfailOnUnmatchedRequests = false;\n}\n+ /**\n+ * Constructor intended for subclasses.\n+ *\n+ * The parameter is a builder so that we can avoid a constructor explosion or\n+ * backwards-incompatible changes when new options are added.\n+ *\n+ * @param builder a {@link com.github.tomakehurst.wiremock.junit5.WireMockExtension.Builder} instance holding the initialisation parameters for the extension.\n+ */\nprotected WireMockExtension(Builder builder) {\nthis.options = builder.options;\nthis.configureStaticDsl = builder.configureStaticDsl;\n@@ -67,20 +80,44 @@ public class WireMockExtension extends DslWrapper\nthis.proxyMode = proxyMode;\n}\n+ /**\n+ * Alias for {@link #newInstance()} for use with custom subclasses, with a more relevant name for that use.\n+ * @return a new {@link com.github.tomakehurst.wiremock.junit5.WireMockExtension.Builder} instance.\n+ */\npublic static Builder extensionOptions() {\nreturn newInstance();\n}\n+ /**\n+ * Create a new builder for the extension.\n+ * @return a new {@link com.github.tomakehurst.wiremock.junit5.WireMockExtension.Builder} instance.\n+ */\npublic static Builder newInstance() {\nreturn new Builder();\n}\n+ /**\n+ * To be overridden in subclasses in order to run code immediately after per-class WireMock setup.\n+ * @param wireMockRuntimeInfo port numbers, base URLs and HTTPS info for the running WireMock instance/\n+ */\nprotected void onBeforeAll(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n+ /**\n+ * To be overridden in subclasses in order to run code immediately after per-test WireMock setup.\n+ * @param wireMockRuntimeInfo port numbers, base URLs and HTTPS info for the running WireMock instance/\n+ */\nprotected void onBeforeEach(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n+ /**\n+ * To be overridden in subclasses in order to run code immediately after per-test cleanup of WireMock and its associated resources.\n+ * @param wireMockRuntimeInfo port numbers, base URLs and HTTPS info for the running WireMock instance/\n+ */\nprotected void onAfterEach(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n+ /**\n+ * To be overridden in subclasses in order to run code immediately after per-class cleanup of WireMock.\n+ * @param wireMockRuntimeInfo port numbers, base URLs and HTTPS info for the running WireMock instance/\n+ */\nprotected void onAfterAll(WireMockRuntimeInfo wireMockRuntimeInfo) {}\n@Override\n@@ -165,7 +202,7 @@ public class WireMockExtension extends DslWrapper\n}\n@Override\n- public void beforeAll(ExtensionContext context) throws Exception {\n+ public final void beforeAll(ExtensionContext context) throws Exception {\nstartServerIfRequired(context);\nsetAdditionalOptions(context);\n@@ -173,7 +210,7 @@ public class WireMockExtension extends DslWrapper\n}\n@Override\n- public void beforeEach(ExtensionContext context) throws Exception {\n+ public final void beforeEach(ExtensionContext context) throws Exception {\nif (wireMockServer == null) {\nisNonStatic = true;\nstartServerIfRequired(context);\n@@ -191,14 +228,14 @@ public class WireMockExtension extends DslWrapper\n}\n@Override\n- public void afterAll(ExtensionContext context) throws Exception {\n+ public final void afterAll(ExtensionContext context) throws Exception {\nstopServerIfRunning();\nonAfterAll(runtimeInfo);\n}\n@Override\n- public void afterEach(ExtensionContext context) throws Exception {\n+ public final void afterEach(ExtensionContext context) throws Exception {\nif (failOnUnmatchedRequests) {\nwireMockServer.checkForUnmatchedRequests();\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added some Javadoc to WireMock extension and made JUnit lifecycle methods final to clearly indicate that the on* methods should be overridden by subclasses. |
686,936 | 29.11.2021 18:44:12 | 0 | 0b24d9d1963599bab45f08ab00091e46df1f8803 | Added a Docker doc article | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "docs-v2/_docs/docker.md",
"diff": "+---\n+layout: docs\n+title: Running in Docker\n+toc_rank: 45\n+description: Configuring and running WireMock in Docker\n+---\n+\n+<div class=\"mocklab-callout\">\n+ <p class=\"mocklab-callout__text\">\n+ Configuring servers can be a major distraction from building great software. <strong>MockLab</strong> provides a hosted, 100% WireMock compatible mocking service, freeing you from the hassles of SSL, DNS and server configuration.\n+ </p>\n+ <a href=\"http://get.mocklab.io/?utm_source=wiremock.org&utm_medium=docs-callout&utm_campaign=running-in-docker\" title=\"Learn more\" class=\"mocklab-callout__learn-more-button\">Learn more</a>\n+</div>\n+\n+From version 2.31.0 WireMock has an [official Docker image](https://hub.docker.com/r/wiremock/wiremock).\n+\n+## Getting started\n+\n+### Start a single WireWock container with default configuration\n+\n+```sh\n+docker run -it --rm\n+ -p 8080:8080 \\\n+ --name wiremock \\\n+ wiremock/wiremock:{{ site.wiremock_version }}\n+```\n+\n+> Access [http://localhost:8080/__admin/mappings](http://localhost:8080/__admin/mappings) to display the mappings (empty set)\n+\n+### Start with command line arguments\n+\n+The Docker image supports exactly the same set of command line arguments as the [standalone version](/docs/running-standalone/#command-line-options).\n+These can be passed to the container by appending them to the end of the command e.g.:\n+\n+```sh\n+docker run -it --rm\n+ -p 8443:8443 \\\n+ --name wiremock \\\n+ wiremock/wiremock:{{ site.wiremock_version }} \\\n+ --https-port 8443 --verbose\n+```\n+\n+\n+### Mounting stub mapping files\n+\n+Inside the container, the WireMock uses `/home/wiremock` as the root from which it reads the `mappings` and `__files` directories.\n+This means you can mount a directory containing these from your host machine into Docker and WireMock will load the stub mappings.\n+\n+To mount the current directory use `-v $PWD:/home/wiremock` e.g.:\n+\n+```sh\n+docker run -it --rm\n+ -p 8080:8080 \\\n+ --name wiremock \\\n+ -v $PWD:/home/wiremock \\\n+ wiremock/wiremock:{{ site.wiremock_version }}\n+```\n+\n+### Running with extensions\n+\n+[WireMock extensions](/docs/extending-wiremock/) are packaged as JAR files. In order to use them they need to be made\n+available at runtime and WireMock must be configured to enable them.\n+\n+For example, to use the [Webhooks extension](/docs/webhooks-and-callbacks/) we would first download [wiremock-webhooks-extension-{{ site.wiremock_version }}.jar](https://repo1.maven.org/maven2/org/wiremock/wiremock-webhooks-extension/{{ site.wiremock_version }}/wiremock-webhooks-extension-{{ site.wiremock_version }}.jar)\n+into the `extensions` directory under our working directory.\n+\n+Then when starting Docker we would mount the extensions directory to `/var/wiremock/extensions` and enable the webhooks extension\n+via a CLI parameter:\n+\n+```sh\n+docker run -it --rm\n+ -p 8080:8080 \\\n+ --name wiremock \\\n+ -v $PWD/extensions:/var/wiremock/extensions \\\n+ wiremock/wiremock \\\n+ --extensions org.wiremock.webhooks.Webhooks\n+```\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added a Docker doc article |
686,949 | 01.12.2021 20:14:24 | 0 | 9bb7b47e7876e8f0b1d58cbd42c20d153e10557a | added proxy prefix removal feature to docs | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/proxying.md",
"new_path": "docs-v2/_docs/proxying.md",
"diff": "@@ -64,6 +64,36 @@ stubFor(get(urlEqualTo(\"/api/override/123\")).atPriority(1)\n.willReturn(aResponse().withStatus(503)));\n```\n+Remove path prefix\n+==================\n+\n+The prefix of a request path can be removed before proxying the request:\n+\n+```java\n+stubFor(get(urlEqualTo(\"/other/service/doc/123\"))\n+ .willReturn(aResponse()\n+ .proxiedFrom(\"http://otherhost.com/approot\")\n+ .withProxyUrlPrefixToRemove(\"/other/service\")));\n+```\n+\n+or\n+\n+```json\n+{\n+ \"request\": {\n+ \"method\": \"GET\",\n+ \"url\": \"/other/service/doc/123\"\n+ },\n+ \"response\": {\n+ \"proxyBaseUrl\" : \"http://otherhost.com/approot\",\n+ \"proxyUrlPrefixToRemove\": \"/other/service\"\n+ }\n+}\n+```\n+\n+Requests using the above path will be forwarded\n+to `http://otherhost.com/approot/doc/123`\n+\nAdditional headers\n==================\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | added proxy prefix removal feature to docs (#1696) |
686,936 | 02.12.2021 10:14:02 | 0 | 66cb51809dee8e2be633f6201a0c98c97b88b325 | Fixed version number in docs | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/running-without-http-server.md",
"new_path": "docs-v2/_docs/running-without-http-server.md",
"diff": "@@ -9,7 +9,7 @@ If you want to run Wiremock inside another process, such as wrapping it in a ser\nThis works well, but has the overhead of a full HTTP server and HTTP calls back and forth that in some cases may not be relevant, and adds a fair bit of overhead to each call, and the memory footprint of the application.\n-Since Wiremock v2.32.2, the `DirectCallHttpServer` provides the ability to run a Wiremock server without ever interacting with an HTTP layer.\n+Since Wiremock v2.32.0, the `DirectCallHttpServer` provides the ability to run a Wiremock server without ever interacting with an HTTP layer.\nIt can be constructed and used like so (example usage is adapted from `DirectCallHttpServerIntegrationTest`):\n@@ -36,4 +36,4 @@ Response response = server.stubRequest(request);\n// then use the `response`'s data, and map it accordingly\n```\n-Note that prior to Wiremock v2.32.2, you can use [the workaround as described by Jamie Tanna](https://www.jvt.me/posts/2021/04/29/wiremock-serverless/), which uses internal APIs for this.\n+Note that prior to Wiremock v2.32.0, you can use [the workaround as described by Jamie Tanna](https://www.jvt.me/posts/2021/04/29/wiremock-serverless/), which uses internal APIs for this.\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed version number in docs |
686,936 | 14.12.2021 13:59:17 | 0 | ba3abca523442cb40e45c587f31036ed24b710e7 | Added log4j vuln note to the README | [
{
"change_type": "MODIFY",
"old_path": "README.md",
"new_path": "README.md",
"diff": "@@ -4,6 +4,10 @@ WireMock - a web service test double for all occasions\n[](https://github.com/tomakehurst/wiremock/actions/workflows/build-and-test.yml)\n[](https://search.maven.org/artifact/com.github.tomakehurst/wiremock-jre8)\n+!!! Log4j notice !!!\n+--------------------\n+WireMock only uses log4j in its test dependencies. Neither the thin nor standalone JAR depends on or embeds log4j, so\n+you can continue to use WireMock 2.32.0 without any risk of exposue to the recently discovered vulnerability.\nKey Features\n------------\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added log4j vuln note to the README |
687,049 | 24.12.2021 10:45:19 | 21,600 | 21bc68464dcf585ff91a394dd5b6777ddf855769 | docs: Fix example Gradle configuration | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/download-and-installation.md",
"new_path": "docs-v2/_docs/download-and-installation.md",
"diff": "@@ -74,25 +74,25 @@ Java 7 standalone (deprecated):\nJava 8:\n```groovy\n-testImplementation \"com.github.tomakehurst:wiremock:{{ site.wiremock_version }}\"\n+testImplementation \"com.github.tomakehurst:wiremock-jre8:{{ site.wiremock_version }}\"\n```\nJava 8 standalone:\n```groovy\n-testImplementation \"com.github.tomakehurst:wiremock-standalone:{{ site.wiremock_version }}\"\n+testImplementation \"com.github.tomakehurst:wiremock-jre8-standalone:{{ site.wiremock_version }}\"\n```\nJava 7 (deprecated):\n```groovy\n-testImplementation \"com.github.tomakehurst:wiremock-jre8:{{ site.wiremock_version }}\"\n+testImplementation \"com.github.tomakehurst:wiremock:2.27.2\"\n```\nJava 7 standalone (deprecated):\n```groovy\n-testImplementation \"com.github.tomakehurst:wiremock-jre8-standalone:{{ site.wiremock_version }}\"\n+testImplementation \"com.github.tomakehurst:wiremock-standalone:2.27.2\"\n```\n## Direct download\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | docs: Fix example Gradle configuration (#1758) |
686,937 | 18.01.2022 07:15:45 | 10,800 | 647194c8993c758148dc56035e86cf01f3e5d6d5 | Add missing backslashes in docker commands
It fixes docker commands in docker section documentation | [
{
"change_type": "MODIFY",
"old_path": "docs-v2/_docs/docker.md",
"new_path": "docs-v2/_docs/docker.md",
"diff": "@@ -19,7 +19,7 @@ From version 2.31.0 WireMock has an [official Docker image](https://hub.docker.c\n### Start a single WireWock container with default configuration\n```sh\n-docker run -it --rm\n+docker run -it --rm \\\n-p 8080:8080 \\\n--name wiremock \\\nwiremock/wiremock:{{ site.wiremock_version }}\n@@ -33,7 +33,7 @@ The Docker image supports exactly the same set of command line arguments as the\nThese can be passed to the container by appending them to the end of the command e.g.:\n```sh\n-docker run -it --rm\n+docker run -it --rm \\\n-p 8443:8443 \\\n--name wiremock \\\nwiremock/wiremock:{{ site.wiremock_version }} \\\n@@ -49,7 +49,7 @@ This means you can mount a directory containing these from your host machine int\nTo mount the current directory use `-v $PWD:/home/wiremock` e.g.:\n```sh\n-docker run -it --rm\n+docker run -it --rm \\\n-p 8080:8080 \\\n--name wiremock \\\n-v $PWD:/home/wiremock \\\n@@ -68,7 +68,7 @@ Then when starting Docker we would mount the extensions directory to `/var/wirem\nvia a CLI parameter:\n```sh\n-docker run -it --rm\n+docker run -it --rm \\\n-p 8080:8080 \\\n--name wiremock \\\n-v $PWD/extensions:/var/wiremock/extensions \\\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Add missing backslashes in docker commands (#1770)
It fixes docker commands in docker section documentation |
686,936 | 07.02.2022 16:45:02 | 0 | 77077e2462ec6da2ebb61d086deb0215a5613ead | Removed pre-generate API docs Actions step | [
{
"change_type": "MODIFY",
"old_path": ".github/workflows/build-and-test.yml",
"new_path": ".github/workflows/build-and-test.yml",
"diff": "@@ -35,8 +35,6 @@ jobs:\nuses: dcodeIO/setup-node-nvm@v4\nwith:\nnode-version: 8.12.0\n- - name: Pre-generate API docs\n- run: ./gradlew classes testClasses -x generateApiDocs\n- name: Cache SonarCloud packages\nuses: actions/cache@v1\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Removed pre-generate API docs Actions step |
686,936 | 07.02.2022 17:01:42 | 0 | ad07216d691349f8f8e66c2e48a7c26007f134e2 | Excluded some temp files from Spotless checks | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -138,6 +138,7 @@ allprojects {\nratchetFrom 'origin/master'\ntrimTrailingWhitespace()\nendWithNewline()\n+ targetExclude '**/Tmp*.java'\n}\ngroovyGradle {\ntarget '**/*.gradle'\n@@ -148,7 +149,7 @@ allprojects {\n}\njson {\ntarget 'src/**/*.json'\n- targetExclude 'src/test/resources/sample.json'\n+ targetExclude '**/tmp*.json', 'src/test/resources/sample.json', 'src/main/resources/swagger/*.json'\nsimple().indentWithSpaces(2)\n}\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Excluded some temp files from Spotless checks |
686,936 | 21.03.2022 12:14:50 | 0 | 58cace3dc54ec4e7f38d2eec4ceecd56419fc5ab | Removed some redundant files relating to documentation generation (since this is now in a separate repo) | [
{
"change_type": "DELETE",
"old_path": ".ruby-version",
"new_path": null,
"diff": "-2.1.10\n"
},
{
"change_type": "DELETE",
"old_path": "gen-docs.sh",
"new_path": null,
"diff": "-#!/bin/bash\n-\n-set -euo pipefail\n-\n-pushd docs-v2\n-bundle exec jekyll build\n-cp -rf _site/* ../../wiremock-gh-pages/\n-popd\n-\n-pushd ../wiremock-gh-pages\n-git add --all\n-git commit -m \"Updated docs\"\n-git push origin gh-pages\n-popd\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Removed some redundant files relating to documentation generation (since this is now in a separate repo) |
687,064 | 06.04.2022 19:38:37 | -10,800 | 999b488dbed7377e52a12e4b6c57ed86722b31ad | proxy request fix
Permit any HTTP request method to have a body when proxying | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"diff": "package com.github.tomakehurst.wiremock.http;\nimport static com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAsByteArrayAndCloseStream;\n-import static com.github.tomakehurst.wiremock.http.RequestMethod.PATCH;\n-import static com.github.tomakehurst.wiremock.http.RequestMethod.POST;\n-import static com.github.tomakehurst.wiremock.http.RequestMethod.PUT;\nimport static com.github.tomakehurst.wiremock.http.Response.response;\nimport static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;\n@@ -101,7 +98,7 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nHttpUriRequest httpRequest = getHttpRequestFor(responseDefinition);\naddRequestHeaders(httpRequest, responseDefinition);\n- addBodyIfPostPutOrPatch(httpRequest, responseDefinition);\n+ httpRequest.setEntity(buildEntityFrom(responseDefinition.getOriginalRequest()));\nCloseableHttpClient client = buildClient(serveEvent.getRequest().isBrowserProxyRequest());\ntry (CloseableHttpResponse httpResponse = client.execute(httpRequest)) {\nreturn response()\n@@ -210,14 +207,6 @@ public class ProxyResponseRenderer implements ResponseRenderer {\n&& !lowerCaseKey.startsWith(\"access-control\");\n}\n- private static void addBodyIfPostPutOrPatch(\n- ClassicHttpRequest httpRequest, ResponseDefinition response) {\n- Request originalRequest = response.getOriginalRequest();\n- if (originalRequest.getMethod().isOneOf(PUT, POST, PATCH)) {\n- httpRequest.setEntity(buildEntityFrom(originalRequest));\n- }\n- }\n-\nprivate static HttpEntity buildEntityFrom(Request originalRequest) {\nContentTypeHeader contentTypeHeader = originalRequest.contentTypeHeader().or(\"text/plain\");\nContentType contentType =\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyBaseUrlTest.java",
"diff": "+/*\n+ * Copyright (C) 2020-2021 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.http;\n+\n+import com.github.tomakehurst.wiremock.client.MappingBuilder;\n+import com.github.tomakehurst.wiremock.common.ProxySettings;\n+import com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings;\n+import com.github.tomakehurst.wiremock.crypto.CertificateSpecification;\n+import com.github.tomakehurst.wiremock.crypto.InMemoryKeyStore;\n+import com.github.tomakehurst.wiremock.crypto.Secret;\n+import com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification;\n+import com.github.tomakehurst.wiremock.global.GlobalSettingsHolder;\n+import com.github.tomakehurst.wiremock.junit5.WireMockExtension;\n+import com.github.tomakehurst.wiremock.matching.UrlPathPattern;\n+import com.github.tomakehurst.wiremock.stubbing.ServeEvent;\n+import com.github.tomakehurst.wiremock.stubbing.StubMapping;\n+import com.github.tomakehurst.wiremock.verification.LoggedRequest;\n+import org.junit.jupiter.api.Test;\n+import org.junit.jupiter.api.condition.DisabledForJreRange;\n+import org.junit.jupiter.api.condition.JRE;\n+import org.junit.jupiter.api.extension.RegisterExtension;\n+\n+import java.io.File;\n+import java.security.KeyPair;\n+import java.security.KeyPairGenerator;\n+import java.security.NoSuchAlgorithmException;\n+import java.util.Collections;\n+import java.util.Date;\n+import java.util.HashMap;\n+import java.util.Map;\n+\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;\n+import static com.github.tomakehurst.wiremock.crypto.X509CertificateVersion.V3;\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.junit.jupiter.api.Assertions.assertEquals;\n+\n+@DisabledForJreRange(\n+ min = JRE.JAVA_17,\n+ disabledReason = \"does not support generating certificates at runtime\")\n+public class ProxyBaseUrlTest {\n+\n+ @RegisterExtension\n+ public WireMockExtension endInstance = newWireMockInstance();\n+\n+ @RegisterExtension\n+ public WireMockExtension proxyInstance = newWireMockInstance();\n+\n+ private final ProxyResponseRenderer proxyResponseRenderer = buildProxyResponseRenderer(false);\n+\n+ private final String URL_PATH = \"/api\";\n+ private final String REQUEST_BODY = \"{\\\"test\\\":true}\";\n+ private final String RESPONSE_BODY = \"Result\";\n+ private final String HEADER_NAME = \"testHeader\";\n+ private final String HEADER_VALUE = \"testHeaderValue\";\n+ private final String QUERY_NAME = \"testParam\";\n+ private final String QUERY_VALUE = \"testParamValue\";\n+\n+ @Test\n+ public void postMethodTest() {\n+ addProxyStub(postMappingBuilder());\n+ addEndStub(postMappingBuilder());\n+ renderAndCheckResponse(RequestMethod.POST);\n+ }\n+\n+ @Test\n+ public void getMethodTest() {\n+ addProxyStub(getMappingBuilder());\n+ addEndStub(getMappingBuilder());\n+ renderAndCheckResponse(RequestMethod.GET);\n+ }\n+\n+ @Test\n+ public void deleteMethodTest() {\n+ addProxyStub(deleteMappingBuilder());\n+ addEndStub(deleteMappingBuilder());\n+ renderAndCheckResponse(RequestMethod.DELETE);\n+ }\n+\n+ @Test\n+ public void putMethodTest() {\n+ addProxyStub(putMappingBuilder());\n+ addEndStub(putMappingBuilder());\n+ renderAndCheckResponse(RequestMethod.PUT);\n+ }\n+\n+ @Test\n+ public void patchMethodTest() {\n+ addProxyStub(patchMappingBuilder());\n+ addEndStub(patchMappingBuilder());\n+ renderAndCheckResponse(RequestMethod.PATCH);\n+ }\n+\n+ private void renderAndCheckResponse(RequestMethod requestMethod) {\n+ ServeEvent serveEvent = serveEvent(requestMethod);\n+ Response response = proxyResponseRenderer.render(serveEvent);\n+ assertEquals(response.getBodyAsString(), RESPONSE_BODY);\n+ }\n+\n+ private ServeEvent serveEvent(RequestMethod method) {\n+ String path = URL_PATH + \"?\" + QUERY_NAME + \"=\" + QUERY_VALUE;\n+\n+ LoggedRequest loggedRequest =\n+ new LoggedRequest(\n+ /* url = */ path,\n+ /* absoluteUrl = */ proxyInstance.url(path),\n+ /* method = */ method,\n+ /* clientIp = */ \"127.0.0.1\",\n+ /* headers = */ new HttpHeaders(HttpHeader.httpHeader(HEADER_NAME, HEADER_VALUE)),\n+ /* cookies = */ new HashMap<String, Cookie>(),\n+ /* isBrowserProxyRequest = */ false,\n+ /* loggedDate = */ new Date(),\n+ /* body = */ REQUEST_BODY.getBytes(),\n+ /* multiparts = */ null);\n+ ResponseDefinition responseDefinition = aResponse().proxiedFrom(proxyInstance.baseUrl()).build();\n+ responseDefinition.setOriginalRequest(loggedRequest);\n+\n+ return ServeEvent.of(loggedRequest, responseDefinition, new StubMapping());\n+ }\n+\n+ private File generateKeystore() throws Exception {\n+\n+ InMemoryKeyStore ks =\n+ new InMemoryKeyStore(InMemoryKeyStore.KeyStoreType.JKS, new Secret(\"password\"));\n+\n+ CertificateSpecification certificateSpecification =\n+ new X509CertificateSpecification(\n+ /* version = */ V3,\n+ /* subject = */ \"CN=localhost\",\n+ /* issuer = */ \"CN=wiremock.org\",\n+ /* notBefore = */ new Date(),\n+ /* notAfter = */ new Date(System.currentTimeMillis() + (365L * 24 * 60 * 60 * 1000)));\n+ KeyPair keyPair = generateKeyPair();\n+ ks.addPrivateKey(\"wiremock\", keyPair, certificateSpecification.certificateFor(keyPair));\n+\n+ File keystoreFile = File.createTempFile(\"wiremock-test\", \"keystore\");\n+\n+ ks.saveAs(keystoreFile);\n+\n+ return keystoreFile;\n+ }\n+\n+ private KeyPair generateKeyPair() throws NoSuchAlgorithmException {\n+ KeyPairGenerator keyGen = KeyPairGenerator.getInstance(\"RSA\");\n+ keyGen.initialize(1024);\n+ return keyGen.generateKeyPair();\n+ }\n+\n+ private ProxyResponseRenderer buildProxyResponseRenderer(boolean trustAllProxyTargets) {\n+ return new ProxyResponseRenderer(\n+ ProxySettings.NO_PROXY,\n+ KeyStoreSettings.NO_STORE,\n+ /* preserveHostHeader = */ false,\n+ /* hostHeaderValue = */ null,\n+ new GlobalSettingsHolder(),\n+ trustAllProxyTargets,\n+ Collections.<String>emptyList());\n+ }\n+\n+ private WireMockExtension newWireMockInstance() {\n+ WireMockExtension result = null;\n+ try {\n+ result = WireMockExtension.newInstance()\n+ .options(\n+ options()\n+ .httpDisabled(true)\n+ .dynamicHttpsPort()\n+ .keystorePath(generateKeystore().getAbsolutePath()))\n+ .build();\n+ } catch (Exception e) {\n+ e.printStackTrace();\n+ }\n+ return result;\n+ }\n+\n+ private void addProxyStub(MappingBuilder stubBuilder) {\n+ proxyInstance.stubFor(\n+ stubBuilder.willReturn(aResponse().proxiedFrom(endInstance.baseUrl()))\n+ );\n+ }\n+\n+ private void addEndStub(MappingBuilder stubBuilder) {\n+ endInstance.stubFor(\n+ stubBuilder\n+ .withRequestBody(equalToJson(REQUEST_BODY))\n+ .withHeader(HEADER_NAME, equalTo(HEADER_VALUE))\n+ .withQueryParam(QUERY_NAME, equalTo(QUERY_VALUE))\n+ .willReturn(aResponse().withBody(RESPONSE_BODY))\n+ );\n+ }\n+\n+ private UrlPathPattern getUrlPathPattern() {\n+ return urlPathEqualTo(URL_PATH);\n+ }\n+\n+ private MappingBuilder getMappingBuilder() {\n+ return get(getUrlPathPattern());\n+ }\n+\n+ private MappingBuilder postMappingBuilder() {\n+ return post(getUrlPathPattern());\n+ }\n+\n+ private MappingBuilder deleteMappingBuilder() {\n+ return delete(getUrlPathPattern());\n+ }\n+\n+ private MappingBuilder putMappingBuilder() {\n+ return put(getUrlPathPattern());\n+ }\n+\n+ private MappingBuilder patchMappingBuilder() {\n+ return patch(getUrlPathPattern());\n+ }\n+}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | proxy request fix (#1765)
Permit any HTTP request method to have a body when proxying |
686,936 | 06.04.2022 17:55:48 | -3,600 | 78ebf3ab77bbbc23d7119e6ebc55f006fecbe2d8 | Simplified test for proxying any request method body | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"diff": "@@ -46,6 +46,8 @@ import java.io.OutputStream;\nimport java.net.InetSocketAddress;\nimport java.util.Arrays;\nimport java.util.Collection;\n+import java.util.List;\n+\nimport org.apache.hc.client5.http.classic.methods.HttpHead;\nimport org.apache.hc.client5.http.entity.GzipCompressingEntity;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\n@@ -55,8 +57,11 @@ import org.apache.hc.core5.http.HttpEntity;\nimport org.apache.hc.core5.http.io.entity.ByteArrayEntity;\nimport org.apache.hc.core5.http.io.entity.StringEntity;\nimport org.hamcrest.Matchers;\n+import org.junit.experimental.theories.DataPoints;\nimport org.junit.jupiter.api.AfterEach;\nimport org.junit.jupiter.api.Test;\n+import org.junit.jupiter.params.ParameterizedTest;\n+import org.junit.jupiter.params.provider.ValueSource;\npublic class ProxyAcceptanceTest {\n@@ -614,6 +619,25 @@ public class ProxyAcceptanceTest {\nassertThat(response.statusCode(), is(200));\n}\n+ @ParameterizedTest\n+ @ValueSource(strings = {\"GET\",\"HEAD\",\"POST\",\"PUT\",\"PATCH\",\"DELETE\",\"BLAH\"})\n+ void proxiesRequestBodyForAnyMethod(String method) {\n+ initWithDefaultConfig();\n+\n+ target.register(any(anyUrl())\n+ .willReturn(ok()));\n+\n+ proxy.register(any(anyUrl())\n+ .willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));\n+\n+ testClient.request(method, \"/somewhere\", \"Proxied content\");\n+\n+ List<LoggedRequest> requests = target.find(anyRequestedFor(urlEqualTo(\"/somewhere\")));\n+ assertThat(requests.size(), is(1));\n+ assertThat(requests.get(0).getMethod().getName(), is(method));\n+ assertThat(requests.get(0).getBodyAsString(), is(\"Proxied content\"));\n+ }\n+\nprivate void register200StubOnProxyAndTarget(String url) {\ntarget.register(get(urlEqualTo(url)).willReturn(aResponse().withStatus(200)));\nproxy.register(get(urlEqualTo(url)).willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));\n"
},
{
"change_type": "DELETE",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyBaseUrlTest.java",
"new_path": null,
"diff": "-/*\n- * Copyright (C) 2020-2021 Thomas Akehurst\n- *\n- * Licensed under the Apache License, Version 2.0 (the \"License\");\n- * you may not use this file except in compliance with the License.\n- * You may obtain a copy of the License at\n- *\n- * http://www.apache.org/licenses/LICENSE-2.0\n- *\n- * Unless required by applicable law or agreed to in writing, software\n- * distributed under the License is distributed on an \"AS IS\" BASIS,\n- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n- * See the License for the specific language governing permissions and\n- * limitations under the License.\n- */\n-package com.github.tomakehurst.wiremock.http;\n-\n-import com.github.tomakehurst.wiremock.client.MappingBuilder;\n-import com.github.tomakehurst.wiremock.common.ProxySettings;\n-import com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings;\n-import com.github.tomakehurst.wiremock.crypto.CertificateSpecification;\n-import com.github.tomakehurst.wiremock.crypto.InMemoryKeyStore;\n-import com.github.tomakehurst.wiremock.crypto.Secret;\n-import com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification;\n-import com.github.tomakehurst.wiremock.global.GlobalSettingsHolder;\n-import com.github.tomakehurst.wiremock.junit5.WireMockExtension;\n-import com.github.tomakehurst.wiremock.matching.UrlPathPattern;\n-import com.github.tomakehurst.wiremock.stubbing.ServeEvent;\n-import com.github.tomakehurst.wiremock.stubbing.StubMapping;\n-import com.github.tomakehurst.wiremock.verification.LoggedRequest;\n-import org.junit.jupiter.api.Test;\n-import org.junit.jupiter.api.condition.DisabledForJreRange;\n-import org.junit.jupiter.api.condition.JRE;\n-import org.junit.jupiter.api.extension.RegisterExtension;\n-\n-import java.io.File;\n-import java.security.KeyPair;\n-import java.security.KeyPairGenerator;\n-import java.security.NoSuchAlgorithmException;\n-import java.util.Collections;\n-import java.util.Date;\n-import java.util.HashMap;\n-import java.util.Map;\n-\n-import static com.github.tomakehurst.wiremock.client.WireMock.*;\n-import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;\n-import static com.github.tomakehurst.wiremock.crypto.X509CertificateVersion.V3;\n-import static org.hamcrest.MatcherAssert.assertThat;\n-import static org.junit.jupiter.api.Assertions.assertEquals;\n-\n-@DisabledForJreRange(\n- min = JRE.JAVA_17,\n- disabledReason = \"does not support generating certificates at runtime\")\n-public class ProxyBaseUrlTest {\n-\n- @RegisterExtension\n- public WireMockExtension endInstance = newWireMockInstance();\n-\n- @RegisterExtension\n- public WireMockExtension proxyInstance = newWireMockInstance();\n-\n- private final ProxyResponseRenderer proxyResponseRenderer = buildProxyResponseRenderer(false);\n-\n- private final String URL_PATH = \"/api\";\n- private final String REQUEST_BODY = \"{\\\"test\\\":true}\";\n- private final String RESPONSE_BODY = \"Result\";\n- private final String HEADER_NAME = \"testHeader\";\n- private final String HEADER_VALUE = \"testHeaderValue\";\n- private final String QUERY_NAME = \"testParam\";\n- private final String QUERY_VALUE = \"testParamValue\";\n-\n- @Test\n- public void postMethodTest() {\n- addProxyStub(postMappingBuilder());\n- addEndStub(postMappingBuilder());\n- renderAndCheckResponse(RequestMethod.POST);\n- }\n-\n- @Test\n- public void getMethodTest() {\n- addProxyStub(getMappingBuilder());\n- addEndStub(getMappingBuilder());\n- renderAndCheckResponse(RequestMethod.GET);\n- }\n-\n- @Test\n- public void deleteMethodTest() {\n- addProxyStub(deleteMappingBuilder());\n- addEndStub(deleteMappingBuilder());\n- renderAndCheckResponse(RequestMethod.DELETE);\n- }\n-\n- @Test\n- public void putMethodTest() {\n- addProxyStub(putMappingBuilder());\n- addEndStub(putMappingBuilder());\n- renderAndCheckResponse(RequestMethod.PUT);\n- }\n-\n- @Test\n- public void patchMethodTest() {\n- addProxyStub(patchMappingBuilder());\n- addEndStub(patchMappingBuilder());\n- renderAndCheckResponse(RequestMethod.PATCH);\n- }\n-\n- private void renderAndCheckResponse(RequestMethod requestMethod) {\n- ServeEvent serveEvent = serveEvent(requestMethod);\n- Response response = proxyResponseRenderer.render(serveEvent);\n- assertEquals(response.getBodyAsString(), RESPONSE_BODY);\n- }\n-\n- private ServeEvent serveEvent(RequestMethod method) {\n- String path = URL_PATH + \"?\" + QUERY_NAME + \"=\" + QUERY_VALUE;\n-\n- LoggedRequest loggedRequest =\n- new LoggedRequest(\n- /* url = */ path,\n- /* absoluteUrl = */ proxyInstance.url(path),\n- /* method = */ method,\n- /* clientIp = */ \"127.0.0.1\",\n- /* headers = */ new HttpHeaders(HttpHeader.httpHeader(HEADER_NAME, HEADER_VALUE)),\n- /* cookies = */ new HashMap<String, Cookie>(),\n- /* isBrowserProxyRequest = */ false,\n- /* loggedDate = */ new Date(),\n- /* body = */ REQUEST_BODY.getBytes(),\n- /* multiparts = */ null);\n- ResponseDefinition responseDefinition = aResponse().proxiedFrom(proxyInstance.baseUrl()).build();\n- responseDefinition.setOriginalRequest(loggedRequest);\n-\n- return ServeEvent.of(loggedRequest, responseDefinition, new StubMapping());\n- }\n-\n- private File generateKeystore() throws Exception {\n-\n- InMemoryKeyStore ks =\n- new InMemoryKeyStore(InMemoryKeyStore.KeyStoreType.JKS, new Secret(\"password\"));\n-\n- CertificateSpecification certificateSpecification =\n- new X509CertificateSpecification(\n- /* version = */ V3,\n- /* subject = */ \"CN=localhost\",\n- /* issuer = */ \"CN=wiremock.org\",\n- /* notBefore = */ new Date(),\n- /* notAfter = */ new Date(System.currentTimeMillis() + (365L * 24 * 60 * 60 * 1000)));\n- KeyPair keyPair = generateKeyPair();\n- ks.addPrivateKey(\"wiremock\", keyPair, certificateSpecification.certificateFor(keyPair));\n-\n- File keystoreFile = File.createTempFile(\"wiremock-test\", \"keystore\");\n-\n- ks.saveAs(keystoreFile);\n-\n- return keystoreFile;\n- }\n-\n- private KeyPair generateKeyPair() throws NoSuchAlgorithmException {\n- KeyPairGenerator keyGen = KeyPairGenerator.getInstance(\"RSA\");\n- keyGen.initialize(1024);\n- return keyGen.generateKeyPair();\n- }\n-\n- private ProxyResponseRenderer buildProxyResponseRenderer(boolean trustAllProxyTargets) {\n- return new ProxyResponseRenderer(\n- ProxySettings.NO_PROXY,\n- KeyStoreSettings.NO_STORE,\n- /* preserveHostHeader = */ false,\n- /* hostHeaderValue = */ null,\n- new GlobalSettingsHolder(),\n- trustAllProxyTargets,\n- Collections.<String>emptyList());\n- }\n-\n- private WireMockExtension newWireMockInstance() {\n- WireMockExtension result = null;\n- try {\n- result = WireMockExtension.newInstance()\n- .options(\n- options()\n- .httpDisabled(true)\n- .dynamicHttpsPort()\n- .keystorePath(generateKeystore().getAbsolutePath()))\n- .build();\n- } catch (Exception e) {\n- e.printStackTrace();\n- }\n- return result;\n- }\n-\n- private void addProxyStub(MappingBuilder stubBuilder) {\n- proxyInstance.stubFor(\n- stubBuilder.willReturn(aResponse().proxiedFrom(endInstance.baseUrl()))\n- );\n- }\n-\n- private void addEndStub(MappingBuilder stubBuilder) {\n- endInstance.stubFor(\n- stubBuilder\n- .withRequestBody(equalToJson(REQUEST_BODY))\n- .withHeader(HEADER_NAME, equalTo(HEADER_VALUE))\n- .withQueryParam(QUERY_NAME, equalTo(QUERY_VALUE))\n- .willReturn(aResponse().withBody(RESPONSE_BODY))\n- );\n- }\n-\n- private UrlPathPattern getUrlPathPattern() {\n- return urlPathEqualTo(URL_PATH);\n- }\n-\n- private MappingBuilder getMappingBuilder() {\n- return get(getUrlPathPattern());\n- }\n-\n- private MappingBuilder postMappingBuilder() {\n- return post(getUrlPathPattern());\n- }\n-\n- private MappingBuilder deleteMappingBuilder() {\n- return delete(getUrlPathPattern());\n- }\n-\n- private MappingBuilder putMappingBuilder() {\n- return put(getUrlPathPattern());\n- }\n-\n- private MappingBuilder patchMappingBuilder() {\n- return patch(getUrlPathPattern());\n- }\n-}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/testsupport/WireMockTestClient.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/testsupport/WireMockTestClient.java",
"diff": "@@ -327,6 +327,13 @@ public class WireMockTestClient {\nreturn executeMethodAndConvertExceptions(httpRequest, headers);\n}\n+ public WireMockResponse request(final String methodName, String url, String body, TestHttpHeader... headers) {\n+ HttpUriRequest httpRequest =\n+ new HttpUriRequestBase(methodName, URI.create(mockServiceUrlFor(url)));\n+ httpRequest.setEntity(new StringEntity(body));\n+ return executeMethodAndConvertExceptions(httpRequest, headers);\n+ }\n+\nprivate static CloseableHttpClient httpClient() {\nreturn HttpClientBuilder.create()\n.disableAuthCaching()\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Simplified test for proxying any request method body |
686,936 | 07.04.2022 11:45:14 | -3,600 | a56f618ba048f85770e558600435163f2e0947f6 | Closes closes CORS headers are now passed through by the proxy when stub CORS is disabled | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"diff": "/*\n- * Copyright (C) 2012-2021 Thomas Akehurst\n+ * Copyright (C) 2012-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -175,7 +175,8 @@ public class WireMockApp implements StubServer, Admin {\noptions.proxyHostHeader(),\nglobalSettingsHolder,\nbrowserProxySettings.trustAllProxyTargets(),\n- browserProxySettings.trustedProxyTargets()),\n+ browserProxySettings.trustedProxyTargets(),\n+ options.getStubCorsEnabled()),\nImmutableList.copyOf(options.extensionsOfType(ResponseTransformer.class).values())),\nthis,\npostServeActions,\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -59,6 +59,7 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nprivate final boolean preserveHostHeader;\nprivate final String hostHeaderValue;\nprivate final GlobalSettingsHolder globalSettingsHolder;\n+ private final boolean stubCorsEnabled;\npublic ProxyResponseRenderer(\nProxySettings proxySettings,\n@@ -67,7 +68,8 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nString hostHeaderValue,\nGlobalSettingsHolder globalSettingsHolder,\nboolean trustAllProxyTargets,\n- List<String> trustedProxyTargets) {\n+ List<String> trustedProxyTargets,\n+ boolean stubCorsEnabled) {\nthis.globalSettingsHolder = globalSettingsHolder;\nreverseProxyClient =\nHttpClientFactory.createClient(\n@@ -90,6 +92,7 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nthis.preserveHostHeader = preserveHostHeader;\nthis.hostHeaderValue = hostHeaderValue;\n+ this.stubCorsEnabled = stubCorsEnabled;\n}\n@Override\n@@ -201,10 +204,10 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nreturn !FORBIDDEN_REQUEST_HEADERS.contains(key.toLowerCase());\n}\n- private static boolean responseHeaderShouldBeTransferred(String key) {\n+ private boolean responseHeaderShouldBeTransferred(String key) {\nfinal String lowerCaseKey = key.toLowerCase();\nreturn !FORBIDDEN_RESPONSE_HEADERS.contains(lowerCaseKey)\n- && !lowerCaseKey.startsWith(\"access-control\");\n+ && (!stubCorsEnabled || !lowerCaseKey.startsWith(\"access-control\"));\n}\nprivate static HttpEntity buildEntityFrom(Request originalRequest) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -45,9 +45,7 @@ import java.io.InputStream;\nimport java.io.OutputStream;\nimport java.net.InetSocketAddress;\nimport java.util.Arrays;\n-import java.util.Collection;\nimport java.util.List;\n-\nimport org.apache.hc.client5.http.classic.methods.HttpHead;\nimport org.apache.hc.client5.http.entity.GzipCompressingEntity;\nimport org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\n@@ -57,7 +55,6 @@ import org.apache.hc.core5.http.HttpEntity;\nimport org.apache.hc.core5.http.io.entity.ByteArrayEntity;\nimport org.apache.hc.core5.http.io.entity.StringEntity;\nimport org.hamcrest.Matchers;\n-import org.junit.experimental.theories.DataPoints;\nimport org.junit.jupiter.api.AfterEach;\nimport org.junit.jupiter.api.Test;\nimport org.junit.jupiter.params.ParameterizedTest;\n@@ -585,22 +582,6 @@ public class ProxyAcceptanceTest {\nassertThat(stopwatch.elapsed(MILLISECONDS), greaterThanOrEqualTo(300L));\n}\n- @Test\n- public void stripsCorsHeadersFromTheTarget() {\n- initWithDefaultConfig();\n-\n- proxy.register(any(anyUrl()).willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));\n-\n- target.register(any(urlPathEqualTo(\"/cors\")).withName(\"Target with CORS\").willReturn(ok()));\n-\n- WireMockResponse response =\n- testClient.get(\"/cors\", withHeader(\"Origin\", \"http://somewhere.com\"));\n-\n- Collection<String> allowOriginHeaderValues =\n- response.headers().get(\"Access-Control-Allow-Origin\");\n- assertThat(allowOriginHeaderValues.size(), is(0));\n- }\n-\n@Test\npublic void removesPrefixFromProxyRequestWhenMatching() {\ninitWithDefaultConfig();\n@@ -624,11 +605,9 @@ public class ProxyAcceptanceTest {\nvoid proxiesRequestBodyForAnyMethod(String method) {\ninitWithDefaultConfig();\n- target.register(any(anyUrl())\n- .willReturn(ok()));\n+ target.register(any(anyUrl()).willReturn(ok()));\n- proxy.register(any(anyUrl())\n- .willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));\n+ proxy.register(any(anyUrl()).willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));\ntestClient.request(method, \"/somewhere\", \"Proxied content\");\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyResponseRendererTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyResponseRendererTest.java",
"diff": "/*\n- * Copyright (C) 2020-2021 Thomas Akehurst\n+ * Copyright (C) 2020-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n*/\npackage com.github.tomakehurst.wiremock.http;\n-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;\n-import static com.github.tomakehurst.wiremock.client.WireMock.get;\n+import static com.github.tomakehurst.wiremock.client.WireMock.*;\nimport static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;\nimport static com.github.tomakehurst.wiremock.crypto.X509CertificateVersion.V3;\nimport static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;\nimport static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\nimport static org.hamcrest.core.StringContains.containsString;\nimport static org.hamcrest.core.StringStartsWith.startsWith;\nimport static org.junit.jupiter.api.Assertions.assertEquals;\n@@ -99,18 +99,53 @@ public class ProxyResponseRendererTest {\n@Test\npublic void acceptsSelfSignedCertificateForForwardProxyingIfTrustAllProxyTargets() {\n-\n- final ProxyResponseRenderer trustAllProxyResponseRenderer = buildProxyResponseRenderer(true);\n+ ProxyResponseRenderer trustAllProxyResponseRenderer = buildProxyResponseRenderer(true);\norigin.stubFor(get(\"/proxied\").willReturn(aResponse().withBody(\"Result\")));\n- final ServeEvent serveEvent = forwardProxyServeEvent(\"/proxied\");\n-\n+ ServeEvent serveEvent = forwardProxyServeEvent(\"/proxied\");\nResponse response = trustAllProxyResponseRenderer.render(serveEvent);\nassertEquals(response.getBodyAsString(), \"Result\");\n}\n+ @Test\n+ void passesThroughCorsResponseHeadersWhenStubCorsDisabled() {\n+ ProxyResponseRenderer responseRenderer = buildProxyResponseRenderer(true, false);\n+\n+ origin.stubFor(\n+ get(\"/proxied\")\n+ .willReturn(ok(\"Result\").withHeader(\"Access-Control-Allow-Headers\", \"X-Blah\")));\n+\n+ ServeEvent serveEvent = forwardProxyServeEvent(\"/proxied\");\n+ Response response = responseRenderer.render(serveEvent);\n+\n+ HttpHeader corsHeader = response.getHeaders().getHeader(\"Access-Control-Allow-Headers\");\n+ assertThat(\n+ \"CORS response header sent from the origin is not present in the response\",\n+ corsHeader.isPresent(),\n+ is(true));\n+ assertThat(corsHeader.firstValue(), is(\"X-Blah\"));\n+ }\n+\n+ @Test\n+ void doesNotPassThroughCorsResponseHeadersWhenStubCorsEnabled() {\n+ ProxyResponseRenderer responseRenderer = buildProxyResponseRenderer(true, true);\n+\n+ origin.stubFor(\n+ get(\"/proxied\")\n+ .willReturn(ok(\"Result\").withHeader(\"Access-Control-Allow-Headers\", \"X-Blah\")));\n+\n+ ServeEvent serveEvent = forwardProxyServeEvent(\"/proxied\");\n+ Response response = responseRenderer.render(serveEvent);\n+\n+ HttpHeader corsHeader = response.getHeaders().getHeader(\"Access-Control-Allow-Headers\");\n+ assertThat(\n+ \"CORS response header sent from the origin is present in the response\",\n+ corsHeader.isPresent(),\n+ is(false));\n+ }\n+\nprivate ServeEvent reverseProxyServeEvent(String path) {\nreturn serveEvent(path, false);\n}\n@@ -167,6 +202,11 @@ public class ProxyResponseRendererTest {\n}\nprivate ProxyResponseRenderer buildProxyResponseRenderer(boolean trustAllProxyTargets) {\n+ return buildProxyResponseRenderer(trustAllProxyTargets, false);\n+ }\n+\n+ private ProxyResponseRenderer buildProxyResponseRenderer(\n+ boolean trustAllProxyTargets, boolean stubCorsEnabled) {\nreturn new ProxyResponseRenderer(\nProxySettings.NO_PROXY,\nKeyStoreSettings.NO_STORE,\n@@ -174,7 +214,8 @@ public class ProxyResponseRendererTest {\n/* hostHeaderValue = */ null,\nnew GlobalSettingsHolder(),\ntrustAllProxyTargets,\n- Collections.<String>emptyList());\n+ Collections.<String>emptyList(),\n+ stubCorsEnabled);\n}\n// Just exists to make the compiler happy by having the throws clause\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Closes #1543, closes #1389; CORS headers are now passed through by the proxy when stub CORS is disabled |
686,936 | 07.04.2022 13:13:01 | -3,600 | 106c00896247da81a240ff5dd1d74d2f18e51270 | Removed docs-v2 entries from bump version tasks in build | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -389,8 +389,6 @@ task 'bump-patch-version' {\ndoLast {\ndef filesWithVersion = [\n'build.gradle' : { \"version = '${it}\" },\n- 'docs-v2/_config.yml' : { \"wiremock_version: ${it}\" },\n- 'docs-v2/package.json' : { \"version\\\": \\\"${it}\\\"\" },\n'src/main/resources/swagger/wiremock-admin-api.yaml': {\n\"version: ${it}\" }\n]\n@@ -416,8 +414,6 @@ task 'bump-minor-version' {\ndoLast {\ndef filesWithVersion = [\n'build.gradle' : { \"version = '${it}\" },\n- 'docs-v2/_config.yml' : { \"wiremock_version: ${it}\" },\n- 'docs-v2/package.json' : { \"version\\\": \\\"${it}\\\"\" },\n'src/main/resources/swagger/wiremock-admin-api.yaml': {\n\"version: ${it}\" }\n]\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Removed docs-v2 entries from bump version tasks in build |
686,936 | 07.04.2022 13:39:18 | -3,600 | abf6cc751cb37c0c4f7ea23ea2a9899323f3cc39 | Added localRelease build task | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -385,6 +385,10 @@ task release {\ndependsOn clean, assemble, publishAllPublicationsToMavenRepository, addGitTag\n}\n+task localRelease {\n+ dependsOn clean, assemble, publishToMavenLocal\n+}\n+\ntask 'bump-patch-version' {\ndoLast {\ndef filesWithVersion = [\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added localRelease build task |
686,936 | 07.04.2022 14:08:25 | -3,600 | 70a31fa82c9d34be7b1c3e5cc44e652dc836dba9 | Closes closes Added ability to set and reset a single scenario's state | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/WireMockServer.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -440,6 +440,16 @@ public class WireMockServer implements Container, Stubbing, Admin {\nreturn wireMockApp.getAllScenarios();\n}\n+ @Override\n+ public void resetScenario(String name) {\n+ wireMockApp.resetScenario(name);\n+ }\n+\n+ @Override\n+ public void setScenarioState(String name, String state) {\n+ wireMockApp.setScenarioState(name, state);\n+ }\n+\n@Override\npublic FindNearMissesResult findTopNearMissesFor(LoggedRequest loggedRequest) {\nreturn wireMockApp.findTopNearMissesFor(loggedRequest);\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/admin/AdminRoutes.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/admin/AdminRoutes.java",
"diff": "@@ -81,6 +81,7 @@ public class AdminRoutes {\nrouter.add(GET, \"/scenarios\", GetAllScenariosTask.class);\nrouter.add(POST, \"/scenarios/reset\", ResetScenariosTask.class);\n+ router.add(PUT, \"/scenarios/{name}/state\", SetScenarioStateTask.class);\nrouter.add(GET, \"/requests\", GetAllRequestsTask.class);\nrouter.add(DELETE, \"/requests\", ResetRequestsTask.class);\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/main/java/com/github/tomakehurst/wiremock/admin/SetScenarioStateTask.java",
"diff": "+/*\n+ * Copyright (C) 2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.admin;\n+\n+import com.github.tomakehurst.wiremock.admin.model.PathParams;\n+import com.github.tomakehurst.wiremock.admin.model.ScenarioState;\n+import com.github.tomakehurst.wiremock.common.Json;\n+import com.github.tomakehurst.wiremock.core.Admin;\n+import com.github.tomakehurst.wiremock.http.Request;\n+import com.github.tomakehurst.wiremock.http.ResponseDefinition;\n+\n+public class SetScenarioStateTask implements AdminTask {\n+\n+ @Override\n+ public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {\n+ String name = pathParams.get(\"name\");\n+ if (request.getBody() != null && !request.getBodyAsString().isEmpty()) {\n+ ScenarioState scenarioState = Json.read(request.getBodyAsString(), ScenarioState.class);\n+ admin.setScenarioState(name, scenarioState.getState());\n+ } else {\n+ admin.resetScenario(name);\n+ }\n+\n+ return ResponseDefinition.okEmptyJson();\n+ }\n+}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/main/java/com/github/tomakehurst/wiremock/admin/model/ScenarioState.java",
"diff": "+/*\n+ * Copyright (C) 2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.admin.model;\n+\n+import com.fasterxml.jackson.annotation.JsonProperty;\n+\n+public class ScenarioState {\n+\n+ private final String state;\n+\n+ public ScenarioState(@JsonProperty(\"state\") String state) {\n+ this.state = state;\n+ }\n+\n+ public String getState() {\n+ return state;\n+ }\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/client/HttpAdminClient.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/client/HttpAdminClient.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -294,6 +294,23 @@ public class HttpAdminClient implements Admin {\nadminRoutes.requestSpecForTask(GetAllScenariosTask.class), GetScenariosResult.class);\n}\n+ @Override\n+ public void resetScenario(String name) {\n+ executeRequest(\n+ adminRoutes.requestSpecForTask(SetScenarioStateTask.class),\n+ PathParams.single(\"name\", name),\n+ Void.class);\n+ }\n+\n+ @Override\n+ public void setScenarioState(String name, String state) {\n+ executeRequest(\n+ adminRoutes.requestSpecForTask(SetScenarioStateTask.class),\n+ PathParams.single(\"name\", name),\n+ new ScenarioState(state),\n+ Void.class);\n+ }\n+\n@Override\npublic FindNearMissesResult findTopNearMissesFor(LoggedRequest loggedRequest) {\nString body =\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -368,6 +368,22 @@ public class WireMock {\nadmin.resetScenarios();\n}\n+ public static void resetScenario(String name) {\n+ defaultInstance.get().resetScenarioState(name);\n+ }\n+\n+ public void resetScenarioState(String name) {\n+ admin.resetScenario(name);\n+ }\n+\n+ public static void setScenarioState(String name, String state) {\n+ defaultInstance.get().setSingleScenarioState(name, state);\n+ }\n+\n+ public void setSingleScenarioState(String name, String state) {\n+ admin.setScenarioState(name, state);\n+ }\n+\npublic static List<Scenario> getAllScenarios() {\nreturn defaultInstance.get().getScenarios();\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/Admin.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/Admin.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -78,6 +78,10 @@ public interface Admin {\nGetScenariosResult getAllScenarios();\n+ void resetScenario(String name);\n+\n+ void setScenarioState(String name, String state);\n+\nvoid updateGlobalSettings(GlobalSettings settings);\nSnapshotRecordResult snapshotRecord();\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"diff": "@@ -410,6 +410,16 @@ public class WireMockApp implements StubServer, Admin {\nreturn new GetScenariosResult(stubMappings.getAllScenarios());\n}\n+ @Override\n+ public void resetScenario(String name) {\n+ scenarios.resetSingle(name);\n+ }\n+\n+ @Override\n+ public void setScenarioState(String name, String state) {\n+ scenarios.setSingle(name, state);\n+ }\n+\n@Override\npublic FindNearMissesResult findTopNearMissesFor(LoggedRequest loggedRequest) {\nreturn new FindNearMissesResult(nearMissCalculator.findNearestTo(loggedRequest));\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/junit/DslWrapper.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/junit/DslWrapper.java",
"diff": "/*\n- * Copyright (C) 2021 Thomas Akehurst\n+ * Copyright (C) 2021-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -161,6 +161,16 @@ public class DslWrapper implements Admin, Stubbing {\nreturn admin.getAllScenarios();\n}\n+ @Override\n+ public void resetScenario(String name) {\n+ admin.resetScenario(name);\n+ }\n+\n+ @Override\n+ public void setScenarioState(String name, String state) {\n+ admin.setScenarioState(name, state);\n+ }\n+\n@Override\npublic void updateGlobalSettings(GlobalSettings settings) {\nadmin.updateGlobalSettings(settings);\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenario.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenario.java",
"diff": "/*\n- * Copyright (C) 2012-2021 Thomas Akehurst\n+ * Copyright (C) 2012-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -18,6 +18,7 @@ package com.github.tomakehurst.wiremock.stubbing;\nimport static com.google.common.collect.FluentIterable.from;\nimport com.fasterxml.jackson.annotation.JsonCreator;\n+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;\nimport com.fasterxml.jackson.annotation.JsonProperty;\nimport com.github.tomakehurst.wiremock.common.Json;\nimport com.google.common.base.Function;\n@@ -28,43 +29,37 @@ import com.google.common.collect.ImmutableSet;\nimport com.google.common.collect.Sets;\nimport java.util.*;\n+@JsonIgnoreProperties({\"name\"})\npublic class Scenario {\npublic static final String STARTED = \"Started\";\n- private final UUID id;\n- private final String name;\n+ private final String id;\nprivate final String state;\nprivate final Set<StubMapping> stubMappings;\n@JsonCreator\npublic Scenario(\n- @JsonProperty(\"id\") UUID id,\n- @JsonProperty(\"name\") String name,\n+ @JsonProperty(\"id\") String id,\n@JsonProperty(\"state\") String currentState,\n@JsonProperty(\"possibleStates\") Set<String> ignored,\n@JsonProperty(\"mappings\") Set<StubMapping> stubMappings) {\nthis.id = id;\n- this.name = name;\nthis.state = currentState;\nthis.stubMappings = stubMappings;\n}\npublic static Scenario inStartedState(String name) {\n- return new Scenario(\n- UUID.randomUUID(),\n- name,\n- STARTED,\n- ImmutableSet.of(STARTED),\n- Collections.<StubMapping>emptySet());\n+ return new Scenario(name, STARTED, ImmutableSet.of(STARTED), Collections.emptySet());\n}\n- public UUID getId() {\n+ public String getId() {\nreturn id;\n}\n+ // For JSON backwards compatibility\npublic String getName() {\n- return name;\n+ return id;\n}\npublic String getState() {\n@@ -100,23 +95,23 @@ public class Scenario {\n}\nScenario setState(String newState) {\n- return new Scenario(id, name, newState, null, stubMappings);\n+ return new Scenario(id, newState, null, stubMappings);\n}\nScenario reset() {\n- return new Scenario(id, name, STARTED, null, stubMappings);\n+ return new Scenario(id, STARTED, null, stubMappings);\n}\nScenario withStubMapping(StubMapping stubMapping) {\nSet<StubMapping> newMappings =\nImmutableSet.<StubMapping>builder().addAll(stubMappings).add(stubMapping).build();\n- return new Scenario(id, name, state, null, newMappings);\n+ return new Scenario(id, state, null, newMappings);\n}\nScenario withoutStubMapping(StubMapping stubMapping) {\nSet<StubMapping> newMappings = Sets.difference(stubMappings, ImmutableSet.of(stubMapping));\n- return new Scenario(id, name, state, null, newMappings);\n+ return new Scenario(id, state, null, newMappings);\n}\n@Override\n@@ -130,21 +125,20 @@ public class Scenario {\nif (o == null || getClass() != o.getClass()) return false;\nScenario scenario = (Scenario) o;\nreturn Objects.equals(getId(), scenario.getId())\n- && Objects.equals(getName(), scenario.getName())\n&& Objects.equals(getState(), scenario.getState())\n&& Objects.equals(getMappings(), scenario.getMappings());\n}\n@Override\npublic int hashCode() {\n- return Objects.hash(getId(), getName(), getState(), getMappings());\n+ return Objects.hash(getId(), getState(), getMappings());\n}\npublic static final Predicate<Scenario> withName(final String name) {\nreturn new Predicate<Scenario>() {\n@Override\npublic boolean apply(Scenario input) {\n- return input.getName().equals(name);\n+ return input.getId().equals(name);\n}\n};\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenarios.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenarios.java",
"diff": "/*\n- * Copyright (C) 2017-2021 Thomas Akehurst\n+ * Copyright (C) 2017-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -52,7 +52,7 @@ public class Scenarios {\nscenarioMap.get(oldMapping.getScenarioName()).withoutStubMapping(oldMapping);\nif (scenarioForOldMapping.getMappings().isEmpty()) {\n- scenarioMap.remove(scenarioForOldMapping.getName());\n+ scenarioMap.remove(scenarioForOldMapping.getId());\n} else {\nscenarioMap.put(oldMapping.getScenarioName(), scenarioForOldMapping);\n}\n@@ -105,6 +105,16 @@ public class Scenarios {\n}));\n}\n+ public void resetSingle(String name) {\n+ Scenario scenario = scenarioMap.get(name);\n+ scenarioMap.replace(name, scenario.reset());\n+ }\n+\n+ public void setSingle(String name, String state) {\n+ Scenario scenario = scenarioMap.get(name);\n+ scenarioMap.replace(name, scenario.setState(state));\n+ }\n+\npublic void clear() {\nscenarioMap.clear();\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"diff": "/*\n- * Copyright (C) 2012-2021 Thomas Akehurst\n+ * Copyright (C) 2012-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\npackage com.github.tomakehurst.wiremock;\nimport static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.client.WireMock.resetScenario;\nimport static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED;\nimport static com.github.tomakehurst.wiremock.stubbing.Scenario.withName;\nimport static com.google.common.collect.Iterables.find;\n@@ -133,7 +134,6 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\nList<Scenario> scenarios = getAllScenarios();\nScenario scenario1 = find(scenarios, withName(\"scenario_one\"));\n- assertThat(scenario1.getId(), notNullValue(UUID.class));\nassertThat(scenario1.getPossibleStates(), hasItems(STARTED, \"state_2\"));\nassertThat(scenario1.getState(), is(\"state_2\"));\n@@ -202,7 +202,7 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\n.willReturn(ok(\"2\")));\nassertThat(getAllScenarios().size(), is(1));\n- assertThat(getAllScenarios().get(0).getName(), is(OLD_NAME));\n+ assertThat(getAllScenarios().get(0).getId(), is(OLD_NAME));\neditStub(\nget(\"/scenarios/33\")\n@@ -220,7 +220,7 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\n.willReturn(ok(\"2\")));\nassertThat(getAllScenarios().size(), is(1));\n- assertThat(getAllScenarios().get(0).getName(), is(NEW_NAME));\n+ assertThat(getAllScenarios().get(0).getId(), is(NEW_NAME));\n}\n@Test\n@@ -245,4 +245,48 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\n.atPriority(1)\n.willSetStateTo(\"Next State\");\n}\n+\n+ @Test\n+ public void resetsASingleScenarioByName() {\n+ stubFor(\n+ get(\"/one\")\n+ .inScenario(\"reset-me\")\n+ .whenScenarioStateIs(STARTED)\n+ .willSetStateTo(\"2\")\n+ .willReturn(ok(\"started\")));\n+\n+ stubFor(get(\"/one\").inScenario(\"reset-me\").whenScenarioStateIs(\"2\").willReturn(ok(\"2\")));\n+\n+ testClient.get(\"/one\");\n+ assertThat(testClient.get(\"/one\").content(), is(\"2\"));\n+\n+ resetScenario(\"reset-me\");\n+\n+ assertThat(testClient.get(\"/one\").content(), is(\"started\"));\n+ }\n+\n+ @Test\n+ public void setsASingleScenarioStateByName() {\n+ stubFor(\n+ get(\"/one\")\n+ .inScenario(\"set-me\")\n+ .whenScenarioStateIs(STARTED)\n+ .willSetStateTo(\"2\")\n+ .willReturn(ok(\"started\")));\n+\n+ stubFor(\n+ get(\"/one\")\n+ .inScenario(\"set-me\")\n+ .whenScenarioStateIs(\"2\")\n+ .willSetStateTo(\"3\")\n+ .willReturn(ok(\"2\")));\n+ stubFor(get(\"/one\").inScenario(\"set-me\").whenScenarioStateIs(\"3\").willReturn(ok(\"3\")));\n+\n+ testClient.get(\"/one\");\n+ assertThat(testClient.get(\"/one\").content(), is(\"2\"));\n+ assertThat(testClient.get(\"/one\").content(), is(\"3\"));\n+\n+ setScenarioState(\"set-me\", \"2\");\n+ assertThat(testClient.get(\"/one\").content(), is(\"2\"));\n+ }\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Closes #1721, closes #1079; Added ability to set and reset a single scenario's state |
686,936 | 09.04.2022 11:41:40 | -3,600 | c4f26780f576cfd90df3fe226ce9d52306bade6e | Fixed - unintended removal of name field on scenarios | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenario.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenario.java",
"diff": "@@ -18,7 +18,6 @@ package com.github.tomakehurst.wiremock.stubbing;\nimport static com.google.common.collect.FluentIterable.from;\nimport com.fasterxml.jackson.annotation.JsonCreator;\n-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;\nimport com.fasterxml.jackson.annotation.JsonProperty;\nimport com.github.tomakehurst.wiremock.common.Json;\nimport com.google.common.base.Function;\n@@ -29,7 +28,6 @@ import com.google.common.collect.ImmutableSet;\nimport com.google.common.collect.Sets;\nimport java.util.*;\n-@JsonIgnoreProperties({\"name\"})\npublic class Scenario {\npublic static final String STARTED = \"Started\";\n@@ -41,16 +39,21 @@ public class Scenario {\n@JsonCreator\npublic Scenario(\n@JsonProperty(\"id\") String id,\n+ @JsonProperty(\"name\") String ignored,\n@JsonProperty(\"state\") String currentState,\n- @JsonProperty(\"possibleStates\") Set<String> ignored,\n+ @JsonProperty(\"possibleStates\") Set<String> ignored2,\n@JsonProperty(\"mappings\") Set<StubMapping> stubMappings) {\nthis.id = id;\nthis.state = currentState;\nthis.stubMappings = stubMappings;\n}\n+ private Scenario(String id, String state, Set<StubMapping> stubMappings) {\n+ this(id, null, state, null, stubMappings);\n+ }\n+\npublic static Scenario inStartedState(String name) {\n- return new Scenario(name, STARTED, ImmutableSet.of(STARTED), Collections.emptySet());\n+ return new Scenario(name, STARTED, Collections.emptySet());\n}\npublic String getId() {\n@@ -95,23 +98,23 @@ public class Scenario {\n}\nScenario setState(String newState) {\n- return new Scenario(id, newState, null, stubMappings);\n+ return new Scenario(id, newState, stubMappings);\n}\nScenario reset() {\n- return new Scenario(id, STARTED, null, stubMappings);\n+ return new Scenario(id, STARTED, stubMappings);\n}\nScenario withStubMapping(StubMapping stubMapping) {\nSet<StubMapping> newMappings =\nImmutableSet.<StubMapping>builder().addAll(stubMappings).add(stubMapping).build();\n- return new Scenario(id, state, null, newMappings);\n+ return new Scenario(id, state, newMappings);\n}\nScenario withoutStubMapping(StubMapping stubMapping) {\nSet<StubMapping> newMappings = Sets.difference(stubMappings, ImmutableSet.of(stubMapping));\n- return new Scenario(id, state, null, newMappings);\n+ return new Scenario(id, state, newMappings);\n}\n@Override\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"diff": "@@ -20,8 +20,8 @@ import static com.github.tomakehurst.wiremock.core.WireMockApp.FILES_ROOT;\nimport static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED;\nimport static com.github.tomakehurst.wiremock.testsupport.WireMatchers.equalsMultiLine;\nimport static com.github.tomakehurst.wiremock.testsupport.WireMatchers.matches;\n-import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals;\n-import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartMatches;\n+import static java.util.Arrays.asList;\n+import static net.javacrumbs.jsonunit.JsonMatchers.*;\nimport static org.apache.hc.core5.http.ContentType.TEXT_PLAIN;\nimport static org.hamcrest.MatcherAssert.assertThat;\nimport static org.hamcrest.Matchers.*;\n@@ -464,6 +464,33 @@ public class AdminApiTest extends AcceptanceTestBase {\nassertThat(testClient.get(\"/stateful\").content(), is(\"Initial\"));\n}\n+ @Test\n+ void getScenarios() {\n+ dsl.stubFor(\n+ get(\"/one\")\n+ .inScenario(\"my-scenario\")\n+ .whenScenarioStateIs(STARTED)\n+ .willSetStateTo(\"2\")\n+ .willReturn(ok(\"started\")));\n+\n+ dsl.stubFor(\n+ get(\"/one\")\n+ .inScenario(\"my-scenario\")\n+ .whenScenarioStateIs(\"2\")\n+ .willSetStateTo(\"3\")\n+ .willReturn(ok(\"2\")));\n+ stubFor(get(\"/one\").inScenario(\"my-scenario\").whenScenarioStateIs(\"3\").willReturn(ok(\"3\")));\n+\n+ testClient.get(\"/one\");\n+\n+ String body = testClient.get(\"/__admin/scenarios\").content();\n+ assertThat(body, jsonPartEquals(\"scenarios[0].id\", \"my-scenario\"));\n+ assertThat(body, jsonPartEquals(\"scenarios[0].name\", \"my-scenario\"));\n+ assertThat(body, jsonPartEquals(\"scenarios[0].state\", \"\\\"2\\\"\"));\n+ assertThat(body, jsonPartEquals(\"scenarios[0].possibleStates\", asList(\"2\", \"3\", \"Started\")));\n+ assertThat(body, jsonPartEquals(\"scenarios[0].mappings[0].request.url\", \"/one\"));\n+ }\n+\n@Test\npublic void defaultsUnspecifiedStubMappingAttributes() {\nWireMockResponse response = testClient.postJson(\"/__admin/mappings\", \"{}\");\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed #1854 - unintended removal of name field on scenarios |
686,936 | 09.04.2022 12:01:35 | -3,600 | 90edfc771d092c69068272352713ee2c389fe380 | Improved validation of scenario set and reset so that a 404 is returned when the scenario doesn't exist instead of a 500 | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/admin/SetScenarioStateTask.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/admin/SetScenarioStateTask.java",
"diff": "@@ -17,6 +17,8 @@ package com.github.tomakehurst.wiremock.admin;\nimport com.github.tomakehurst.wiremock.admin.model.PathParams;\nimport com.github.tomakehurst.wiremock.admin.model.ScenarioState;\n+import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;\n+import com.github.tomakehurst.wiremock.common.Errors;\nimport com.github.tomakehurst.wiremock.common.Json;\nimport com.github.tomakehurst.wiremock.core.Admin;\nimport com.github.tomakehurst.wiremock.http.Request;\n@@ -27,13 +29,23 @@ public class SetScenarioStateTask implements AdminTask {\n@Override\npublic ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {\nString name = pathParams.get(\"name\");\n- if (request.getBody() != null && !request.getBodyAsString().isEmpty()) {\n- ScenarioState scenarioState = Json.read(request.getBodyAsString(), ScenarioState.class);\n+ String body = request.getBodyAsString();\n+\n+ try {\n+ setOrResetScenarioState(admin, name, body);\n+ } catch (NotFoundException e) {\n+ return ResponseDefinitionBuilder.jsonResponse(Errors.single(404, e.getMessage()), 404);\n+ }\n+\n+ return ResponseDefinition.okEmptyJson();\n+ }\n+\n+ private void setOrResetScenarioState(Admin admin, String name, String body) {\n+ if (body != null && !body.isEmpty()) {\n+ ScenarioState scenarioState = Json.read(body, ScenarioState.class);\nadmin.setScenarioState(name, scenarioState.getState());\n} else {\nadmin.resetScenario(name);\n}\n-\n- return ResponseDefinition.okEmptyJson();\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenarios.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenarios.java",
"diff": "@@ -17,6 +17,7 @@ package com.github.tomakehurst.wiremock.stubbing;\nimport static com.google.common.base.MoreObjects.firstNonNull;\n+import com.github.tomakehurst.wiremock.admin.NotFoundException;\nimport com.google.common.base.Function;\nimport com.google.common.collect.ImmutableList;\nimport com.google.common.collect.Maps;\n@@ -106,13 +107,21 @@ public class Scenarios {\n}\npublic void resetSingle(String name) {\n- Scenario scenario = scenarioMap.get(name);\n- scenarioMap.replace(name, scenario.reset());\n+ setSingleScenarioState(name, Scenario::reset);\n}\npublic void setSingle(String name, String state) {\n+ setSingleScenarioState(name, scenario -> scenario.setState(state));\n+ }\n+\n+ private void setSingleScenarioState(\n+ String name, java.util.function.Function<Scenario, Scenario> fn) {\nScenario scenario = scenarioMap.get(name);\n- scenarioMap.replace(name, scenario.setState(state));\n+ if (scenario == null) {\n+ throw new NotFoundException(\"Scenario \" + name + \" does not exist\");\n+ }\n+\n+ scenarioMap.replace(name, fn.apply(scenario));\n}\npublic void clear() {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"diff": "@@ -491,6 +491,28 @@ public class AdminApiTest extends AcceptanceTestBase {\nassertThat(body, jsonPartEquals(\"scenarios[0].mappings[0].request.url\", \"/one\"));\n}\n+ @Test\n+ void returnsNotFoundWhenAttemptingToResetNonExistentScenario() {\n+ WireMockResponse response = testClient.put(\"/__admin/scenarios/i-dont-exist/state\");\n+ assertThat(response.statusCode(), is(404));\n+ assertThat(\n+ response.content(),\n+ jsonPartEquals(\"errors[0].title\", \"Scenario i-dont-exist does not exist\"));\n+ }\n+\n+ @Test\n+ void returnsNotFoundWhenAttemptingToSetNonExistentScenarioState() {\n+ WireMockResponse response =\n+ testClient.putWithBody(\n+ \"/__admin/scenarios/i-dont-exist/state\",\n+ \"{\\\"state\\\":\\\"newstate\\\"}\",\n+ \"application/json\");\n+ assertThat(response.statusCode(), is(404));\n+ assertThat(\n+ response.content(),\n+ jsonPartEquals(\"errors[0].title\", \"Scenario i-dont-exist does not exist\"));\n+ }\n+\n@Test\npublic void defaultsUnspecifiedStubMappingAttributes() {\nWireMockResponse response = testClient.postJson(\"/__admin/mappings\", \"{}\");\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"diff": "@@ -26,6 +26,7 @@ import static org.hamcrest.Matchers.*;\nimport static org.junit.jupiter.api.Assertions.assertThrows;\nimport com.github.tomakehurst.wiremock.client.WireMock;\n+import com.github.tomakehurst.wiremock.common.ClientError;\nimport com.github.tomakehurst.wiremock.stubbing.Scenario;\nimport com.github.tomakehurst.wiremock.stubbing.StubMapping;\nimport com.github.tomakehurst.wiremock.testsupport.WireMockResponse;\n@@ -289,4 +290,9 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\nsetScenarioState(\"set-me\", \"2\");\nassertThat(testClient.get(\"/one\").content(), is(\"2\"));\n}\n+\n+ @Test\n+ void throwsClientErrorWhenAttemptingToResetNonExistentScenario() {\n+ assertThrows(ClientError.class, () -> resetScenario(\"non-exist\"));\n+ }\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Improved validation of scenario set and reset so that a 404 is returned when the scenario doesn't exist instead of a 500 |
686,936 | 09.04.2022 12:10:30 | -3,600 | 2e9a438ed8173c06c292d14c9632162b977d759e | Improved validation of scenario set and reset so that a 422 is returned instead of quietly accepting when an attempt it made to set a scenario to a non-existent state | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenario.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenario.java",
"diff": "@@ -19,6 +19,8 @@ import static com.google.common.collect.FluentIterable.from;\nimport com.fasterxml.jackson.annotation.JsonCreator;\nimport com.fasterxml.jackson.annotation.JsonProperty;\n+import com.github.tomakehurst.wiremock.common.Errors;\n+import com.github.tomakehurst.wiremock.common.InvalidInputException;\nimport com.github.tomakehurst.wiremock.common.Json;\nimport com.google.common.base.Function;\nimport com.google.common.base.Predicate;\n@@ -98,6 +100,11 @@ public class Scenario {\n}\nScenario setState(String newState) {\n+ if (!getPossibleStates().contains(newState)) {\n+ throw new InvalidInputException(\n+ Errors.single(11, \"Scenario my-scenario does not support state \" + newState));\n+ }\n+\nreturn new Scenario(id, newState, stubMappings);\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/AdminApiTest.java",
"diff": "@@ -513,6 +513,35 @@ public class AdminApiTest extends AcceptanceTestBase {\njsonPartEquals(\"errors[0].title\", \"Scenario i-dont-exist does not exist\"));\n}\n+ @Test\n+ void returnsBadEntityWhenAttemptingToSetNonExistentScenarioState() {\n+ dsl.stubFor(\n+ get(\"/one\")\n+ .inScenario(\"my-scenario\")\n+ .whenScenarioStateIs(STARTED)\n+ .willSetStateTo(\"2\")\n+ .willReturn(ok(\"started\")));\n+\n+ dsl.stubFor(\n+ get(\"/one\")\n+ .inScenario(\"my-scenario\")\n+ .whenScenarioStateIs(\"2\")\n+ .willSetStateTo(STARTED)\n+ .willReturn(ok(\"2\")));\n+\n+ WireMockResponse response =\n+ testClient.putWithBody(\n+ \"/__admin/scenarios/my-scenario/state\",\n+ \"{\\\"state\\\":\\\"non-existent-state\\\"}\",\n+ \"application/json\");\n+\n+ assertThat(response.statusCode(), is(422));\n+ assertThat(\n+ response.content(),\n+ jsonPartEquals(\n+ \"errors[0].title\", \"Scenario my-scenario does not support state non-existent-state\"));\n+ }\n+\n@Test\npublic void defaultsUnspecifiedStubMappingAttributes() {\nWireMockResponse response = testClient.postJson(\"/__admin/mappings\", \"{}\");\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"diff": "@@ -295,4 +295,23 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\nvoid throwsClientErrorWhenAttemptingToResetNonExistentScenario() {\nassertThrows(ClientError.class, () -> resetScenario(\"non-exist\"));\n}\n+\n+ @Test\n+ void throwsClientErrorWhenAttemptingToSetToNonExistentState() {\n+ stubFor(\n+ get(\"/one\")\n+ .inScenario(\"set-me\")\n+ .whenScenarioStateIs(STARTED)\n+ .willSetStateTo(\"2\")\n+ .willReturn(ok(\"started\")));\n+\n+ stubFor(\n+ get(\"/one\")\n+ .inScenario(\"set-me\")\n+ .whenScenarioStateIs(\"2\")\n+ .willSetStateTo(\"3\")\n+ .willReturn(ok(\"2\")));\n+\n+ assertThrows(ClientError.class, () -> setScenarioState(\"set-me\", \"non-exist\"));\n+ }\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Improved validation of scenario set and reset so that a 422 is returned instead of quietly accepting when an attempt it made to set a scenario to a non-existent state |
686,936 | 09.04.2022 12:12:00 | -3,600 | 5ba1fa4c733c8b492c1474619e7c6bb5f5b08753 | Minor readability improvement to scenarios acceptance test | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ScenarioAcceptanceTest.java",
"diff": "@@ -258,7 +258,7 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\nstubFor(get(\"/one\").inScenario(\"reset-me\").whenScenarioStateIs(\"2\").willReturn(ok(\"2\")));\n- testClient.get(\"/one\");\n+ assertThat(testClient.get(\"/one\").content(), is(\"started\"));\nassertThat(testClient.get(\"/one\").content(), is(\"2\"));\nresetScenario(\"reset-me\");\n@@ -283,7 +283,7 @@ public class ScenarioAcceptanceTest extends AcceptanceTestBase {\n.willReturn(ok(\"2\")));\nstubFor(get(\"/one\").inScenario(\"set-me\").whenScenarioStateIs(\"3\").willReturn(ok(\"3\")));\n- testClient.get(\"/one\");\n+ assertThat(testClient.get(\"/one\").content(), is(\"started\"));\nassertThat(testClient.get(\"/one\").content(), is(\"2\"));\nassertThat(testClient.get(\"/one\").content(), is(\"3\"));\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Minor readability improvement to scenarios acceptance test |
687,047 | 26.04.2022 12:43:54 | -7,200 | 34912990880afd192874a1ab2a19b84b7c5eded2 | Don't create request entity when it was not present in original request | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"diff": "@@ -101,7 +101,10 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nHttpUriRequest httpRequest = getHttpRequestFor(responseDefinition);\naddRequestHeaders(httpRequest, responseDefinition);\n- httpRequest.setEntity(buildEntityFrom(responseDefinition.getOriginalRequest()));\n+ Request originalRequest = responseDefinition.getOriginalRequest();\n+ if (originalRequest.getBody() != null && originalRequest.getBody().length > 0) {\n+ httpRequest.setEntity(buildEntityFrom(originalRequest));\n+ }\nCloseableHttpClient client = buildClient(serveEvent.getRequest().isBrowserProxyRequest());\ntry (CloseableHttpResponse httpResponse = client.execute(httpRequest)) {\nreturn response()\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyResponseRendererTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyResponseRendererTest.java",
"diff": "@@ -24,6 +24,8 @@ import static org.hamcrest.Matchers.is;\nimport static org.hamcrest.core.StringContains.containsString;\nimport static org.hamcrest.core.StringStartsWith.startsWith;\nimport static org.junit.jupiter.api.Assertions.assertEquals;\n+import static org.mockito.ArgumentMatchers.argThat;\n+import static org.mockito.Mockito.spy;\nimport com.github.tomakehurst.wiremock.common.ProxySettings;\nimport com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings;\n@@ -37,16 +39,21 @@ import com.github.tomakehurst.wiremock.stubbing.ServeEvent;\nimport com.github.tomakehurst.wiremock.stubbing.StubMapping;\nimport com.github.tomakehurst.wiremock.verification.LoggedRequest;\nimport java.io.File;\n+import java.io.IOException;\n+import java.lang.reflect.Field;\n+import java.nio.charset.StandardCharsets;\nimport java.security.KeyPair;\nimport java.security.KeyPairGenerator;\nimport java.security.NoSuchAlgorithmException;\nimport java.util.Collections;\nimport java.util.Date;\nimport java.util.HashMap;\n+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;\nimport org.junit.jupiter.api.Test;\nimport org.junit.jupiter.api.condition.DisabledForJreRange;\nimport org.junit.jupiter.api.condition.JRE;\nimport org.junit.jupiter.api.extension.RegisterExtension;\n+import org.mockito.Mockito;\n@DisabledForJreRange(\nmin = JRE.JAVA_17,\n@@ -146,15 +153,73 @@ public class ProxyResponseRendererTest {\nis(false));\n}\n+ @Test\n+ void doesNotAddEntityIfEmptyBodyReverseProxy() throws IOException {\n+ CloseableHttpClient clientSpy =\n+ reflectiveSpyField(CloseableHttpClient.class, \"reverseProxyClient\", proxyResponseRenderer);\n+\n+ ServeEvent serveEvent = reverseProxyServeEvent(\"/proxied\");\n+\n+ proxyResponseRenderer.render(serveEvent);\n+ Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() == null));\n+ }\n+\n+ @Test\n+ void doesNotAddEntityIfEmptyBodyForwardProxy() throws IOException {\n+ CloseableHttpClient clientSpy =\n+ reflectiveSpyField(CloseableHttpClient.class, \"forwardProxyClient\", proxyResponseRenderer);\n+\n+ ServeEvent serveEvent = forwardProxyServeEvent(\"/proxied\");\n+\n+ proxyResponseRenderer.render(serveEvent);\n+ Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() == null));\n+ }\n+\n+ @Test\n+ void addsEntityIfNotEmptyBodyReverseProxy() throws IOException {\n+ CloseableHttpClient clientSpy =\n+ reflectiveSpyField(CloseableHttpClient.class, \"reverseProxyClient\", proxyResponseRenderer);\n+\n+ ServeEvent serveEvent =\n+ serveEvent(\"/proxied\", false, \"Text body\".getBytes(StandardCharsets.UTF_8));\n+\n+ proxyResponseRenderer.render(serveEvent);\n+ Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null));\n+ }\n+\n+ @Test\n+ void addsEntityIfNotEmptyBodyForwardProxy() throws IOException {\n+ CloseableHttpClient clientSpy =\n+ reflectiveSpyField(CloseableHttpClient.class, \"forwardProxyClient\", proxyResponseRenderer);\n+\n+ ServeEvent serveEvent =\n+ serveEvent(\"/proxied\", true, \"Text body\".getBytes(StandardCharsets.UTF_8));\n+\n+ proxyResponseRenderer.render(serveEvent);\n+ Mockito.verify(clientSpy).execute(argThat(request -> request.getEntity() != null));\n+ }\n+\n+ private static <T> T reflectiveSpyField(Class<T> fieldType, String fieldName, Object object) {\n+ try {\n+ Field field = object.getClass().getDeclaredField(fieldName);\n+ field.setAccessible(true);\n+ T spy = spy(fieldType.cast(field.get(object)));\n+ field.set(object, spy);\n+ return spy;\n+ } catch (NoSuchFieldException | IllegalAccessException e) {\n+ throw new RuntimeException(e);\n+ }\n+ }\n+\nprivate ServeEvent reverseProxyServeEvent(String path) {\n- return serveEvent(path, false);\n+ return serveEvent(path, false, new byte[0]);\n}\nprivate ServeEvent forwardProxyServeEvent(String path) {\n- return serveEvent(path, true);\n+ return serveEvent(path, true, new byte[0]);\n}\n- private ServeEvent serveEvent(String path, boolean isBrowserProxyRequest) {\n+ private ServeEvent serveEvent(String path, boolean isBrowserProxyRequest, byte[] body) {\nLoggedRequest loggedRequest =\nnew LoggedRequest(\n/* url = */ path,\n@@ -165,7 +230,7 @@ public class ProxyResponseRendererTest {\n/* cookies = */ new HashMap<String, Cookie>(),\n/* isBrowserProxyRequest = */ isBrowserProxyRequest,\n/* loggedDate = */ new Date(),\n- /* body = */ new byte[0],\n+ /* body = */ body,\n/* multiparts = */ null);\nResponseDefinition responseDefinition = aResponse().proxiedFrom(origin.baseUrl()).build();\nresponseDefinition.setOriginalRequest(loggedRequest);\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Don't create request entity when it was not present in original request (#1865)
Co-authored-by: Alexey Hizhnyak <alexeyh@playtika.com> |
686,936 | 26.04.2022 12:14:33 | -3,600 | c4338759fa23ea3beaf66c1c2ff4ed4a581dce5e | Fixes - added missing files to bump version build tasks and fixed incorrect version numbers. | [
{
"change_type": "MODIFY",
"old_path": "README.md",
"new_path": "README.md",
"diff": "@@ -7,7 +7,7 @@ WireMock - a web service test double for all occasions\n!!! Log4j notice !!!\n--------------------\nWireMock only uses log4j in its test dependencies. Neither the thin nor standalone JAR depends on or embeds log4j, so\n-you can continue to use WireMock 2.32.0 without any risk of exposure to the recently discovered vulnerability.\n+you can continue to use WireMock 2.32.0 and above without any risk of exposure to the recently discovered vulnerability.\nKey Features\n------------\n"
},
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -393,8 +393,10 @@ task 'bump-patch-version' {\ndoLast {\ndef filesWithVersion = [\n'build.gradle' : { \"version = '${it}\" },\n- 'src/main/resources/swagger/wiremock-admin-api.yaml': {\n- \"version: ${it}\" }\n+ 'ui/package.json' : { \"version: ${it}\" },\n+ 'ui/package-lock.json' : { \"version: ${it}\" },\n+ 'src/main/resources/swagger/wiremock-admin-api.json': { \"version: ${it}\" },\n+ 'src/main/resources/swagger/wiremock-admin-api.yaml': { \"version: ${it}\" }\n]\ndef currentVersion = project.version\n@@ -418,8 +420,10 @@ task 'bump-minor-version' {\ndoLast {\ndef filesWithVersion = [\n'build.gradle' : { \"version = '${it}\" },\n- 'src/main/resources/swagger/wiremock-admin-api.yaml': {\n- \"version: ${it}\" }\n+ 'ui/package.json' : { \"version: ${it}\" },\n+ 'ui/package-lock.json' : { \"version: ${it}\" },\n+ 'src/main/resources/swagger/wiremock-admin-api.json': { \"version: ${it}\" },\n+ 'src/main/resources/swagger/wiremock-admin-api.yaml': { \"version: ${it}\" }\n]\ndef currentVersion = project.version\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/resources/swagger/wiremock-admin-api.json",
"new_path": "src/main/resources/swagger/wiremock-admin-api.json",
"diff": "\"openapi\": \"3.0.0\",\n\"info\": {\n\"title\": \"WireMock\",\n- \"version\": \"2.32.0\"\n+ \"version\": \"2.33.1\"\n},\n\"externalDocs\": {\n\"description\": \"WireMock user documentation\",\n"
},
{
"change_type": "MODIFY",
"old_path": "ui/package-lock.json",
"new_path": "ui/package-lock.json",
"diff": "{\n\"name\": \"wiremock-ui-resources\",\n- \"version\": \"2.32.0\",\n+ \"version\": \"2.33.1\",\n\"lockfileVersion\": 1,\n\"requires\": true,\n\"dependencies\": {\n"
},
{
"change_type": "MODIFY",
"old_path": "ui/package.json",
"new_path": "ui/package.json",
"diff": "{\n\"name\": \"wiremock-ui-resources\",\n- \"version\": \"2.32.0\",\n+ \"version\": \"2.33.1\",\n\"description\": \"WireMock UI resources processor\",\n\"engines\": {\n\"node\": \">= 0.10.0\"\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixes #1860 - added missing files to bump version build tasks and fixed incorrect version numbers. |
686,936 | 26.04.2022 12:22:16 | -3,600 | 25a779cc8926b9c3628e8325b0967a39fc52a8e6 | Appeasing the gods of Spotless | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -396,7 +396,8 @@ task 'bump-patch-version' {\n'ui/package.json' : { \"version: ${it}\" },\n'ui/package-lock.json' : { \"version: ${it}\" },\n'src/main/resources/swagger/wiremock-admin-api.json': { \"version: ${it}\" },\n- 'src/main/resources/swagger/wiremock-admin-api.yaml': { \"version: ${it}\" }\n+ 'src/main/resources/swagger/wiremock-admin-api.yaml': {\n+ \"version: ${it}\" }\n]\ndef currentVersion = project.version\n@@ -423,7 +424,8 @@ task 'bump-minor-version' {\n'ui/package.json' : { \"version: ${it}\" },\n'ui/package-lock.json' : { \"version: ${it}\" },\n'src/main/resources/swagger/wiremock-admin-api.json': { \"version: ${it}\" },\n- 'src/main/resources/swagger/wiremock-admin-api.yaml': { \"version: ${it}\" }\n+ 'src/main/resources/swagger/wiremock-admin-api.yaml': {\n+ \"version: ${it}\" }\n]\ndef currentVersion = project.version\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Appeasing the gods of Spotless |
686,936 | 29.04.2022 14:41:04 | -3,600 | 7301cf86647a72a4c8c479b5254a4633cdc196b8 | Added guard in build.gradle to ensure release can only happen with Java 8 | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -368,6 +368,7 @@ task checkReleasePreconditions {\ndef REQUIRED_GIT_BRANCH = 'master'\ndef currentGitBranch = 'git rev-parse --abbrev-ref HEAD'.execute().text.trim()\nassert currentGitBranch == REQUIRED_GIT_BRANCH, \"Must be on the $REQUIRED_GIT_BRANCH branch in order to release to Sonatype\"\n+ assert JavaVersion.current().isJava8(), 'Must use Java 8 when releasing'\n}\n}\npublish.dependsOn checkReleasePreconditions\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added guard in build.gradle to ensure release can only happen with Java 8 |
686,936 | 14.06.2022 13:47:18 | -3,600 | 9b9dbecbb09e252ffee1cf9ef1680bec769945e2 | Updated WireMock version in ui package.json | [
{
"change_type": "MODIFY",
"old_path": "ui/package-lock.json",
"new_path": "ui/package-lock.json",
"diff": "{\n\"name\": \"wiremock-ui-resources\",\n- \"version\": \"2.33.1\",\n+ \"version\": \"2.33.2\",\n\"lockfileVersion\": 1,\n\"requires\": true,\n\"dependencies\": {\n"
},
{
"change_type": "MODIFY",
"old_path": "ui/package.json",
"new_path": "ui/package.json",
"diff": "{\n\"name\": \"wiremock-ui-resources\",\n- \"version\": \"2.33.1\",\n+ \"version\": \"2.33.2\",\n\"description\": \"WireMock UI resources processor\",\n\"engines\": {\n\"node\": \">= 0.10.0\"\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Updated WireMock version in ui package.json |
687,053 | 05.07.2022 18:00:35 | -7,200 | dcd881cbb0a78ac0c5421b6a19932f85d9605060 | Added equals and hashCode methods to MultipartValuePattern
Added equals and hashCode methods to MultipartValuePattern | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/matching/MultipartValuePattern.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/matching/MultipartValuePattern.java",
"diff": "/*\n- * Copyright (C) 2017-2021 Thomas Akehurst\n+ * Copyright (C) 2017-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -27,6 +27,7 @@ import com.google.common.base.Predicate;\nimport java.util.Collection;\nimport java.util.List;\nimport java.util.Map;\n+import java.util.Objects;\npublic class MultipartValuePattern implements ValueMatcher<Request.Part> {\n@@ -165,4 +166,22 @@ public class MultipartValuePattern implements ValueMatcher<Request.Part> {\nreturn ((StringValuePattern) bodyPattern).match(body.asString());\n}\n+\n+ @Override\n+ public boolean equals(Object o) {\n+ if (this == o) return true;\n+ if (o == null || getClass() != o.getClass()) return false;\n+\n+ MultipartValuePattern that = (MultipartValuePattern) o;\n+\n+ return Objects.equals(name, that.name)\n+ && Objects.equals(headers, that.headers)\n+ && Objects.equals(bodyPatterns, that.bodyPatterns)\n+ && matchingType == that.matchingType;\n+ }\n+\n+ @Override\n+ public int hashCode() {\n+ return Objects.hash(name, headers, bodyPatterns, matchingType);\n+ }\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/matching/MultipartValuePatternTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/matching/MultipartValuePatternTest.java",
"diff": "/*\n- * Copyright (C) 2017-2021 Thomas Akehurst\n+ * Copyright (C) 2017-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -197,4 +197,58 @@ public class MultipartValuePatternTest {\n+ \" } ]\\n\"\n+ \"}\"));\n}\n+\n+ @Test\n+ public void equalsShouldReturnTrueOnSameObject() {\n+ MultipartValuePattern pattern =\n+ aMultipart()\n+ .withName(\"title\")\n+ .withHeader(\"X-First-Header\", equalTo(\"One\"))\n+ .withHeader(\"X-Second-Header\", matching(\".*2\"))\n+ .withBody(equalToJson(\"{ \\\"thing\\\": 123 }\"))\n+ .build();\n+\n+ assertThat(pattern.equals(pattern), is(true));\n+ }\n+\n+ @Test\n+ public void equalsShouldReturnTrueOnIdenticalButNotSameObjects() {\n+ MultipartValuePattern patternA =\n+ aMultipart()\n+ .withName(\"title\")\n+ .withHeader(\"X-First-Header\", equalTo(\"One\"))\n+ .withHeader(\"X-Second-Header\", matching(\".*2\"))\n+ .withBody(equalToJson(\"{ \\\"thing\\\": 123 }\"))\n+ .build();\n+\n+ MultipartValuePattern patternB =\n+ aMultipart()\n+ .withName(\"title\")\n+ .withHeader(\"X-First-Header\", equalTo(\"One\"))\n+ .withHeader(\"X-Second-Header\", matching(\".*2\"))\n+ .withBody(equalToJson(\"{ \\\"thing\\\": 123 }\"))\n+ .build();\n+\n+ assertThat(patternA.equals(patternB), is(true));\n+ }\n+\n+ @Test\n+ public void equalsShouldReturnFalseOnDifferentObjects() {\n+ MultipartValuePattern patternA =\n+ aMultipart()\n+ .withName(\"title\")\n+ .withHeader(\"X-First-Header\", equalTo(\"One\"))\n+ .withHeader(\"X-Second-Header\", matching(\".*2\"))\n+ .withBody(equalToJson(\"{ \\\"thing\\\": 123 }\"))\n+ .build();\n+\n+ MultipartValuePattern patternB =\n+ aMultipart()\n+ .withName(\"anotherTitle\")\n+ .withHeader(\"X-Second-Header\", matching(\".*2\"))\n+ .withBody(equalToJson(\"{ \\\"thing\\\": \\\"abc\\\" }\"))\n+ .build();\n+\n+ assertThat(patternA.equals(patternB), is(false));\n+ }\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added equals and hashCode methods to MultipartValuePattern (#1911)
Added equals and hashCode methods to MultipartValuePattern |
686,981 | 02.08.2022 11:42:08 | -3,600 | ac19e49941e58afa5353953cf93196f326923568 | Make the testlogging maven project build
version99.qos.ch has been deprecated and the TLS cert has died.
Brought everything up to date. | [
{
"change_type": "MODIFY",
"old_path": "testlogging/pom.xml",
"new_path": "testlogging/pom.xml",
"diff": "<properties>\n<slf4jversion>1.7.1</slf4jversion>\n+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>\n+ <project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>\n</properties>\n- <repositories>\n- <repository>\n- <id>version99</id>\n- <url>https://version99.qos.ch/</url>\n- </repository>\n- </repositories>\n-\n<build>\n<plugins>\n<plugin>\n<artifactId>maven-compiler-plugin</artifactId>\n+ <version>3.8.1</version>\n<configuration>\n- <source>1.6</source>\n- <target>1.6</target>\n+ <source>1.8</source>\n+ <target>1.8</target>\n</configuration>\n</plugin>\n</plugins>\n</dependency>\n<dependency>\n<groupId>com.github.tomakehurst</groupId>\n- <artifactId>wiremock</artifactId>\n- <version>1.30</version>\n+ <artifactId>wiremock-jre8</artifactId>\n+ <version>2.33.2</version>\n<scope>test</scope>\n</dependency>\n<dependency>\n<version>${slf4jversion}</version>\n<scope>test</scope>\n</dependency>\n- <dependency>\n- <groupId>commons-logging</groupId>\n- <artifactId>commons-logging</artifactId>\n- <version>99-empty</version>\n- <scope>test</scope>\n- </dependency>\n- <dependency>\n- <groupId>log4j</groupId>\n- <artifactId>log4j</artifactId>\n- <version>99-empty</version>\n- <scope>test</scope>\n- </dependency>\n<dependency>\n<groupId>commons-io</groupId>\n<artifactId>commons-io</artifactId>\n"
},
{
"change_type": "MODIFY",
"old_path": "testlogging/src/test/java/WiremockTest.java",
"new_path": "testlogging/src/test/java/WiremockTest.java",
"diff": "@@ -12,9 +12,10 @@ import java.io.PrintStream;\nimport java.net.URL;\nimport static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static java.nio.charset.StandardCharsets.UTF_8;\nimport static org.hamcrest.CoreMatchers.containsString;\n+import static org.hamcrest.MatcherAssert.assertThat;\nimport static org.junit.Assert.assertEquals;\n-import static org.junit.Assert.assertThat;\npublic class WiremockTest {\n@@ -43,9 +44,9 @@ public class WiremockTest {\nURL uri = new URL(\"http://localhost:8080/blah\");\nInputStream content = uri.openConnection().getInputStream();\n- final String retrievedBody = IOUtils.toString(content);\n+ final String retrievedBody = IOUtils.toString(content, UTF_8);\nassertEquals(\"body\", retrievedBody);\n- assertThat(stdOutCapture.toString(), containsString(\"c.g.t.wiremock.common.Log4jNotifier - Received request to /mappings/new\"));\n+ assertThat(stdOutCapture.toString(), containsString(\"INFO o.e.j.s.h.ContextHandler.__admin - RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler\"));\n}\nprivate static class StringPrintStream extends PrintStream {\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Make the testlogging maven project build
version99.qos.ch has been deprecated and the TLS cert has died.
Brought everything up to date. |
686,981 | 02.08.2022 12:04:46 | -3,600 | d5f9159ea4c661d9e54917a9eb05bf373f3a0ae9 | Run the logging test against standalone
The whole point is to make sure the standalone jar does not shade the
logging classes. | [
{
"change_type": "MODIFY",
"old_path": "testlogging/pom.xml",
"new_path": "testlogging/pom.xml",
"diff": "</dependency>\n<dependency>\n<groupId>com.github.tomakehurst</groupId>\n- <artifactId>wiremock-jre8</artifactId>\n+ <artifactId>wiremock-jre8-standalone</artifactId>\n<version>2.33.2</version>\n<scope>test</scope>\n</dependency>\n"
},
{
"change_type": "MODIFY",
"old_path": "testlogging/src/test/java/WiremockTest.java",
"new_path": "testlogging/src/test/java/WiremockTest.java",
"diff": "@@ -46,7 +46,7 @@ public class WiremockTest {\nfinal String retrievedBody = IOUtils.toString(content, UTF_8);\nassertEquals(\"body\", retrievedBody);\n- assertThat(stdOutCapture.toString(), containsString(\"INFO o.e.j.s.h.ContextHandler.__admin - RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler\"));\n+ assertThat(stdOutCapture.toString(), containsString(\"LOGBACK INFO w.o.e.j.s.h.ContextHandler.__admin - RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler\"));\n}\nprivate static class StringPrintStream extends PrintStream {\n"
},
{
"change_type": "MODIFY",
"old_path": "testlogging/src/test/resources/logback-test.xml",
"new_path": "testlogging/src/test/resources/logback-test.xml",
"diff": "<appender name=\"STDOUT\" class=\"ch.qos.logback.core.ConsoleAppender\">\n<encoder>\n- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>\n+ <pattern>%d{HH:mm:ss.SSS} [%thread] LOGBACK %-5level %logger{36} - %msg%n</pattern>\n</encoder>\n</appender>\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Run the logging test against standalone
The whole point is to make sure the standalone jar does not shade the
logging classes. |
686,936 | 09.09.2022 09:05:59 | -3,600 | bbbc03f5a0ebcf2377cc5e33e2c067214dc1b06b | Fixed forward proxying issues triggered by Jetty 9.4.48 upgrade | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -26,7 +26,7 @@ group = 'com.github.tomakehurst'\nproject.ext {\nversions = [\nhandlebars : '4.3.0',\n- jetty : '9.4.46.v20220331',\n+ jetty : '9.4.48.v20220622',\nguava : '31.1-jre',\njackson : '2.13.2.20220328',\nxmlUnit : '2.9.0',\n@@ -110,8 +110,8 @@ dependencies {\ntestImplementation \"org.eclipse.jetty:jetty-client\"\ntestImplementation \"org.eclipse.jetty.http2:http2-http-client-transport\"\n- testRuntimeOnly platform(\"org.apache.logging.log4j:log4j-bom:2.17.2\")\n- testRuntimeOnly \"org.apache.logging.log4j:log4j-slf4j-impl\"\n+ testImplementation \"ch.qos.logback:logback-classic:1.3.0\"\n+\ntestRuntimeOnly files('src/test/resources/classpath file source/classpathfiles.zip', 'src/test/resources/classpath-filesource.jar')\ntestImplementation ('net.jockx:littleproxy:1.1.3') {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/Urls.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/Urls.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -99,9 +99,14 @@ public class Urls {\npublic static URL safelyCreateURL(String url) {\ntry {\n- return new URL(url);\n+ return new URL(clean(url));\n} catch (MalformedURLException e) {\nreturn throwUnchecked(e, URL.class);\n}\n}\n+\n+ // Workaround for a Jetty bug that appends \"null\" onto the end of the URL\n+ private static String clean(String url) {\n+ return url.matches(\".*:[0-9]+null$\") ? url.substring(0, url.length() - 4) : url;\n+ }\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/jetty94/Jetty94HttpServer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/jetty94/Jetty94HttpServer.java",
"diff": "/*\n- * Copyright (C) 2019-2021 Thomas Akehurst\n+ * Copyright (C) 2019-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -114,7 +114,7 @@ public class Jetty94HttpServer extends JettyHttpServer {\nsuper.createHandler(options, adminRequestHandler, stubRequestHandler);\nif (options.browserProxySettings().enabled()) {\n- handler.addHandler(new ManInTheMiddleSslConnectHandler(mitmProxyConnector));\n+ handler.prependHandler(new ManInTheMiddleSslConnectHandler(mitmProxyConnector));\n}\nreturn handler;\n"
},
{
"change_type": "DELETE",
"old_path": "src/test/resources/log4j.properties",
"new_path": null,
"diff": "-log4j.rootLogger=WARN, stdout\n-\n-log4j.appender.stdout=org.apache.log4j.ConsoleAppender\n-log4j.appender.stdout.target=System.out\n-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout\n-log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n\n-\n-log4j.logger.org.apache.hc.client5.http.wire=DEBUG\n-log4j.logger.org.eclipse.jetty.util.thread=WARN\n-log4j.logger.org.eclipse.jetty.util.component=WARN\n\\ No newline at end of file\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed forward proxying issues triggered by Jetty 9.4.48 upgrade |
686,936 | 10.09.2022 15:30:53 | -3,600 | 5525c389addbe4ebfcc11113e61deb17dd33a0ee | Added a test case for the path traversal bug fix in | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/common/SingleRootFileSourceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/common/SingleRootFileSourceTest.java",
"diff": "@@ -90,6 +90,17 @@ public class SingleRootFileSourceTest {\n});\n}\n+ @Test\n+ public void listFilesRecursivelyThrowsExceptionWhenLastPathNodeIsSimilarToRootButWithExtraCharacters() {\n+ assertThrows(\n+ NotAuthorisedException.class,\n+ () -> {\n+ SingleRootFileSource fileSource =\n+ new SingleRootFileSource(\"src/test/resources/filesource/root\");\n+ fileSource.getBinaryFileNamed(\"../rootdir/file.json\");\n+ });\n+ }\n+\n@Test\npublic void writeTextFileThrowsExceptionWhenGivenRelativePathNotUnderRoot() {\nassertThrows(\n"
},
{
"change_type": "ADD",
"old_path": "src/test/resources/filesource/root/.gitkeep",
"new_path": "src/test/resources/filesource/root/.gitkeep",
"diff": ""
},
{
"change_type": "ADD",
"old_path": "src/test/resources/filesource/rootdir/.gitkeep",
"new_path": "src/test/resources/filesource/rootdir/.gitkeep",
"diff": ""
},
{
"change_type": "ADD",
"old_path": "src/test/resources/filesource/rootdir/file.json",
"new_path": "src/test/resources/filesource/rootdir/file.json",
"diff": ""
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added a test case for the path traversal bug fix in e41635bb36f6d90fccbfff451eeb4e5c6aedde64 |
686,947 | 11.09.2022 00:34:57 | -36,000 | 9aad8789d2c470eb9e92df83494a2dcffe90ad06 | Fix proxyUrlPrefixToRemove property not properly being set for ResponseDefinition, also conditionally return builder of ProxyResponseDefinitionBuilder if proxyBaseUrl is set | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/client/ResponseDefinitionBuilder.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/client/ResponseDefinitionBuilder.java",
"diff": "@@ -40,6 +40,7 @@ public class ResponseDefinitionBuilder {\nprotected DelayDistribution delayDistribution;\nprotected ChunkedDribbleDelay chunkedDribbleDelay;\nprotected String proxyBaseUrl;\n+ protected String proxyUrlPrefixToRemove;\nprotected Fault fault;\nprotected List<String> responseTransformerNames;\nprotected Map<String, Object> transformerParameters = newHashMap();\n@@ -59,6 +60,7 @@ public class ResponseDefinitionBuilder {\nbuilder.delayDistribution = responseDefinition.getDelayDistribution();\nbuilder.chunkedDribbleDelay = responseDefinition.getChunkedDribbleDelay();\nbuilder.proxyBaseUrl = responseDefinition.getProxyBaseUrl();\n+ builder.proxyUrlPrefixToRemove = responseDefinition.getProxyUrlPrefixToRemove();\nbuilder.fault = responseDefinition.getFault();\nbuilder.responseTransformerNames = responseDefinition.getTransformers();\nbuilder.transformerParameters =\n@@ -66,6 +68,18 @@ public class ResponseDefinitionBuilder {\n? Parameters.from(responseDefinition.getTransformerParameters())\n: Parameters.empty();\nbuilder.wasConfigured = responseDefinition.isFromConfiguredStub();\n+\n+ if (builder.proxyBaseUrl != null) {\n+ ProxyResponseDefinitionBuilder proxyResponseDefinitionBuilder = new ProxyResponseDefinitionBuilder(builder);\n+ proxyResponseDefinitionBuilder.proxyUrlPrefixToRemove = responseDefinition.getProxyUrlPrefixToRemove();\n+ proxyResponseDefinitionBuilder.additionalRequestHeaders =\n+ responseDefinition.getAdditionalProxyRequestHeaders() != null\n+ ? (List<HttpHeader>) responseDefinition.getAdditionalProxyRequestHeaders().all()\n+ : Lists.<HttpHeader>newArrayList();\n+\n+ return proxyResponseDefinitionBuilder;\n+ }\n+\nreturn builder;\n}\n@@ -208,7 +222,6 @@ public class ResponseDefinitionBuilder {\npublic static class ProxyResponseDefinitionBuilder extends ResponseDefinitionBuilder {\nprivate List<HttpHeader> additionalRequestHeaders = newArrayList();\n- private String proxyUrlPrefixToRemove;\npublic ProxyResponseDefinitionBuilder(ResponseDefinitionBuilder from) {\nthis.status = from.status;\n@@ -221,6 +234,7 @@ public class ResponseDefinitionBuilder {\nthis.delayDistribution = from.delayDistribution;\nthis.chunkedDribbleDelay = from.chunkedDribbleDelay;\nthis.proxyBaseUrl = from.proxyBaseUrl;\n+ this.proxyUrlPrefixToRemove = from.proxyUrlPrefixToRemove;\nthis.responseTransformerNames = from.responseTransformerNames;\nthis.transformerParameters = from.transformerParameters;\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fix proxyUrlPrefixToRemove property not properly being set for ResponseDefinition, also conditionally return builder of ProxyResponseDefinitionBuilder if proxyBaseUrl is set (#1898)
Co-authored-by: RHurley <ross.hurley@greater.com.au> |
686,936 | 10.09.2022 15:35:31 | -3,600 | 2883f6e76afb6c9aa58a6acb7339ef7793018079 | Added a test case for bug fixed by | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"diff": "@@ -32,6 +32,7 @@ import com.github.tomakehurst.wiremock.client.WireMock;\nimport com.github.tomakehurst.wiremock.common.ProxySettings;\nimport com.github.tomakehurst.wiremock.core.Options;\nimport com.github.tomakehurst.wiremock.core.WireMockConfiguration;\n+import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;\nimport com.github.tomakehurst.wiremock.http.HttpClientFactory;\nimport com.github.tomakehurst.wiremock.testsupport.WireMockResponse;\nimport com.github.tomakehurst.wiremock.testsupport.WireMockTestClient;\n@@ -600,6 +601,24 @@ public class ProxyAcceptanceTest {\nassertThat(response.statusCode(), is(200));\n}\n+ @Test\n+ public void removesPrefixFromProxyRequestWhenResponseTransformersAreUsed() {\n+ init(wireMockConfig().extensions(new ResponseTemplateTransformer(true)));\n+\n+ proxy.register(\n+ get(\"/other/service/doc/123\")\n+ .willReturn(\n+ aResponse()\n+ .proxiedFrom(targetServiceBaseUrl + \"/approot\")\n+ .withProxyUrlPrefixToRemove(\"/other/service\")));\n+\n+ target.register(get(\"/approot/doc/123\").willReturn(ok()));\n+\n+ WireMockResponse response = testClient.get(\"/other/service/doc/123\");\n+\n+ assertThat(response.statusCode(), is(200));\n+ }\n+\n@ParameterizedTest\n@ValueSource(strings = {\"GET\", \"HEAD\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\", \"BLAH\"})\nvoid proxiesRequestBodyForAnyMethod(String method) {\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added a test case for bug fixed by 9aad8789d2c470eb9e92df83494a2dcffe90ad06 |
686,936 | 10.09.2022 15:49:47 | -3,600 | c03c4824fa76091ca0d8f405482306a07b30749d | Moved test files used for file source security test to avoid them breaking another test expecting an exact structure | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/common/SingleRootFileSourceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/common/SingleRootFileSourceTest.java",
"diff": "/*\n- * Copyright (C) 2011-2021 Thomas Akehurst\n+ * Copyright (C) 2011-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -91,12 +91,13 @@ public class SingleRootFileSourceTest {\n}\n@Test\n- public void listFilesRecursivelyThrowsExceptionWhenLastPathNodeIsSimilarToRootButWithExtraCharacters() {\n+ public void\n+ listFilesRecursivelyThrowsExceptionWhenLastPathNodeIsSimilarToRootButWithExtraCharacters() {\nassertThrows(\nNotAuthorisedException.class,\n() -> {\nSingleRootFileSource fileSource =\n- new SingleRootFileSource(\"src/test/resources/filesource/root\");\n+ new SingleRootFileSource(\"src/test/resources/security-filesource/root\");\nfileSource.getBinaryFileNamed(\"../rootdir/file.json\");\n});\n}\n"
},
{
"change_type": "RENAME",
"old_path": "src/test/resources/filesource/root/.gitkeep",
"new_path": "src/test/resources/security-filesource/root/.gitkeep",
"diff": ""
},
{
"change_type": "RENAME",
"old_path": "src/test/resources/filesource/rootdir/.gitkeep",
"new_path": "src/test/resources/security-filesource/rootdir/.gitkeep",
"diff": ""
},
{
"change_type": "RENAME",
"old_path": "src/test/resources/filesource/rootdir/file.json",
"new_path": "src/test/resources/security-filesource/rootdir/file.json",
"diff": ""
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Moved test files used for file source security test to avoid them breaking another test expecting an exact structure |
686,936 | 12.09.2022 08:36:15 | -3,600 | 9792aee49d1f89d32722b7fbf639aeb3a4bdcec6 | Made WireMock.getScenarios() public so that it can be used on the instance client as well as static | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java",
"diff": "@@ -388,7 +388,7 @@ public class WireMock {\nreturn defaultInstance.get().getScenarios();\n}\n- private List<Scenario> getScenarios() {\n+ public List<Scenario> getScenarios() {\nreturn admin.getAllScenarios().getScenarios();\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Made WireMock.getScenarios() public so that it can be used on the instance client as well as static |
686,936 | 15.09.2022 17:19:16 | -3,600 | d370fed7d4499674a03ae659369a17852562fd48 | Fixed - maths helper now makes a last-ditch attempt to parse the toString() result from an unknown value type into a number, only returning 0 if this fails. This means that renderable dates formatted as epoch will be parseable. | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/MathsHelper.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/MathsHelper.java",
"diff": "/*\n- * Copyright (C) 2021 Thomas Akehurst\n+ * Copyright (C) 2021-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -75,12 +75,12 @@ public class MathsHelper extends HandlebarsHelper<Object> {\nreturn BigDecimal.valueOf((float) value);\n}\n- if (value instanceof CharSequence) {\n+ try {\nreturn new BigDecimal(value.toString());\n- }\n-\n+ } catch (NumberFormatException e) {\nreturn new BigDecimal(0);\n}\n+ }\nprivate static Object reduceToPrimitiveNumber(BigDecimal value) {\nif (value == null) {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/MathsHelperTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/extension/responsetemplating/helpers/MathsHelperTest.java",
"diff": "/*\n- * Copyright (C) 2021 Thomas Akehurst\n+ * Copyright (C) 2021-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -19,6 +19,7 @@ import static org.hamcrest.MatcherAssert.assertThat;\nimport static org.hamcrest.Matchers.closeTo;\nimport static org.hamcrest.Matchers.is;\n+import java.util.Date;\nimport org.junit.jupiter.api.BeforeEach;\nimport org.junit.jupiter.api.Test;\n@@ -101,4 +102,12 @@ public class MathsHelperTest extends HandlebarsHelperTestBase {\npublic void modsTwoIntegers() throws Exception {\nassertThat(renderHelperValue(helper, 11, \"%\", 3), is(2));\n}\n+\n+ @Test\n+ void coercesEpochFormattedRenderableDateParameterCorrectly() throws Exception {\n+ Date date = new Date(1663258226792L);\n+ assertThat(\n+ renderHelperValue(helper, new RenderableDate(date, \"epoch\", null), \"+\", 0),\n+ is(1663258226792L));\n+ }\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed #1946 - maths helper now makes a last-ditch attempt to parse the toString() result from an unknown value type into a number, only returning 0 if this fails. This means that renderable dates formatted as epoch will be parseable. |
686,936 | 15.09.2022 18:03:36 | -3,600 | 6378baf01d3869d36eb78f175f60095cfa73a093 | Attempt at making direct server delay tests less flakey by switching to the same delay strategy as the main HTTP server | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/direct/SleepFacade.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/direct/SleepFacade.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.direct;\n+import java.util.concurrent.TimeUnit;\n+\nclass SleepFacade {\nvoid sleep(long millis) {\ntry {\n- Thread.sleep(millis);\n+ TimeUnit.MILLISECONDS.sleep(millis);\n} catch (InterruptedException e) {\nThread.currentThread().interrupt();\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Attempt at making direct server delay tests less flakey by switching to the same delay strategy as the main HTTP server |
686,936 | 15.09.2022 18:23:15 | -3,600 | 577f70b76bb6db6c5e77e0536456530ddea4cfb8 | Further attempt at eliminating flakeyness of delay test for direct HTTP server | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/direct/SleepFacade.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/direct/SleepFacade.java",
"diff": "*/\npackage com.github.tomakehurst.wiremock.direct;\n-import java.util.concurrent.TimeUnit;\n+import java.util.concurrent.*;\n+\n+import static java.util.concurrent.TimeUnit.MILLISECONDS;\nclass SleepFacade {\n+\n+ private final ScheduledExecutorService executorService;\n+\n+ public SleepFacade() {\n+ this.executorService = Executors.newSingleThreadScheduledExecutor();\n+ }\n+\nvoid sleep(long millis) {\ntry {\n- TimeUnit.MILLISECONDS.sleep(millis);\n- } catch (InterruptedException e) {\n+ executorService.schedule(() -> {}, millis, MILLISECONDS).get();\n+ } catch (Exception e) {\nThread.currentThread().interrupt();\n}\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Further attempt at eliminating flakeyness of delay test for direct HTTP server |
686,984 | 15.10.2022 11:50:29 | -7,200 | 7818ed00ebf5cbebbd505480c57a2db78f9afb60 | Add NegativeContainsPattern (aka notContaining) | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/client/WireMock.java",
"diff": "@@ -264,6 +264,10 @@ public class WireMock {\nreturn new ContainsPattern(value);\n}\n+ public static StringValuePattern notContaining(String value) {\n+ return new NegativeContainsPattern(value);\n+ }\n+\npublic static StringValuePattern matching(String regex) {\nreturn new RegexPattern(regex);\n}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/main/java/com/github/tomakehurst/wiremock/matching/NegativeContainsPattern.java",
"diff": "+/*\n+ * Copyright (C) 2016-2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.matching;\n+\n+import com.fasterxml.jackson.annotation.JsonProperty;\n+\n+public class NegativeContainsPattern extends StringValuePattern {\n+\n+ public NegativeContainsPattern(@JsonProperty(\"doesNotContain\") String expectedValue) {\n+ super(expectedValue);\n+ }\n+\n+ public String getDoesNotContain() {\n+ return expectedValue;\n+ }\n+\n+ @Override\n+ public MatchResult match(String value) {\n+ return MatchResult.of(value == null || !value.contains(expectedValue));\n+ }\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/matching/StringValuePatternJsonDeserializer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/matching/StringValuePatternJsonDeserializer.java",
"diff": "@@ -49,6 +49,7 @@ public class StringValuePatternJsonDeserializer extends JsonDeserializer<StringV\n.put(\"equalToXml\", EqualToXmlPattern.class)\n.put(\"matchesXPath\", MatchesXPathPattern.class)\n.put(\"contains\", ContainsPattern.class)\n+ .put(\"doesNotContain\", NegativeContainsPattern.class)\n.put(\"matches\", RegexPattern.class)\n.put(\"doesNotMatch\", NegativeRegexPattern.class)\n.put(\"before\", BeforeDateTimePattern.class)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/StubbingAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/StubbingAcceptanceTest.java",
"diff": "@@ -282,6 +282,19 @@ public class StubbingAcceptanceTest extends AcceptanceTestBase {\nassertThat(testClient.get(\"/path-and-query/match?anotherparam=present\").statusCode(), is(200));\n}\n+ @Test\n+ public void matchesOnQueryParametersNotContaining() {\n+ stubFor(\n+ get(urlPathEqualTo(\"/query/match\"))\n+ .withQueryParam(\"search\", notContaining(\"WireMock\"))\n+ .willReturn(aResponse().withStatus(200)));\n+\n+ assertThat(\n+ testClient.get(\"/query/match?search=WireMock%20stubbing\").statusCode(), is(HTTP_NOT_FOUND));\n+\n+ assertThat(testClient.get(\"/query/match?search=Other%20stubbing\").statusCode(), is(HTTP_OK));\n+ }\n+\n@Test\npublic void responseBodyLoadedFromFile() {\nstubFor(\n@@ -328,6 +341,21 @@ public class StubbingAcceptanceTest extends AcceptanceTestBase {\nassertThat(response.statusCode(), is(HTTP_OK));\n}\n+ @Test\n+ public void matchingOnRequestBodyWithNotContaining() {\n+ stubFor(\n+ put(urlEqualTo(\"/match/this/body/too\"))\n+ .withRequestBody(notContaining(\"OtherBody\"))\n+ .willReturn(aResponse().withStatus(HTTP_OK).withBodyFile(\"plain-example.txt\")));\n+\n+ WireMockResponse response =\n+ testClient.putWithBody(\"/match/this/body/too\", \"BlahOtherBody12345\", \"text/plain\");\n+ assertThat(response.statusCode(), is(HTTP_NOT_FOUND));\n+\n+ response = testClient.putWithBody(\"/match/this/body/too\", \"BlahBlahBlah\", \"text/plain\");\n+ assertThat(response.statusCode(), is(HTTP_OK));\n+ }\n+\n@Test\npublic void matchingOnRequestBodyWithEqualTo() {\nstubFor(\n@@ -668,6 +696,27 @@ public class StubbingAcceptanceTest extends AcceptanceTestBase {\nassertThat(response.statusCode(), is(HTTP_OK));\n}\n+ @Test\n+ public void matchingOnMultipartRequestBodyWithNotContaining() {\n+ stubFor(\n+ post(urlEqualTo(\"/match/this/part/too\"))\n+ .withMultipartRequestBody(\n+ aMultipart()\n+ .withHeader(\"Content-Type\", notContaining(\"application/json\"))\n+ .withBody(notContaining(\"OtherStuff\")))\n+ .willReturn(aResponse().withStatus(HTTP_OK).withBodyFile(\"plain-example.txt\")));\n+\n+ WireMockResponse response =\n+ testClient.postWithMultiparts(\n+ \"/match/this/part/too\", singletonList(part(\"part\", \"BlahOtherStuff12345\", TEXT_PLAIN)));\n+ assertThat(response.statusCode(), is(HTTP_NOT_FOUND));\n+\n+ response =\n+ testClient.postWithMultiparts(\n+ \"/match/this/part/too\", singletonList(part(\"part\", \"BlahBlahBlah\", TEXT_PLAIN)));\n+ assertThat(response.statusCode(), is(HTTP_OK));\n+ }\n+\n@Test\npublic void matchingOnMultipartRequestBodyWithEqualTo() {\nstubFor(\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/matching/NegativeContainsPatternTest.java",
"diff": "+/*\n+ * Copyright (C) 2016-2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.matching;\n+\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+import static org.junit.jupiter.api.Assertions.assertFalse;\n+import static org.junit.jupiter.api.Assertions.assertTrue;\n+\n+import com.github.tomakehurst.wiremock.client.WireMock;\n+import org.junit.jupiter.api.Test;\n+\n+public class NegativeContainsPatternTest {\n+\n+ @Test\n+ public void returnsExactMatchWhenExpectedValueNotContainedInTestValue() {\n+ assertTrue(WireMock.notContaining(\"thing\").match(\"otherstuff\").isExactMatch());\n+ }\n+\n+ @Test\n+ public void returnsExactMatchWhenTestValueIsNull() {\n+ assertTrue(WireMock.notContaining(\"thing\").match(null).isExactMatch());\n+ }\n+\n+ @Test\n+ public void returnsNoMatchWhenWhenExpectedValueWhollyContainedInTestValue() {\n+ MatchResult matchResult = WireMock.notContaining(\"thing\").match(\"mythings\");\n+ assertFalse(matchResult.isExactMatch());\n+ assertThat(matchResult.getDistance(), is(1.0));\n+ }\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/matching/RequestPatternTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/matching/RequestPatternTest.java",
"diff": "@@ -458,6 +458,7 @@ public class RequestPatternTest {\n+ \" { \\\"equalToXml\\\": \\\"<thing />\\\" }, \\n\"\n+ \" { \\\"matchesXPath\\\": \\\"//thing\\\" }, \\n\"\n+ \" { \\\"contains\\\": \\\"thin\\\" }, \\n\"\n+ + \" { \\\"doesNotContain\\\": \\\"stuff\\\" }, \\n\"\n+ \" { \\\"matches\\\": \\\".*thing.*\\\" }, \\n\"\n+ \" { \\\"doesNotMatch\\\": \\\"^stuff.+\\\" } \\n\"\n+ \" ] \\n\"\n@@ -476,6 +477,7 @@ public class RequestPatternTest {\nvaluePattern(EqualToXmlPattern.class, \"<thing />\"),\nvaluePattern(MatchesXPathPattern.class, \"//thing\"),\nvaluePattern(ContainsPattern.class, \"thin\"),\n+ valuePattern(NegativeContainsPattern.class, \"stuff\"),\nvaluePattern(RegexPattern.class, \".*thing.*\"),\nvaluePattern(NegativeRegexPattern.class, \"^stuff.+\")));\n}\n@@ -490,6 +492,7 @@ public class RequestPatternTest {\n.withRequestBody(equalToXml(\"<thing />\"))\n.withRequestBody(matchingXPath(\"//thing\"))\n.withRequestBody(containing(\"thin\"))\n+ .withRequestBody(notContaining(\"stuff\"))\n.withRequestBody(matching(\".*thing.*\"))\n.withRequestBody(notMatching(\"^stuff.+\"))\n.build();\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Add NegativeContainsPattern (aka notContaining) (#1881) (#1987) |
687,011 | 21.10.2022 13:40:12 | -7,200 | dac7adb492f62296020861d623fb51f0c53298b9 | Bumping Handlebars library version to 4.3.1, that includes the fixed
commons-text CVE. | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -25,7 +25,7 @@ group = 'com.github.tomakehurst'\nproject.ext {\nversions = [\n- handlebars : '4.3.0',\n+ handlebars : '4.3.1',\njetty : '9.4.49.v20220914',\nguava : '31.1-jre',\njackson : '2.13.4.20221013',\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Bumping Handlebars library version to 4.3.1, that includes the fixed (#1995)
commons-text CVE.
Co-authored-by: Tom Akehurst <t.m.akehurst@googlemail.com> |
686,936 | 25.10.2022 13:41:33 | -3,600 | b367b7b1be2aca2c61836ce3c42d699439597223 | Switched BodyChunker to use the configured notifier rather than creating its own | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/BodyChunker.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/BodyChunker.java",
"diff": "/*\n- * Copyright (C) 2017-2021 Thomas Akehurst\n+ * Copyright (C) 2017-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n*/\npackage com.github.tomakehurst.wiremock.servlet;\n-import com.github.tomakehurst.wiremock.common.Notifier;\n-import com.github.tomakehurst.wiremock.common.Slf4jNotifier;\n+import static com.github.tomakehurst.wiremock.common.LocalNotifier.notifier;\n+\nimport java.util.Arrays;\npublic class BodyChunker {\n- private static final Notifier notifier = new Slf4jNotifier(false);\n-\npublic static byte[][] chunkBody(byte[] body, int numberOfChunks) {\nif (numberOfChunks < 1) {\n- notifier.error(\"Number of chunks set to value less than 1: \" + numberOfChunks);\n+ notifier().error(\"Number of chunks set to value less than 1: \" + numberOfChunks);\nnumberOfChunks = 1;\n}\nif (body.length < numberOfChunks) {\n- notifier.error(\n+ notifier()\n+ .error(\n\"Number of chunks set to value greater then body length. Number of chunks: \"\n+ numberOfChunks\n+ \". Body length: \"\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Switched BodyChunker to use the configured notifier rather than creating its own |
686,936 | 25.10.2022 13:43:05 | -3,600 | 1f43b2794ca301a8504851b90d23522193bec5b1 | Dropped back down to slf4j 1.7.36 and relocated it in the standalone JAR to avoid clashes with 2.x. | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -65,7 +65,9 @@ dependencies {\nexclude group: 'org.ow2.asm', module: 'asm'\n}\napi \"org.ow2.asm:asm:9.4\"\n- api \"org.slf4j:slf4j-api:2.0.3\"\n+\n+ implementation \"org.slf4j:slf4j-api:1.7.36\"\n+\napi \"net.sf.jopt-simple:jopt-simple:5.0.4\"\ncompileOnly(\"junit:junit:4.13.2\") {\n@@ -287,6 +289,7 @@ shadowJar {\nrelocate \"javax.servlet\", \"wiremock.javax.servlet\"\nrelocate \"org.checkerframework\", \"wiremock.org.checkerframework\"\nrelocate \"org.hamcrest\", \"wiremock.org.hamcrest\"\n+ relocate \"org.slf4j\", \"wiremock.org.slf4j\"\ndependencies {\nexclude(dependency('junit:junit'))\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Dropped back down to slf4j 1.7.36 and relocated it in the standalone JAR to avoid clashes with 2.x. |
686,936 | 25.10.2022 13:56:57 | -3,600 | e1368f436fc692b14b5edf36a0fcf65a12dff131 | Added slf4j no-op (disables logging and annoying messages from slf4j) to the standalone JAR | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -35,6 +35,10 @@ project.ext {\n]\n}\n+configurations {\n+ standaloneOnly\n+}\n+\ndependencies {\napi platform(\"org.eclipse.jetty:jetty-bom:$versions.jetty\")\napi \"org.eclipse.jetty:jetty-server\"\n@@ -67,6 +71,7 @@ dependencies {\napi \"org.ow2.asm:asm:9.4\"\nimplementation \"org.slf4j:slf4j-api:1.7.36\"\n+ standaloneOnly \"org.slf4j:slf4j-nop:1.7.36\"\napi \"net.sf.jopt-simple:jopt-simple:5.0.4\"\n@@ -265,6 +270,10 @@ jar {\n}\nshadowJar {\n+ configurations = [\n+ project.configurations.runtimeClasspath,\n+ project.configurations.standaloneOnly\n+ ]\narchiveBaseName.set('wiremock-jre8-standalone')\nrelocate \"org.mortbay\", 'wiremock.org.mortbay'\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added slf4j no-op (disables logging and annoying messages from slf4j) to the standalone JAR |
686,936 | 01.11.2022 15:15:31 | 0 | 5d0a056c7714a91c03971c8b2e52c0d45aefee96 | Closes - added support for preventing proxying to certain addresses via allow/deny lists | [
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRange.java",
"diff": "+/*\n+ * Copyright (C) 2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.common;\n+\n+import com.google.common.net.InetAddresses;\n+import java.math.BigInteger;\n+import java.net.InetAddress;\n+import java.net.UnknownHostException;\n+import java.util.regex.Pattern;\n+\n+public abstract class NetworkAddressRange {\n+\n+ public static final NetworkAddressRange ALL = new All();\n+\n+ private static final Pattern SINGLE_IP =\n+ Pattern.compile(\"\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\");\n+ private static final Pattern IP_RANGE =\n+ Pattern.compile(\n+ \"\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}-\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\");\n+\n+ public static NetworkAddressRange of(String value) {\n+ if (SINGLE_IP.matcher(value).matches()) {\n+ return new SingleIp(value);\n+ }\n+\n+ if (IP_RANGE.matcher(value).matches()) {\n+ return new IpRange(value);\n+ }\n+\n+ return new DomainNameWildcard(value);\n+ }\n+\n+ public abstract boolean isIncluded(String testValue);\n+\n+ private static class SingleIp extends NetworkAddressRange {\n+\n+ private final InetAddress inetAddress;\n+\n+ private SingleIp(String ipAddress) {\n+ this.inetAddress = parseIpAddress(ipAddress);\n+ }\n+\n+ @Override\n+ public boolean isIncluded(String testValue) {\n+ return lookup(testValue).equals(inetAddress);\n+ }\n+ }\n+\n+ private static class IpRange extends NetworkAddressRange {\n+\n+ private final BigInteger start;\n+ private final BigInteger end;\n+\n+ private IpRange(String ipRange) {\n+ String[] parts = ipRange.split(\"-\");\n+ if (parts.length != 2) {\n+ throw new InvalidInputException(Errors.single(18, ipRange + \" is not a valid IP range\"));\n+ }\n+ this.start = InetAddresses.toBigInteger(parseIpAddress(parts[0]));\n+ this.end = InetAddresses.toBigInteger(parseIpAddress(parts[1]));\n+ }\n+\n+ @Override\n+ public boolean isIncluded(String testValue) {\n+ InetAddress testValueAddress = lookup(testValue);\n+ BigInteger intVal = InetAddresses.toBigInteger(testValueAddress);\n+ return intVal.compareTo(start) >= 0 && intVal.compareTo(end) <= 0;\n+ }\n+ }\n+\n+ private static class DomainNameWildcard extends NetworkAddressRange {\n+\n+ private final Pattern namePattern;\n+\n+ private DomainNameWildcard(String namePattern) {\n+ String nameRegex = namePattern.replace(\".\", \"\\\\.\").replace(\"*\", \".+\");\n+ this.namePattern = Pattern.compile(nameRegex);\n+ }\n+\n+ @Override\n+ public boolean isIncluded(String testValue) {\n+ return namePattern.matcher(testValue).matches();\n+ }\n+ }\n+\n+ private static class All extends NetworkAddressRange {\n+\n+ @Override\n+ public boolean isIncluded(String testValue) {\n+ return true;\n+ }\n+ }\n+\n+ private static InetAddress parseIpAddress(String ipAddress) {\n+ if (!InetAddresses.isInetAddress(ipAddress)) {\n+ throw new InvalidInputException(Errors.single(16, ipAddress + \" is not a valid IP address\"));\n+ }\n+\n+ return lookup(ipAddress);\n+ }\n+\n+ private static InetAddress lookup(String host) {\n+ try {\n+ return InetAddress.getByName(host);\n+ } catch (UnknownHostException e) {\n+ throw new InvalidInputException(\n+ e, Errors.single(17, host + \" is not a valid network address\"));\n+ }\n+ }\n+}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRules.java",
"diff": "+/*\n+ * Copyright (C) 2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.common;\n+\n+import static com.github.tomakehurst.wiremock.common.NetworkAddressRange.ALL;\n+import static java.util.Collections.emptySet;\n+\n+import com.google.common.collect.ImmutableSet;\n+import java.util.Set;\n+\n+public class NetworkAddressRules {\n+\n+ public static Builder builder() {\n+ return new Builder();\n+ }\n+\n+ private final Set<NetworkAddressRange> allowed;\n+ private final Set<NetworkAddressRange> denied;\n+\n+ public static NetworkAddressRules ALLOW_ALL =\n+ new NetworkAddressRules(ImmutableSet.of(ALL), emptySet());\n+\n+ public NetworkAddressRules(Set<NetworkAddressRange> allowed, Set<NetworkAddressRange> denied) {\n+ this.allowed = allowed;\n+ this.denied = denied;\n+ }\n+\n+ public boolean isAllowed(String testValue) {\n+ return allowed.stream().anyMatch(rule -> rule.isIncluded(testValue))\n+ && denied.stream().noneMatch(rule -> rule.isIncluded(testValue));\n+ }\n+\n+ public static class Builder {\n+ private final ImmutableSet.Builder<NetworkAddressRange> allowed = ImmutableSet.builder();\n+ private final ImmutableSet.Builder<NetworkAddressRange> denied = ImmutableSet.builder();\n+\n+ public Builder allow(String expression) {\n+ allowed.add(NetworkAddressRange.of(expression));\n+ return this;\n+ }\n+\n+ public Builder deny(String expression) {\n+ denied.add(NetworkAddressRange.of(expression));\n+ return this;\n+ }\n+\n+ public NetworkAddressRules build() {\n+ return new NetworkAddressRules(allowed.build(), denied.build());\n+ }\n+ }\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/Options.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/Options.java",
"diff": "@@ -111,4 +111,6 @@ public interface Options {\nboolean getDisableStrictHttpHeaders();\nDataTruncationSettings getDataTruncationSettings();\n+\n+ NetworkAddressRules getProxyTargetRules();\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockApp.java",
"diff": "@@ -177,7 +177,8 @@ public class WireMockApp implements StubServer, Admin {\nglobalSettingsHolder,\nbrowserProxySettings.trustAllProxyTargets(),\nbrowserProxySettings.trustedProxyTargets(),\n- options.getStubCorsEnabled()),\n+ options.getStubCorsEnabled(),\n+ options.getProxyTargetRules()),\nImmutableList.copyOf(options.extensionsOfType(ResponseTransformer.class).values())),\nthis,\npostServeActions,\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/core/WireMockConfiguration.java",
"diff": "@@ -121,6 +121,8 @@ public class WireMockConfiguration implements Options {\nprivate Limit responseBodySizeLimit = UNLIMITED;\n+ private NetworkAddressRules proxyTargetRules = NetworkAddressRules.ALLOW_ALL;\n+\nprivate MappingsSource getMappingsSource() {\nif (mappingsSource == null) {\nmappingsSource = new JsonFileMappingsSource(filesRoot.child(MAPPINGS_ROOT));\n@@ -444,6 +446,22 @@ public class WireMockConfiguration implements Options {\nreturn this;\n}\n+ public WireMockConfiguration disableOptimizeXmlFactoriesLoading(\n+ boolean disableOptimizeXmlFactoriesLoading) {\n+ this.disableOptimizeXmlFactoriesLoading = disableOptimizeXmlFactoriesLoading;\n+ return this;\n+ }\n+\n+ public WireMockConfiguration maxLoggedResponseSize(int maxSize) {\n+ this.responseBodySizeLimit = new Limit(maxSize);\n+ return this;\n+ }\n+\n+ public WireMockConfiguration limitProxyTargets(NetworkAddressRules proxyTargetRules) {\n+ this.proxyTargetRules = proxyTargetRules;\n+ return this;\n+ }\n+\n@Override\npublic int portNumber() {\nreturn portNumber;\n@@ -619,12 +637,6 @@ public class WireMockConfiguration implements Options {\nreturn disableOptimizeXmlFactoriesLoading;\n}\n- public WireMockConfiguration disableOptimizeXmlFactoriesLoading(\n- boolean disableOptimizeXmlFactoriesLoading) {\n- this.disableOptimizeXmlFactoriesLoading = disableOptimizeXmlFactoriesLoading;\n- return this;\n- }\n-\n@Override\npublic boolean getDisableStrictHttpHeaders() {\nreturn disableStrictHttpHeaders;\n@@ -657,8 +669,8 @@ public class WireMockConfiguration implements Options {\n.build();\n}\n- public WireMockConfiguration maxLoggedResponseSize(int maxSize) {\n- this.responseBodySizeLimit = new Limit(maxSize);\n- return this;\n+ @Override\n+ public NetworkAddressRules getProxyTargetRules() {\n+ return proxyTargetRules;\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/http/ProxyResponseRenderer.java",
"diff": "@@ -19,6 +19,7 @@ import static com.github.tomakehurst.wiremock.common.HttpClientUtils.getEntityAs\nimport static com.github.tomakehurst.wiremock.http.Response.response;\nimport static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;\n+import com.github.tomakehurst.wiremock.common.NetworkAddressRules;\nimport com.github.tomakehurst.wiremock.common.ProxySettings;\nimport com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings;\nimport com.github.tomakehurst.wiremock.global.GlobalSettingsHolder;\n@@ -26,8 +27,11 @@ import com.github.tomakehurst.wiremock.stubbing.ServeEvent;\nimport com.google.common.collect.ImmutableList;\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\n+import java.net.InetAddress;\nimport java.net.URI;\nimport java.net.URISyntaxException;\n+import java.net.UnknownHostException;\n+import java.util.Arrays;\nimport java.util.Collections;\nimport java.util.LinkedList;\nimport java.util.List;\n@@ -61,6 +65,8 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nprivate final GlobalSettingsHolder globalSettingsHolder;\nprivate final boolean stubCorsEnabled;\n+ private final NetworkAddressRules targetAddressRules;\n+\npublic ProxyResponseRenderer(\nProxySettings proxySettings,\nKeyStoreSettings trustStoreSettings,\n@@ -69,7 +75,8 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nGlobalSettingsHolder globalSettingsHolder,\nboolean trustAllProxyTargets,\nList<String> trustedProxyTargets,\n- boolean stubCorsEnabled) {\n+ boolean stubCorsEnabled,\n+ NetworkAddressRules targetAddressRules) {\nthis.globalSettingsHolder = globalSettingsHolder;\nreverseProxyClient =\nHttpClientFactory.createClient(\n@@ -93,11 +100,20 @@ public class ProxyResponseRenderer implements ResponseRenderer {\nthis.preserveHostHeader = preserveHostHeader;\nthis.hostHeaderValue = hostHeaderValue;\nthis.stubCorsEnabled = stubCorsEnabled;\n+ this.targetAddressRules = targetAddressRules;\n}\n@Override\npublic Response render(ServeEvent serveEvent) {\nResponseDefinition responseDefinition = serveEvent.getResponseDefinition();\n+ if (targetAddressProhibited(responseDefinition.getProxyUrl())) {\n+ return response()\n+ .status(500)\n+ .headers(new HttpHeaders(new HttpHeader(\"Content-Type\", \"text/plain\")))\n+ .body(\"The target proxy address is denied in WireMock's configuration.\")\n+ .build();\n+ }\n+\nHttpUriRequest httpRequest = getHttpRequestFor(responseDefinition);\naddRequestHeaders(httpRequest, responseDefinition);\n@@ -127,6 +143,17 @@ public class ProxyResponseRenderer implements ResponseRenderer {\n}\n}\n+ private boolean targetAddressProhibited(String proxyUrl) {\n+ String host = URI.create(proxyUrl).getHost();\n+ try {\n+ final InetAddress[] resolvedAddresses = InetAddress.getAllByName(host);\n+ return !Arrays.stream(resolvedAddresses)\n+ .allMatch(address -> targetAddressRules.isAllowed(address.getHostAddress()));\n+ } catch (UnknownHostException e) {\n+ return true;\n+ }\n+ }\n+\nprivate Response proxyResponseError(String type, HttpUriRequest request, Exception e) {\nreturn response()\n.status(HTTP_INTERNAL_ERROR)\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WarConfiguration.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/servlet/WarConfiguration.java",
"diff": "@@ -219,6 +219,11 @@ public class WarConfiguration implements Options {\nreturn DataTruncationSettings.DEFAULTS;\n}\n+ @Override\n+ public NetworkAddressRules getProxyTargetRules() {\n+ return NetworkAddressRules.ALLOW_ALL;\n+ }\n+\n@Override\npublic BrowserProxySettings browserProxySettings() {\nreturn BrowserProxySettings.DISABLED;\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"diff": "@@ -22,6 +22,8 @@ import static com.github.tomakehurst.wiremock.common.ProxySettings.NO_PROXY;\nimport static com.github.tomakehurst.wiremock.core.WireMockApp.MAPPINGS_ROOT;\nimport static com.github.tomakehurst.wiremock.extension.ExtensionLoader.valueAssignableFrom;\nimport static com.github.tomakehurst.wiremock.http.CaseInsensitiveKey.TO_CASE_INSENSITIVE_KEYS;\n+import static java.util.Collections.emptySet;\n+import static java.util.stream.Collectors.toSet;\nimport com.github.tomakehurst.wiremock.common.*;\nimport com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings;\n@@ -53,10 +55,7 @@ import com.google.common.io.Resources;\nimport java.io.IOException;\nimport java.io.StringWriter;\nimport java.net.URI;\n-import java.util.Collections;\n-import java.util.List;\n-import java.util.Map;\n-import java.util.Set;\n+import java.util.*;\nimport joptsimple.OptionParser;\nimport joptsimple.OptionSet;\n@@ -119,6 +118,8 @@ public class CommandLineOptions implements Options {\nprivate static final String DISABLE_STRICT_HTTP_HEADERS = \"disable-strict-http-headers\";\nprivate static final String LOAD_RESOURCES_FROM_CLASSPATH = \"load-resources-from-classpath\";\nprivate static final String LOGGED_RESPONSE_BODY_SIZE_LIMIT = \"logged-response-body-size-limit\";\n+ private static final String ALLOW_PROXY_TARGETS = \"allow-proxy-targets\";\n+ private static final String DENY_PROXY_TARGETS = \"deny-proxy-targets\";\nprivate final OptionSet optionSet;\nprivate final FileSource fileSource;\n@@ -342,6 +343,16 @@ public class CommandLineOptions implements Options {\nLOGGED_RESPONSE_BODY_SIZE_LIMIT,\n\"Maximum size for response bodies stored in the request journal beyond which truncation will be applied\")\n.withRequiredArg();\n+ optionParser\n+ .accepts(\n+ ALLOW_PROXY_TARGETS,\n+ \"Comma separated list of IP addresses, IP ranges (hyphenated) and domain name wildcards that can be proxied to/recorded from. Is evaluated before the list of denied addresses.\")\n+ .withRequiredArg();\n+ optionParser\n+ .accepts(\n+ DENY_PROXY_TARGETS,\n+ \"Comma separated list of IP addresses, IP ranges (hyphenated) and domain name wildcards that cannot be proxied to/recorded from. Is evaluated after the list of allowed addresses.\")\n+ .withRequiredArg();\noptionParser.accepts(HELP, \"Print this message\").forHelp();\n@@ -836,6 +847,23 @@ public class CommandLineOptions implements Options {\n: DataTruncationSettings.DEFAULTS;\n}\n+ @Override\n+ public NetworkAddressRules getProxyTargetRules() {\n+ final Set<NetworkAddressRange> allowed =\n+ optionSet.has(ALLOW_PROXY_TARGETS)\n+ ? Arrays.stream(((String) optionSet.valueOf(ALLOW_PROXY_TARGETS)).split(\",\"))\n+ .map(NetworkAddressRange::of)\n+ .collect(toSet())\n+ : ImmutableSet.of(NetworkAddressRange.ALL);\n+ final Set<NetworkAddressRange> denied =\n+ optionSet.has(DENY_PROXY_TARGETS)\n+ ? Arrays.stream(((String) optionSet.valueOf(DENY_PROXY_TARGETS)).split(\",\"))\n+ .map(NetworkAddressRange::of)\n+ .collect(toSet())\n+ : emptySet();\n+ return new NetworkAddressRules(allowed, denied);\n+ }\n+\n@SuppressWarnings(\"unchecked\")\n@Override\npublic BrowserProxySettings browserProxySettings() {\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/ProxyAcceptanceTest.java",
"diff": "package com.github.tomakehurst.wiremock;\nimport static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.client.WireMock.any;\n+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;\nimport static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;\nimport static com.github.tomakehurst.wiremock.testsupport.TestHttpHeader.withHeader;\nimport static com.google.common.collect.Iterables.getLast;\n@@ -23,12 +25,11 @@ import static com.google.common.net.HttpHeaders.CONTENT_ENCODING;\nimport static java.util.concurrent.TimeUnit.MILLISECONDS;\nimport static org.apache.hc.core5.http.ContentType.TEXT_PLAIN;\nimport static org.hamcrest.MatcherAssert.assertThat;\n-import static org.hamcrest.Matchers.greaterThanOrEqualTo;\n-import static org.hamcrest.Matchers.hasItems;\n-import static org.hamcrest.Matchers.is;\n-import static org.junit.jupiter.api.Assertions.assertFalse;\n+import static org.hamcrest.Matchers.*;\n+import static org.junit.jupiter.api.Assertions.*;\nimport com.github.tomakehurst.wiremock.client.WireMock;\n+import com.github.tomakehurst.wiremock.common.NetworkAddressRules;\nimport com.github.tomakehurst.wiremock.common.ProxySettings;\nimport com.github.tomakehurst.wiremock.core.Options;\nimport com.github.tomakehurst.wiremock.core.WireMockConfiguration;\n@@ -636,6 +637,62 @@ public class ProxyAcceptanceTest {\nassertThat(requests.get(0).getBodyAsString(), is(\"Proxied content\"));\n}\n+ @Test\n+ void preventsProxyingToExcludedIpAddress() {\n+ init(\n+ wireMockConfig()\n+ .limitProxyTargets(\n+ NetworkAddressRules.builder()\n+ .deny(\"10.1.2.3\")\n+ .deny(\"192.168.10.1-192.168.11.254\")\n+ .build()));\n+\n+ proxy.register(proxyAllTo(\"https://10.1.2.3\"));\n+ WireMockResponse response = testClient.get(\"/\");\n+ assertThat(response.statusCode(), is(500));\n+ assertThat(\n+ response.content(), is(\"The target proxy address is denied in WireMock's configuration.\"));\n+\n+ proxy.register(proxyAllTo(\"https://192.168.10.255\"));\n+ assertThat(testClient.get(\"/\").statusCode(), is(500));\n+ }\n+\n+ @Test\n+ void preventsProxyingToExcludedHostnames() {\n+ init(\n+ wireMockConfig()\n+ .limitProxyTargets(NetworkAddressRules.builder().deny(\"*.wiremock.org\").build()));\n+\n+ proxy.register(proxyAllTo(\"http://noway.wiremock.org\"));\n+ assertThat(\n+ testClient.get(\"/\").content(),\n+ is(\"The target proxy address is denied in WireMock's configuration.\"));\n+ }\n+\n+ @Test\n+ void preventsProxyingToNonIncludedHostnames() {\n+ init(\n+ wireMockConfig()\n+ .limitProxyTargets(NetworkAddressRules.builder().allow(\"wiremock.org\").build()));\n+\n+ proxy.register(proxyAllTo(\"http://wiremock.io\"));\n+ assertThat(\n+ testClient.get(\"/\").content(),\n+ is(\"The target proxy address is denied in WireMock's configuration.\"));\n+ }\n+\n+ @Test\n+ void preventsProxyingToIpResolvedFromHostname() {\n+ init(\n+ wireMockConfig()\n+ .limitProxyTargets(NetworkAddressRules.builder().deny(\"127.0.0.1\").build()));\n+\n+ proxy.register(proxyAllTo(\"http://localhost\"));\n+ assertThat(\n+ testClient.get(\"/\").content(),\n+ is(\"The target proxy address is denied in WireMock's configuration.\"));\n+ }\n+\nprivate void register200StubOnProxyAndTarget(String url) {\ntarget.register(get(urlEqualTo(url)).willReturn(aResponse().withStatus(200)));\nproxy.register(get(urlEqualTo(url)).willReturn(aResponse().proxiedFrom(targetServiceBaseUrl)));\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/common/NetworkAddressRangeTest.java",
"diff": "+/*\n+ * Copyright (C) 2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.common;\n+\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+\n+import org.junit.jupiter.api.Test;\n+\n+public class NetworkAddressRangeTest {\n+\n+ @Test\n+ void singleIpAddress() {\n+ NetworkAddressRange exclusion = NetworkAddressRange.of(\"10.1.2.3\");\n+\n+ assertThat(exclusion.isIncluded(\"10.1.2.3\"), is(true));\n+ assertThat(exclusion.isIncluded(\"10.3.2.1\"), is(false));\n+ }\n+\n+ @Test\n+ void ipAddressRange() {\n+ NetworkAddressRange exclusion = NetworkAddressRange.of(\"10.1.1.1-10.1.2.2\");\n+\n+ assertThat(exclusion.isIncluded(\"10.1.1.1\"), is(true));\n+ assertThat(exclusion.isIncluded(\"10.1.2.2\"), is(true));\n+ assertThat(exclusion.isIncluded(\"10.1.1.254\"), is(true));\n+ assertThat(exclusion.isIncluded(\"10.1.2.1\"), is(true));\n+\n+ assertThat(exclusion.isIncluded(\"10.3.2.1\"), is(false));\n+ assertThat(exclusion.isIncluded(\"10.1.1.0\"), is(false));\n+ assertThat(exclusion.isIncluded(\"10.1.2.3\"), is(false));\n+ }\n+\n+ @Test\n+ void exactDomainName() {\n+ NetworkAddressRange exclusion = NetworkAddressRange.of(\"my.stuff.wiremock.org\");\n+\n+ assertThat(exclusion.isIncluded(\"my.stuff.wiremock.org\"), is(true));\n+ assertThat(exclusion.isIncluded(\"notmy.stuff.wiremock.org\"), is(false));\n+ }\n+\n+ @Test\n+ void domainNameWithWholeNameWildcard() {\n+ NetworkAddressRange exclusion = NetworkAddressRange.of(\"*.stuff.wiremock.org\");\n+\n+ assertThat(exclusion.isIncluded(\"my.stuff.wiremock.org\"), is(true));\n+ assertThat(exclusion.isIncluded(\"alsomy.stuff.wiremock.org\"), is(true));\n+ assertThat(exclusion.isIncluded(\"notmy.things.wiremock.org\"), is(false));\n+ }\n+\n+ @Test\n+ void domainNameWithPartialNameWildcard() {\n+ NetworkAddressRange exclusion = NetworkAddressRange.of(\"my.*uff.wiremock.org\");\n+\n+ assertThat(exclusion.isIncluded(\"my.stuff.wiremock.org\"), is(true));\n+ assertThat(exclusion.isIncluded(\"my.fluff.wiremock.org\"), is(true));\n+ assertThat(exclusion.isIncluded(\"notmy.stuff.wiremock.org\"), is(false));\n+ }\n+\n+ @Test\n+ void ipAddressResolvedFromDomainName() {\n+ NetworkAddressRange exclusion = NetworkAddressRange.of(\"127.0.0.1\");\n+ assertThat(exclusion.isIncluded(\"localhost\"), is(true));\n+ }\n+\n+ @Test\n+ void ipRangeResolvedFromDomainName() {\n+ NetworkAddressRange exclusion = NetworkAddressRange.of(\"127.0.0.1-127.0.0.255\");\n+ assertThat(exclusion.isIncluded(\"localhost\"), is(true));\n+ }\n+}\n"
},
{
"change_type": "ADD",
"old_path": null,
"new_path": "src/test/java/com/github/tomakehurst/wiremock/common/NetworkAddressRulesTest.java",
"diff": "+/*\n+ * Copyright (C) 2022 Thomas Akehurst\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package com.github.tomakehurst.wiremock.common;\n+\n+import static org.hamcrest.MatcherAssert.assertThat;\n+import static org.hamcrest.Matchers.is;\n+\n+import org.junit.jupiter.api.Test;\n+\n+public class NetworkAddressRulesTest {\n+\n+ @Test\n+ void allowsAddressIncludedAndNotExcluded() {\n+ NetworkAddressRules rules =\n+ NetworkAddressRules.builder()\n+ .allow(\"10.1.1.1-10.2.1.1\")\n+ .allow(\"192.168.1.1-192.168.2.1\")\n+ .deny(\"10.1.2.3\")\n+ .deny(\"10.5.5.5\")\n+ .build();\n+\n+ assertThat(rules.isAllowed(\"192.168.1.111\"), is(true));\n+\n+ assertThat(rules.isAllowed(\"10.1.2.1\"), is(true));\n+ assertThat(rules.isAllowed(\"10.1.2.3\"), is(false));\n+ assertThat(rules.isAllowed(\"10.5.5.5\"), is(false));\n+ }\n+}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyResponseRendererTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/http/ProxyResponseRendererTest.java",
"diff": "package com.github.tomakehurst.wiremock.http;\nimport static com.github.tomakehurst.wiremock.client.WireMock.*;\n+import static com.github.tomakehurst.wiremock.common.NetworkAddressRules.ALLOW_ALL;\nimport static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;\nimport static com.github.tomakehurst.wiremock.crypto.X509CertificateVersion.V3;\nimport static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;\n@@ -346,7 +347,8 @@ public class ProxyResponseRendererTest {\nnew GlobalSettingsHolder(),\ntrustAllProxyTargets,\nCollections.<String>emptyList(),\n- stubCorsEnabled);\n+ stubCorsEnabled,\n+ ALLOW_ALL);\n}\n// Just exists to make the compiler happy by having the throws clause\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptionsTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptionsTest.java",
"diff": "@@ -753,6 +753,22 @@ public class CommandLineOptionsTest {\nassertThat(limit.isExceededBy(Integer.MAX_VALUE), is(false));\n}\n+ @Test\n+ void proxyTargetRules() {\n+ CommandLineOptions options =\n+ new CommandLineOptions(\n+ \"--allow-proxy-targets\", \"192.168.1.1,10.1.1.1-10.2.2.2\",\n+ \"--deny-proxy-targets\", \"192.168.56.1,*host\");\n+\n+ NetworkAddressRules proxyTargetRules = options.getProxyTargetRules();\n+\n+ assertThat(proxyTargetRules.isAllowed(\"192.168.1.1\"), is(true));\n+ assertThat(proxyTargetRules.isAllowed(\"10.1.2.3\"), is(true));\n+\n+ assertThat(proxyTargetRules.isAllowed(\"10.3.2.1\"), is(false));\n+ assertThat(proxyTargetRules.isAllowed(\"localhost\"), is(false));\n+ }\n+\npublic static class ResponseDefinitionTransformerExt1 extends ResponseDefinitionTransformer {\n@Override\npublic ResponseDefinition transform(\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Closes #2007 - added support for preventing proxying to certain addresses via allow/deny lists |
686,936 | 02.11.2022 08:05:56 | 0 | ac079cf3655056c5476469b50670b58c447215be | Simplified IP address range regex in NetworkAddressRange | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRange.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRange.java",
"diff": "@@ -28,8 +28,7 @@ public abstract class NetworkAddressRange {\nprivate static final Pattern SINGLE_IP =\nPattern.compile(\"\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\");\nprivate static final Pattern IP_RANGE =\n- Pattern.compile(\n- \"\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}-\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\\\\.\\\\d{1,3}\");\n+ Pattern.compile(SINGLE_IP.pattern() + \"-\" + SINGLE_IP.pattern());\npublic static NetworkAddressRange of(String value) {\nif (SINGLE_IP.matcher(value).matches()) {\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Simplified IP address range regex in NetworkAddressRange |
686,936 | 02.11.2022 08:17:33 | 0 | 0e42c14c7941a0e91082fc34ac1e9726586e79f9 | Removed some duplicated defaulting logic for configuring proxy target rules from the command line | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRules.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRules.java",
"diff": "@@ -58,7 +58,11 @@ public class NetworkAddressRules {\n}\npublic NetworkAddressRules build() {\n- return new NetworkAddressRules(allowed.build(), denied.build());\n+ Set<NetworkAddressRange> allowedRanges = allowed.build();\n+ if (allowedRanges.isEmpty()) {\n+ allowedRanges = ImmutableSet.of(ALL);\n+ }\n+ return new NetworkAddressRules(allowedRanges, denied.build());\n}\n}\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/standalone/CommandLineOptions.java",
"diff": "@@ -22,8 +22,6 @@ import static com.github.tomakehurst.wiremock.common.ProxySettings.NO_PROXY;\nimport static com.github.tomakehurst.wiremock.core.WireMockApp.MAPPINGS_ROOT;\nimport static com.github.tomakehurst.wiremock.extension.ExtensionLoader.valueAssignableFrom;\nimport static com.github.tomakehurst.wiremock.http.CaseInsensitiveKey.TO_CASE_INSENSITIVE_KEYS;\n-import static java.util.Collections.emptySet;\n-import static java.util.stream.Collectors.toSet;\nimport com.github.tomakehurst.wiremock.common.*;\nimport com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings;\n@@ -849,19 +847,18 @@ public class CommandLineOptions implements Options {\n@Override\npublic NetworkAddressRules getProxyTargetRules() {\n- final Set<NetworkAddressRange> allowed =\n- optionSet.has(ALLOW_PROXY_TARGETS)\n- ? Arrays.stream(((String) optionSet.valueOf(ALLOW_PROXY_TARGETS)).split(\",\"))\n- .map(NetworkAddressRange::of)\n- .collect(toSet())\n- : ImmutableSet.of(NetworkAddressRange.ALL);\n- final Set<NetworkAddressRange> denied =\n- optionSet.has(DENY_PROXY_TARGETS)\n- ? Arrays.stream(((String) optionSet.valueOf(DENY_PROXY_TARGETS)).split(\",\"))\n- .map(NetworkAddressRange::of)\n- .collect(toSet())\n- : emptySet();\n- return new NetworkAddressRules(allowed, denied);\n+ NetworkAddressRules.Builder builder = NetworkAddressRules.builder();\n+ if (optionSet.has(ALLOW_PROXY_TARGETS)) {\n+ Arrays.stream(((String) optionSet.valueOf(ALLOW_PROXY_TARGETS)).split(\",\"))\n+ .forEach(builder::allow);\n+ }\n+\n+ if (optionSet.has(DENY_PROXY_TARGETS)) {\n+ Arrays.stream(((String) optionSet.valueOf(DENY_PROXY_TARGETS)).split(\",\"))\n+ .forEach(builder::deny);\n+ }\n+\n+ return builder.build();\n}\n@SuppressWarnings(\"unchecked\")\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Removed some duplicated defaulting logic for configuring proxy target rules from the command line |
686,936 | 02.11.2022 08:28:02 | 0 | 483d937ed2b3870e9319b74ab18e0279e931622c | Added equals() and hashCode() to NetworkAddressRange | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRange.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/common/NetworkAddressRange.java",
"diff": "@@ -19,6 +19,7 @@ import com.google.common.net.InetAddresses;\nimport java.math.BigInteger;\nimport java.net.InetAddress;\nimport java.net.UnknownHostException;\n+import java.util.Objects;\nimport java.util.regex.Pattern;\npublic abstract class NetworkAddressRange {\n@@ -56,6 +57,19 @@ public abstract class NetworkAddressRange {\npublic boolean isIncluded(String testValue) {\nreturn lookup(testValue).equals(inetAddress);\n}\n+\n+ @Override\n+ public boolean equals(Object o) {\n+ if (this == o) return true;\n+ if (o == null || getClass() != o.getClass()) return false;\n+ SingleIp singleIp = (SingleIp) o;\n+ return inetAddress.equals(singleIp.inetAddress);\n+ }\n+\n+ @Override\n+ public int hashCode() {\n+ return Objects.hash(inetAddress);\n+ }\n}\nprivate static class IpRange extends NetworkAddressRange {\n@@ -78,6 +92,19 @@ public abstract class NetworkAddressRange {\nBigInteger intVal = InetAddresses.toBigInteger(testValueAddress);\nreturn intVal.compareTo(start) >= 0 && intVal.compareTo(end) <= 0;\n}\n+\n+ @Override\n+ public boolean equals(Object o) {\n+ if (this == o) return true;\n+ if (o == null || getClass() != o.getClass()) return false;\n+ IpRange ipRange = (IpRange) o;\n+ return start.equals(ipRange.start) && end.equals(ipRange.end);\n+ }\n+\n+ @Override\n+ public int hashCode() {\n+ return Objects.hash(start, end);\n+ }\n}\nprivate static class DomainNameWildcard extends NetworkAddressRange {\n@@ -93,6 +120,19 @@ public abstract class NetworkAddressRange {\npublic boolean isIncluded(String testValue) {\nreturn namePattern.matcher(testValue).matches();\n}\n+\n+ @Override\n+ public boolean equals(Object o) {\n+ if (this == o) return true;\n+ if (o == null || getClass() != o.getClass()) return false;\n+ DomainNameWildcard that = (DomainNameWildcard) o;\n+ return namePattern.equals(that.namePattern);\n+ }\n+\n+ @Override\n+ public int hashCode() {\n+ return Objects.hash(namePattern);\n+ }\n}\nprivate static class All extends NetworkAddressRange {\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added equals() and hashCode() to NetworkAddressRange |
686,936 | 02.11.2022 08:45:19 | 0 | 355c53dc7ed35bb2fea0621394a5e8ff4c709ee8 | Added some extra NetworkAddressRules test cases | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/common/NetworkAddressRulesTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/common/NetworkAddressRulesTest.java",
"diff": "@@ -38,4 +38,73 @@ public class NetworkAddressRulesTest {\nassertThat(rules.isAllowed(\"10.1.2.3\"), is(false));\nassertThat(rules.isAllowed(\"10.5.5.5\"), is(false));\n}\n+\n+ @Test\n+ void onlyAllowSingleIp() {\n+ NetworkAddressRules rules =\n+ NetworkAddressRules.builder()\n+ .allow(\"10.1.1.1\")\n+ .build();\n+\n+ assertThat(rules.isAllowed(\"10.1.1.1\"), is(true));\n+ assertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.2\"), is(false));\n+ }\n+\n+ @Test\n+ void onlyDenySingleIp() {\n+ NetworkAddressRules rules =\n+ NetworkAddressRules.builder()\n+ .deny(\"10.1.1.1\")\n+ .build();\n+\n+ assertThat(rules.isAllowed(\"10.1.1.1\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.0\"), is(true));\n+ assertThat(rules.isAllowed(\"10.1.1.2\"), is(true));\n+ }\n+\n+ @Test\n+ void allowAndDenySingleIps() {\n+ NetworkAddressRules rules =\n+ NetworkAddressRules.builder()\n+ .deny(\"10.1.1.1\")\n+ .allow(\"10.1.1.3\")\n+ .build();\n+\n+ assertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.1\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.2\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.3\"), is(true));\n+ assertThat(rules.isAllowed(\"10.1.1.4\"), is(false));\n+ }\n+\n+ @Test\n+ void allowRangeAndDenySingleIp() {\n+ NetworkAddressRules rules =\n+ NetworkAddressRules.builder()\n+ .allow(\"10.1.1.1-10.1.1.3\")\n+ .deny(\"10.1.1.2\")\n+ .build();\n+\n+ assertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.1\"), is(true));\n+ assertThat(rules.isAllowed(\"10.1.1.2\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.3\"), is(true));\n+ assertThat(rules.isAllowed(\"10.1.1.4\"), is(false));\n+ }\n+\n+ @Test\n+ void denyRangeAndAllowSingleIp() {\n+ NetworkAddressRules rules =\n+ NetworkAddressRules.builder()\n+ .deny(\"10.1.1.1-10.1.1.3\")\n+ .allow(\"10.1.1.2\")\n+ .build();\n+\n+ assertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.1\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.2\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.3\"), is(false));\n+ assertThat(rules.isAllowed(\"10.1.1.4\"), is(false));\n+ }\n}\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Added some extra NetworkAddressRules test cases |
686,936 | 02.11.2022 08:47:21 | 0 | 91353df604c31ce603162173c30c2e1066a023d2 | Fixed some formatting in NetworkAddressRulesTest | [
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/common/NetworkAddressRulesTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/common/NetworkAddressRulesTest.java",
"diff": "@@ -41,10 +41,7 @@ public class NetworkAddressRulesTest {\n@Test\nvoid onlyAllowSingleIp() {\n- NetworkAddressRules rules =\n- NetworkAddressRules.builder()\n- .allow(\"10.1.1.1\")\n- .build();\n+ NetworkAddressRules rules = NetworkAddressRules.builder().allow(\"10.1.1.1\").build();\nassertThat(rules.isAllowed(\"10.1.1.1\"), is(true));\nassertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\n@@ -53,10 +50,7 @@ public class NetworkAddressRulesTest {\n@Test\nvoid onlyDenySingleIp() {\n- NetworkAddressRules rules =\n- NetworkAddressRules.builder()\n- .deny(\"10.1.1.1\")\n- .build();\n+ NetworkAddressRules rules = NetworkAddressRules.builder().deny(\"10.1.1.1\").build();\nassertThat(rules.isAllowed(\"10.1.1.1\"), is(false));\nassertThat(rules.isAllowed(\"10.1.1.0\"), is(true));\n@@ -66,10 +60,7 @@ public class NetworkAddressRulesTest {\n@Test\nvoid allowAndDenySingleIps() {\nNetworkAddressRules rules =\n- NetworkAddressRules.builder()\n- .deny(\"10.1.1.1\")\n- .allow(\"10.1.1.3\")\n- .build();\n+ NetworkAddressRules.builder().deny(\"10.1.1.1\").allow(\"10.1.1.3\").build();\nassertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\nassertThat(rules.isAllowed(\"10.1.1.1\"), is(false));\n@@ -81,10 +72,7 @@ public class NetworkAddressRulesTest {\n@Test\nvoid allowRangeAndDenySingleIp() {\nNetworkAddressRules rules =\n- NetworkAddressRules.builder()\n- .allow(\"10.1.1.1-10.1.1.3\")\n- .deny(\"10.1.1.2\")\n- .build();\n+ NetworkAddressRules.builder().allow(\"10.1.1.1-10.1.1.3\").deny(\"10.1.1.2\").build();\nassertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\nassertThat(rules.isAllowed(\"10.1.1.1\"), is(true));\n@@ -96,10 +84,7 @@ public class NetworkAddressRulesTest {\n@Test\nvoid denyRangeAndAllowSingleIp() {\nNetworkAddressRules rules =\n- NetworkAddressRules.builder()\n- .deny(\"10.1.1.1-10.1.1.3\")\n- .allow(\"10.1.1.2\")\n- .build();\n+ NetworkAddressRules.builder().deny(\"10.1.1.1-10.1.1.3\").allow(\"10.1.1.2\").build();\nassertThat(rules.isAllowed(\"10.1.1.0\"), is(false));\nassertThat(rules.isAllowed(\"10.1.1.1\"), is(false));\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fixed some formatting in NetworkAddressRulesTest |
686,936 | 02.11.2022 20:18:41 | 0 | 0c008cd45f100893540db128aee546c6694bc3a1 | Updated OpenAPI JSON file | [
{
"change_type": "MODIFY",
"old_path": "src/main/resources/swagger/wiremock-admin-api.json",
"new_path": "src/main/resources/swagger/wiremock-admin-api.json",
"diff": "\"openapi\": \"3.0.0\",\n\"info\": {\n\"title\": \"WireMock\",\n- \"version\": \"2.33.2\"\n+ \"version\": \"2.35.0\"\n},\n\"externalDocs\": {\n\"description\": \"WireMock user documentation\",\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Updated OpenAPI JSON file |
686,981 | 10.12.2022 15:50:28 | 0 | 2a469ec836a4b77eed2cb79ae96eb329423e5fb2 | Fix NullPointerException
Just because the old mapping is in a scenario doesn't mean its
replacement is. | [
{
"change_type": "MODIFY",
"old_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenarios.java",
"new_path": "src/main/java/com/github/tomakehurst/wiremock/stubbing/Scenarios.java",
"diff": "@@ -48,7 +48,7 @@ public class Scenarios {\npublic void onStubMappingUpdated(StubMapping oldMapping, StubMapping newMapping) {\nif (oldMapping.isInScenario()\n- && !newMapping.getScenarioName().equals(oldMapping.getScenarioName())) {\n+ && !oldMapping.getScenarioName().equals(newMapping.getScenarioName())) {\nScenario scenarioForOldMapping =\nscenarioMap.get(oldMapping.getScenarioName()).withoutStubMapping(oldMapping);\n"
},
{
"change_type": "MODIFY",
"old_path": "src/test/java/com/github/tomakehurst/wiremock/stubbing/ScenariosTest.java",
"new_path": "src/test/java/com/github/tomakehurst/wiremock/stubbing/ScenariosTest.java",
"diff": "/*\n- * Copyright (C) 2017-2021 Thomas Akehurst\n+ * Copyright (C) 2017-2022 Thomas Akehurst\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n@@ -163,6 +163,26 @@ public class ScenariosTest {\nassertThat(scenarios.getByName(\"one\"), nullValue());\n}\n+ @Test\n+ public void stubMappingCanStopBeingInScenario() {\n+ StubMapping oldMapping =\n+ get(\"/scenarios/1\")\n+ .inScenario(\"one\")\n+ .whenScenarioStateIs(STARTED)\n+ .willSetStateTo(\"step_2\")\n+ .willReturn(ok())\n+ .build();\n+ scenarios.onStubMappingAdded(oldMapping);\n+\n+ assertThat(scenarios.getByName(\"one\"), notNullValue());\n+\n+ StubMapping newMapping = get(\"/scenarios/1\").willReturn(ok()).build();\n+\n+ scenarios.onStubMappingUpdated(oldMapping, newMapping);\n+\n+ assertThat(scenarios.getByName(\"one\"), nullValue());\n+ }\n+\n@Test\npublic void modifiesScenarioStateWhenStubServed() {\nStubMapping mapping1 =\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Fix NullPointerException
Just because the old mapping is in a scenario doesn't mean its
replacement is. |
686,936 | 30.12.2022 15:13:13 | 0 | 87c5d29ae3c7780c11143e15af9f92e309d4cf05 | Bumped version to 3.0.0-beta-1 and Java version to 11 | [
{
"change_type": "MODIFY",
"old_path": "build.gradle",
"new_path": "build.gradle",
"diff": "@@ -201,10 +201,10 @@ allprojects {\nmavenCentral()\n}\n- version = '2.35.0'\n+ version = '3.0.0-beta-1'\n- sourceCompatibility = 1.8\n- targetCompatibility = 1.8\n+ sourceCompatibility = 1.11\n+ targetCompatibility = 1.11\ncompileJava {\noptions.encoding = 'UTF-8'\n@@ -262,7 +262,7 @@ task testJar(type: Jar, dependsOn: testClasses) {\nfinal DOCS_DIR = project(':').rootDir.getAbsolutePath() + '/docs-v2'\njar {\n- archiveBaseName.set('wiremock-jre8')\n+ archiveBaseName.set('wiremock')\nmanifest {\nattributes(\"Main-Class\": \"com.github.tomakehurst.wiremock.standalone.WireMockServerRunner\")\nattributes(\"Add-Exports\": \"java.base/sun.security.x509\")\n@@ -274,7 +274,7 @@ shadowJar {\nproject.configurations.runtimeClasspath,\nproject.configurations.standaloneOnly\n]\n- archiveBaseName.set('wiremock-jre8-standalone')\n+ archiveBaseName.set('wiremock-standalone')\nrelocate \"org.mortbay\", 'wiremock.org.mortbay'\nrelocate \"org.eclipse\", 'wiremock.org.eclipse'\n@@ -463,6 +463,13 @@ task 'bump-minor-version' {\n}\n}\n+tasks.withType(JavaCompile) {\n+ options.compilerArgs.addAll([\n+ \"--add-exports\",\n+ \"java.base/sun.security.x509=ALL-UNNAMED\"\n+ ])\n+}\n+\nint getMajorVersion() {\nInteger.valueOf(project.version.substring(0, project.version.indexOf('.')))\n}\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/resources/swagger/wiremock-admin-api.json",
"new_path": "src/main/resources/swagger/wiremock-admin-api.json",
"diff": "\"openapi\": \"3.0.0\",\n\"info\": {\n\"title\": \"WireMock\",\n- \"version\": \"2.35.0\"\n+ \"version\": \"3.0.0-beta-1\"\n},\n\"externalDocs\": {\n\"description\": \"WireMock user documentation\",\n"
},
{
"change_type": "MODIFY",
"old_path": "src/main/resources/swagger/wiremock-admin-api.yaml",
"new_path": "src/main/resources/swagger/wiremock-admin-api.yaml",
"diff": "@@ -2,7 +2,7 @@ openapi: 3.0.0\ninfo:\ntitle: WireMock\n- version: 2.35.0\n+ version: 3.0.0-beta-1\nexternalDocs:\ndescription: WireMock user documentation\n"
},
{
"change_type": "MODIFY",
"old_path": "ui/package-lock.json",
"new_path": "ui/package-lock.json",
"diff": "{\n\"name\": \"wiremock-ui-resources\",\n- \"version\": \"2.33.2\",\n+ \"version\": \"3.0.0-beta-1\",\n\"lockfileVersion\": 1,\n\"requires\": true,\n\"dependencies\": {\n"
},
{
"change_type": "MODIFY",
"old_path": "ui/package.json",
"new_path": "ui/package.json",
"diff": "{\n\"name\": \"wiremock-ui-resources\",\n- \"version\": \"2.35.0\",\n+ \"version\": \"3.0.0-beta-1\",\n\"description\": \"WireMock UI resources processor\",\n\"engines\": {\n\"node\": \">= 0.10.0\"\n"
}
]
| Java | Apache License 2.0 | tomakehurst/wiremock | Bumped version to 3.0.0-beta-1 and Java version to 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.