From 0c10b6e1c82bcc6d5f4d596d1ac7696f87739ca7 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Thu, 18 Apr 2024 11:20:45 +1000 Subject: [PATCH] fix: Add tests for generating URLs with null or empty query parameter values #1788 --- .../spring/junit5/WebFluxTargetSpec.groovy | 14 ++++++++++++++ .../spring/WebFluxProviderVerifierSpec.groovy | 12 ++++++++++++ .../spring/spring6/MockMvcTestTargetSpec.groovy | 13 +++++++++++++ .../groovysupport/ProviderClientSpec.groovy | 12 ++++++++++++ 4 files changed, 51 insertions(+) diff --git a/provider/junit5spring/src/test/groovy/au/com/dius/pact/provider/spring/junit5/WebFluxTargetSpec.groovy b/provider/junit5spring/src/test/groovy/au/com/dius/pact/provider/spring/junit5/WebFluxTargetSpec.groovy index 819494a4c0..bef1cfa9f0 100644 --- a/provider/junit5spring/src/test/groovy/au/com/dius/pact/provider/spring/junit5/WebFluxTargetSpec.groovy +++ b/provider/junit5spring/src/test/groovy/au/com/dius/pact/provider/spring/junit5/WebFluxTargetSpec.groovy @@ -13,6 +13,7 @@ import org.springframework.web.reactive.function.server.RequestPredicates import org.springframework.web.reactive.function.server.RouterFunction import org.springframework.web.reactive.function.server.RouterFunctions import org.springframework.web.reactive.function.server.ServerResponse +import spock.lang.Issue import spock.lang.Specification import java.nio.charset.StandardCharsets @@ -98,4 +99,17 @@ class WebFluxTargetSpec extends Specification { new V4Interaction.SynchronousMessages('test') | false new V4Interaction.SynchronousHttp('test') | true } + + @Issue('#1788') + def 'query parameters with null and empty values'() { + given: + def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]]) + WebFluxTarget webFluxTarget = new WebFluxTarget(routerFunction) + + when: + def request = webFluxTarget.requestUriString(pactRequest) + + then: + request == '/?A=&A=&B&B' + } } diff --git a/provider/spring/src/test/groovy/au/com/dius/pact/provider/spring/WebFluxProviderVerifierSpec.groovy b/provider/spring/src/test/groovy/au/com/dius/pact/provider/spring/WebFluxProviderVerifierSpec.groovy index 10779852c9..865bafbf4e 100644 --- a/provider/spring/src/test/groovy/au/com/dius/pact/provider/spring/WebFluxProviderVerifierSpec.groovy +++ b/provider/spring/src/test/groovy/au/com/dius/pact/provider/spring/WebFluxProviderVerifierSpec.groovy @@ -11,6 +11,7 @@ import org.springframework.web.reactive.function.server.RouterFunctions import org.springframework.web.reactive.function.server.ServerRequest import org.springframework.web.reactive.function.server.ServerResponse import reactor.core.publisher.Mono +import spock.lang.Issue import spock.lang.Specification import static org.springframework.web.reactive.function.server.RequestPredicates.GET @@ -96,4 +97,15 @@ class WebFluxProviderVerifierSpec extends Specification { new String(bytes) } + @Issue('#1788') + def 'query parameters with null and empty values'() { + given: + def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]]) + + when: + def request = verifier.requestUriString(pactRequest) + + then: + request == '/?A=&A=&B&B' + } } diff --git a/provider/spring6/src/test/groovy/au/com/dius/pact/provider/spring/spring6/MockMvcTestTargetSpec.groovy b/provider/spring6/src/test/groovy/au/com/dius/pact/provider/spring/spring6/MockMvcTestTargetSpec.groovy index 20d5a82088..5ea99f3ac6 100644 --- a/provider/spring6/src/test/groovy/au/com/dius/pact/provider/spring/spring6/MockMvcTestTargetSpec.groovy +++ b/provider/spring6/src/test/groovy/au/com/dius/pact/provider/spring/spring6/MockMvcTestTargetSpec.groovy @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestController +import spock.lang.Issue import spock.lang.Specification import java.nio.charset.StandardCharsets @@ -123,6 +124,18 @@ class MockMvcTestTargetSpec extends Specification { responseMap.body.valueAsString() == 'Hello 1234' } + @Issue('#1788') + def 'query parameters with null and empty values'() { + given: + def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]]) + + when: + def request = mockMvcTestTarget.requestUriString(pactRequest) + + then: + request.query == 'A=&A=&B&B' + } + @RestController static class TestResource { @GetMapping(value = '/data', produces = 'application/json') diff --git a/provider/src/test/groovy/au/com/dius/pact/provider/groovysupport/ProviderClientSpec.groovy b/provider/src/test/groovy/au/com/dius/pact/provider/groovysupport/ProviderClientSpec.groovy index 9e7b21b3dc..9a821fe311 100644 --- a/provider/src/test/groovy/au/com/dius/pact/provider/groovysupport/ProviderClientSpec.groovy +++ b/provider/src/test/groovy/au/com/dius/pact/provider/groovysupport/ProviderClientSpec.groovy @@ -789,4 +789,16 @@ class ProviderClientSpec extends Specification { entity.content.text == '{"ä": "äbc"}' entity.contentType == 'application/json; charset=UTF-8' } + + @Issue('#1788') + def 'query parameters with null and empty values'() { + given: + def pactRequest = new Request('GET', '/', ['A': ['', ''], 'B': [null, null]]) + + when: + def request = client.newRequest(pactRequest) + + then: + request.uri.query == 'A=&A=&B&B' + } }