pact-jvm icon indicating copy to clipboard operation
pact-jvm copied to clipboard

BUG: semicolon is not handled correctly in headers by au.com.dius.pact.consumer - junit5 version:4.6.3

Open vasile21 opened this issue 8 months ago • 1 comments

Hi I am migrating to latest pact-consumer library:

<dependency>
   <groupId>au.com.dius.pact.consumer</groupId>
   <artifactId>junit5</artifactId>
   <version>4.6.3</version>
</dependency>

My PactDsl creation looks like:

return pactDslWithProvider
        .given("myProviderState")
        .uponReceiving("interactionDescription")
        .path("/path/resource/blabla")
        .method("POST")
        .headers(setRequestHeaders())
        .body("{\"anyField\":\"anyResource\"}")
        .willRespondWith()
        .status(400)
        .headers(setResponseHeaders())
        .body(matcherRules(getResponseBody()))
        .toPact();
private Map<String, String> setResponseHeaders(){
Map<String, String> headers  = new HashMap<>();
    headers.put(
        "strict-transport-security, "max-age=3600; includeSubDomains; reload");
    headers.put("Content-Security-Policy", "default-src: 'none'; frame-ancestors 'none'; base-uri 'self'");
//other headers...
}

In the older version of pact headers that contained semicolon were handled correctly in pact file:

 "response": {
        "status": 400,
        "headers": {
          "Content-Security-Policy": "default-src: 'none'; frame-ancestors 'none'; base-uri 'self'",
          "strict-transport-security": "max-age=3600; includeSubDomains; reload",
        },
        "body": {
         //....

Pact file after the upgrade contains invalid values for headers as can be seen below:

 "response": {
        "status": 400,
        "headers": {
          "Content-Security-Policy": "default-src: 'none'; frame-ancestors 'none'=\"\"; base-uri 'self'=\"\"",
          "strict-transport-security":  "max-age=3600; includeSubDomains=\"\"; reload=\"\"",
        },
        "body": {
         //....

Pact consumer logs:

14:48:34.250 [HTTP-Dispatcher] DEBUG au.com.dius.pact.consumer.BaseJdkMockServer$Companion - Generating response: 	status: 400
	headers: {Referrer-Policy=[no-referrer], Content-Security-Policy=[default-src: 'none'; frame-ancestors 'none'; base-uri 'self'], strict-transport-security=[max-age=3600; includeSubDomains; preload]}
	matchers: MatchingRules(rules={body=MatchingRuleCategory(name=body, matchingRules={$.anyField=MatchingRuleGroup(rules=[RegexMatcher(regex=anyValue, example=null)], ruleLogic=AND, cascaded=false), $.otherField=MatchingRuleGroup(rules=[RegexMatcher(regex=Constraint validation.+, example=null)], ruleLogic=AND, cascaded=false), $.lastField.suggestedStatus=MatchingRuleGroup(rules=[RegexMatcher(regex=QWERTY, example=null)], ruleLogic=AND, cascaded=false)}), status=MatchingRuleCategory(name=status, matchingRules={}), header=MatchingRuleCategory(name=header, matchingRules={})})
	generators: Generators(categories={})
	body: PRESENT({"anyField: "anyValue", "otherField":"otherValue", "lastField":"QWERTY"})
14:48:34.252 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
14:48:34.252 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "strict-transport-security: max-age=3600; includeSubDomains; preload[\r][\n]"
14:48:34.252 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Referrer-Policy: no-referrer[\r][\n]"
14:48:34.252 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Security-Policy: default-src: 'none'; frame-ancestors 'none'; base-uri 'self'[\r][\n]"
14:48:34.252 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
14:48:34.252 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "{"anyField: "anyValue", "otherField":"otherValue", "lastField":"QWERTY"}"
14:48:34.253 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 400 Bad Request
14:48:34.253 [main] DEBUG org.apache.http.headers - http-outgoing-0 << strict-transport-security: max-age=31536000; includeSubDomains; preload
14:48:34.253 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Referrer-Policy: no-referrer
14:48:34.253 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Security-Policy: default-src: 'none'; frame-ancestors 'none'; base-uri 'self'

Could you let me know if this will be fixed or if there is any workaround for this issue?

vasile21 avatar Nov 01 '23 07:11 vasile21