<#1088 Using fromProviderState should not allow mo...
# pact-js-development
g
#1088 Using fromProviderState should not allow mock server to match any request Issue created by tienvx When I add interaction like this:
Copy code
pact.addInteraction({
        states: [{ description: 'A user' }],
        uponReceiving: 'get one user',
        withRequest: {
            method: 'GET',
            path: fromProviderState('${iri}', '/api/users/14f6626f-c51e-4311-ac52-182c8f2a7634')
        },
        willRespondWith: {
            status: 200,
            body: {
                id: '14f6626f-c51e-4311-ac52-182c8f2a7634'
            },
        },
    });
I expect mock server should return 404 for this request
GET /any
, but it return 200 with body
{"id": "14f6626f-c51e-4311-ac52-182c8f2a7634"}
For more development information, please take a look at this Slack's discussion https://pact-foundation.slack.com/archives/C9VBGLUM9/p1683003726545669 Software versions Please provide at least OS and version of pact-js • OS: Linux Mint 21.1 • Consumer Pact library: Pact JS 11.0.2 • Provider Pact library: NA • Node Version:
v18.16.0
Issue Checklist Please confirm the following: ☑︎ I have upgraded to the latest ☐ I have the read the FAQs in the Readme <--- Where is the FAQs, I can't find ☑︎ I have triple checked, that there are no unhandled promises in my code and have read the section on intermittent test failures ☑︎ I have set my log level to debug and attached a log file showing the complete request/response cycle ☑︎ For bonus points and virtual high fives, I have created a reproduceable git repository (see below) to illustrate the problem Expected behaviour The request
GET /any
should return 404, and mock server should report
the request GET /api/users/14f6626f-c51e-4311-ac52-182c8f2a7634 is expected but not received
. Actual behaviour The request
GET /any
return 200 with json body that didn't belong to it. Steps to reproduce Here is the demo project https://github.com/tienvx/test-from-provider-state-generator Relevant log files
Copy code
2023-05-02T06:32:57.458644Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure a matcher
2023-05-02T06:32:57.458691Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:generator:type, will configure a generators
2023-05-02T06:32:57.459161Z DEBUG ThreadId(01) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/transport/http
core/transport/https
2023-05-02T06:32:57.459183Z DEBUG ThreadId(01) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/content-generator/binary
core/content-generator/json
core/content-matcher/json
core/content-matcher/multipart-form-data
core/content-matcher/text
core/content-matcher/xml
2023-05-02T06:32:57.459201Z DEBUG ThreadId(01) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/matcher/v1-equality
core/matcher/v2-max-type
core/matcher/v2-min-type
core/matcher/v2-minmax-type
core/matcher/v2-regex
core/matcher/v2-type
core/matcher/v3-content-type
core/matcher/v3-date
core/matcher/v3-datetime
core/matcher/v3-decimal-type
core/matcher/v3-includes
core/matcher/v3-integer-type
core/matcher/v3-null
core/matcher/v3-number-type
core/matcher/v3-time
core/matcher/v4-array-contains
core/matcher/v4-equals-ignore-order
core/matcher/v4-max-equals-ignore-order
core/matcher/v4-min-equals-ignore-order
core/matcher/v4-minmax-equals-ignore-order
core/matcher/v4-not-empty
core/matcher/v4-semver
2023-05-02T06:32:57.459330Z DEBUG ThreadId(01) pact_mock_server::mock_server: Started mock server on 127.0.0.1:41507
2023-05-02T06:32:57.469704Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers
2023-05-02T06:32:57.469711Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is empty
2023-05-02T06:32:57.469719Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Creating pact request from hyper request
2023-05-02T06:32:57.469722Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Extracting query from uri /any
2023-05-02T06:32:57.469739Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request HTTP Request ( method: GET, path: /any, query: None, headers: Some({"accept-encoding": ["gzip", "deflate"], "sec-fetch-mode": ["cors"], "accept-language": ["*"], "host": ["127.0.0.1:41507"], "connection": ["keep-alive"], "accept": ["*/*"], "user-agent": ["undici"]}), body: Empty )
2023-05-02T06:32:57.469770Z  INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /api/users/14f6626f-c51e-4311-ac52-182c8f2a7634, query: None, headers: None, body: Missing )
2023-05-02T06:32:57.469772Z DEBUG tokio-runtime-worker pact_matching:      body: ''
2023-05-02T06:32:57.469774Z DEBUG tokio-runtime-worker pact_matching:      matching_rules: MatchingRules { rules: {PATH: MatchingRuleCategory { name: PATH, rules: {DocPath { path_tokens: [Root], expr: "$" }: RuleList { rules: [Type], rule_logic: And, cascaded: false }} }} }
2023-05-02T06:32:57.469779Z DEBUG tokio-runtime-worker pact_matching:      generators: Generators { categories: {PATH: {DocPath { path_tokens: [Root], expr: "$" }: ProviderStateGenerator("${iri}", None)}} }
2023-05-02T06:32:57.469790Z DEBUG tokio-runtime-worker pact_matching::matchers: String -> String: comparing '/api/users/14f6626f-c51e-4311-ac52-182c8f2a7634' to '/any' ==> true cascaded=false matcher=Type
2023-05-02T06:32:57.469798Z DEBUG tokio-runtime-worker pact_matching: expected content type = '*/*', actual content type = '*/*'
2023-05-02T06:32:57.469834Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }'
2023-05-02T06:32:57.469839Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: []
2023-05-02T06:32:57.469855Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Test context = {"mockServer": Object {"href": String("<http://127.0.0.1:41507>"), "port": Number(41507)}}
2023-05-02T06:32:57.469861Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(45 bytes, application/json) )
2023-05-02T06:32:57.469865Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server:      body: '{"id":"14f6626f-c51e-4311-ac52-182c8f2a7634"}'
2023-05-02T06:32:57.469892Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 397 bytes
2023-05-02T06:32:57.474816Z DEBUG ThreadId(01) pact_matching::metrics: Could not get the tokio runtime, will not send metrics - there is no reactor running, must be called from the context of a Tokio 1.x runtime
2023-05-02T06:32:57.474825Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID d6d59524-a61e-479e-85f3-3a9051691611 - MockServerMetrics { requests: 1 }
2023-05-02T06:32:57.474831Z DEBUG ThreadId(01) pact_mock_server::mock_server: Mock server d6d59524-a61e-479e-85f3-3a9051691611 shutdown - MockServerMetrics { requests: 1 }
2023-05-02T06:32:57.474838Z DEBUG tokio-runtime-worker hyper::server::shutdown: signal received, starting graceful shutdown
pact-foundation/pact-js