pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.08k stars 479 forks source link

Query keys with angled brackets treated as arrays #1766

Closed milda-a closed 6 months ago

milda-a commented 9 months ago

Java 21, dependency version 4.6.5+

from Slack https://pact-foundation.slack.com/archives/C9UN99H24/p1707392044235519

We found an odd issue with the pact jvm consumer dependency update, from version 4.6.5 and up, specifically with query matchers. One provider we use has queries that have square brackets [] in them, i.e. principle_identifier[account_id] etc. When running pact tests to generate a contract, running individual test classes runs fine, but as soon as another test class is added to run together, the second class throws errors, seemingly treating the brackets in the query key as an array:

[ERROR] GetAuthorizationContractTest -- Time elapsed: 0.919 s <<< ERROR!
au.com.dius.pact.core.model.InvalidPathExpression: Indexes can only consist of numbers or a "*", found "a" instead in path expression "$.query.principal_identifier[account_id]" at index 29
    at au.com.dius.pact.core.model.PathExpressionsKt.bracketPath(PathExpressions.kt:141)
    at au.com.dius.pact.core.model.PathExpressionsKt.pathExp(PathExpressions.kt:165)
    at au.com.dius.pact.core.model.PathExpressionsKt.parsePath(PathExpressions.kt:181)
    at au.com.dius.pact.core.model.matchingrules.MatchingRulesImpl.fromV2Json(MatchingRulesImpl.kt:34)
    at au.com.dius.pact.core.model.matchingrules.MatchingRulesImpl$Companion.fromJson(MatchingRulesImpl.kt:104)
    at au.com.dius.pact.core.model.Request$Companion.fromJson(Request.kt:170)
    at au.com.dius.pact.core.model.DefaultPactReader.extractRequest(PactReader.kt:327)
    at au.com.dius.pact.core.model.DefaultPactReader$loadV2Pact$interactions$1.invoke(PactReader.kt:283)
    at au.com.dius.pact.core.model.DefaultPactReader$loadV2Pact$interactions$1.invoke(PactReader.kt:282)
    at au.com.dius.pact.core.support.json.JsonValueKt.map(JsonValue.kt:338)
    at au.com.dius.pact.core.model.DefaultPactReader.loadV2Pact(PactReader.kt:282)
    at au.com.dius.pact.core.model.DefaultPactReader.pactFromJson(PactReader.kt:220)
    at au.com.dius.pact.core.model.DefaultPactWriter.writePact(PactWriter.kt:92)
    at au.com.dius.pact.core.model.BasePact.write(BasePact.kt:24)
    at au.com.dius.pact.consumer.junit5.PactConsumerTestExt.afterAll(PactConsumerTestExt.kt:709)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

Again, both classes run individually pass, the first class in the run list passes, even if they're swapped, and the second one throws this error. Downgrading to v4.6.4 works for now.

rholshausen commented 9 months ago

Can you provide the tests that cause this?

github-actions[bot] commented 9 months ago

🤖 Great news! We've labeled this issue as smartbear-supported and created a tracking ticket in PactFlow's Jira (PACT-1832). We'll keep work public and post updates here. Meanwhile, feel free to check out our docs. Thanks for your patience!

rholshausen commented 8 months ago

4.6.7 released with this fix