Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vasile21 opened this issue Nov 1, 2023 · 1 comment
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@vasile21
Copy link

vasile21 commented Nov 1, 2023

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 vasile21 changed the title BUG: semicolon is not handled correctly in headers by au.com.dius.pact.consumer - junit5 4.6.3 BUG: semicolon is not handled correctly in headers by au.com.dius.pact.consumer - junit5 version:4.6.3 Nov 1, 2023
@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Nov 14, 2023
@rholshausen
Copy link
Contributor

I can't replicate this. If I run the given code against the master version of Pact-JVM, I get:

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

and the logs from the test:

http-outgoing-1 << HTTP/1.1 200 OK
http-outgoing-1 << strict-transport-security: max-age=3600; includeSubDomains; reload
http-outgoing-1 << Date: Tue, 14 Nov 2023 22:49:25 GMT
http-outgoing-1 << Transfer-encoding: chunked
http-outgoing-1 << Content-Security-Policy: default-src: 'none'; frame-ancestors 'none'; base-uri 'self'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants