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

Using fromProviderState should not allow mock server to match any request #1088

Open
4 of 5 tasks
tienvx opened this issue May 2, 2023 · 7 comments · May be fixed by #1223
Open
4 of 5 tasks

Using fromProviderState should not allow mock server to match any request #1088

tienvx opened this issue May 2, 2023 · 7 comments · May be fixed by #1223
Labels
bug Indicates an unexpected problem or unintended behavior upstream Indicates that an issue relates to an upstream problem (such as in pact-reference)

Comments

@tienvx
Copy link

tienvx commented May 2, 2023

When I add interaction like this:

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 12.1.0
  • Provider Pact library: NA
  • Node Version: v18.17.1

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

[21:12:21.618] INFO (27131): 0.4.7: pact native library successfully found, and the correct version
2023-08-11T14:12:21.624175Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:matcher:type, will configure a matcher
2023-08-11T14:12:21.624206Z DEBUG ThreadId(01) pact_ffi::mock_server::handles: detected pact:generator:type, will configure a generators
2023-08-11T14:12:21.624683Z DEBUG ThreadId(01) pact_plugin_driver::catalogue_manager: Updated catalogue entries:
core/transport/http
core/transport/https
2023-08-11T14:12:21.624703Z 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-08-11T14:12:21.624722Z 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-08-11T14:12:21.624852Z DEBUG ThreadId(01) pact_mock_server::mock_server: Started mock server on 127.0.0.1:36287
*
2023-08-11T14:12:21.641024Z DEBUG tokio-runtime-worker hyper::proto::h1::io: parsed 7 headers
2023-08-11T14:12:21.641032Z DEBUG tokio-runtime-worker hyper::proto::h1::conn: incoming body is empty
2023-08-11T14:12:21.641047Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Creating pact request from hyper request
2023-08-11T14:12:21.641051Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Extracting query from uri /any
2023-08-11T14:12:21.641067Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request GET /any
2023-08-11T14:12:21.641071Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: 
      ----------------------------------------------------------------------------------------
       method: GET
       path: /any
       query: None
       headers: Some({"host": ["127.0.0.1:36287"], "accept": ["*/*"], "accept-language": ["*"], "sec-fetch-mode": ["cors"], "accept-encoding": ["gzip", "deflate"], "connection": ["keep-alive"], "user-agent": ["undici"]})
       body: Empty
      ----------------------------------------------------------------------------------------
      
2023-08-11T14:12:21.641104Z  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-08-11T14:12:21.641108Z DEBUG tokio-runtime-worker pact_matching:      body: ''
2023-08-11T14:12:21.641109Z 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-08-11T14:12:21.641116Z DEBUG tokio-runtime-worker pact_matching:      generators: Generators { categories: {PATH: {DocPath { path_tokens: [Root], expr: "$" }: ProviderStateGenerator("${iri}", None)}} }
2023-08-11T14:12:21.641131Z 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-08-11T14:12:21.641139Z DEBUG tokio-runtime-worker pact_matching: expected content type = '*/*', actual content type = '*/*'
2023-08-11T14:12:21.641173Z DEBUG tokio-runtime-worker pact_matching: content type header matcher = 'RuleList { rules: [], rule_logic: And, cascaded: false }'
2023-08-11T14:12:21.641178Z DEBUG tokio-runtime-worker pact_matching: --> Mismatches: []
2023-08-11T14:12:21.641197Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Test context = {"mockServer": Object {"port": Number(36287), "url": String("http://127.0.0.1:36287")}}
2023-08-11T14:12:21.641204Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response
2023-08-11T14:12:21.641206Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: 
          ----------------------------------------------------------------------------------------
           status: 200
           headers: Some({"Content-Type": ["application/json"]})
           body: Present(45 bytes, application/json) '{"id":"14f6626f-c51e-4311-ac52-182c8f2a7634"}'
          ----------------------------------------------------------------------------------------
          
2023-08-11T14:12:21.641243Z DEBUG tokio-runtime-worker hyper::proto::h1::io: flushed 397 bytes
2023-08-11T14:12:21.646194Z 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-08-11T14:12:21.646203Z DEBUG ThreadId(01) pact_mock_server::server_manager: Shutting down mock server with ID 804f0cc0-02ce-47b5-ac0f-8c84f595b26c - MockServerMetrics { requests: 1, requests_by_path: {"/any": 1} }
2023-08-11T14:12:21.646209Z DEBUG ThreadId(01) pact_mock_server::mock_server: Mock server 804f0cc0-02ce-47b5-ac0f-8c84f595b26c shutdown - MockServerMetrics { requests: 1, requests_by_path: {"/any": 1} }
@tienvx tienvx added the bug Indicates an unexpected problem or unintended behavior label May 2, 2023
@github-actions
Copy link

👋 Hi! The 'smartbear-supported' label has just been added to this issue, which will create an internal tracking ticket in PactFlow's Jira (PACT-1137). We will use this to prioritise and assign a team member to this task. All activity will be public on this ticket. For now, sit tight and we'll update this ticket once we have more information on the next steps.

See our documentation for more information.

@mefellows
Copy link
Member

Thanks for this report Tien. Might be a tricky one actually, let's see how we go!

@tienvx
Copy link
Author

tienvx commented Aug 11, 2023

Updated issue's description with latest version of pact-js. The log is now cleaner. Also added explanation to demo project.

@SiimMardus
Copy link

This is still relevant, having the same issue. Posted another question to Slack, as it doesn't show messages from more than 90 days ago.

@mefellows mefellows added the upstream Indicates that an issue relates to an upstream problem (such as in pact-reference) label Jun 20, 2024
@mefellows
Copy link
Member

I realised this wasn't linked to an upstream issue, I'll re-raise in the core where I believe this belongs.

@mefellows
Copy link
Member

Not an upstream issue, the bug is because it's a type matcher and a generator - it should only be a generator. This will require some typing updates.

Source of issue was introduced here: 5fdf7eb#diff-884c1c7cbdaafa772a7a428e0ca83ce1fc58f03972dfa0fabcb89106d6ac35f5R409.

@mefellows mefellows removed the upstream Indicates that an issue relates to an upstream problem (such as in pact-reference) label Jun 21, 2024
@mefellows mefellows added the upstream Indicates that an issue relates to an upstream problem (such as in pact-reference) label Jun 21, 2024
@mefellows
Copy link
Member

New (possible) upstream issue: pact-foundation/pact-reference#448

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 upstream Indicates that an issue relates to an upstream problem (such as in pact-reference)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants