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

Provider Verification - parse header error coming from pact-ffi #447

Open
hborham opened this issue Jul 25, 2024 · 2 comments
Open

Provider Verification - parse header error coming from pact-ffi #447

hborham opened this issue Jul 25, 2024 · 2 comments

Comments

@hborham
Copy link
Contributor

hborham commented Jul 25, 2024

Software versions

  • OS: e.g. linux (al2023)
  • Consumer Pact library: e.g. Pact-js 11.0.2
  • Provider Pact library: e.g. Pact go v2.0.3
  • Golang Version: 1.21
  • Golang environment: Provide output of go env

Expected behaviour

Able to verify the pact header and value.

Actual behaviour

Fails to verify the pact

Request Failed - Invalid header name: 'Failed to parse header value: redacted-encoded-jwt-token

Enabled PACT_LOG_LEVEL=TRACE and this additional output seems relevant

2024-02-08T16:08:33.563649Z ERROR ThreadId(04) pact_ffi::mock_server::handles: Failed to parse the value: expected value at line 1 column 1
2024-02-08T16:08:33.563710Z ERROR ThreadId(04) pact_ffi::mock_server::handles: Failed to parse the value: expected value at line 1 column 1

Steps to reproduce

First noticed in v2.0.3 and pinned our build to v2.0.2

[Container] 2024/02/08 14:00:23.228131 Running command go install github.com/pact-foundation/pact-go/v2@latest
go: downloading github.com/pact-foundation/pact-go/v2 v2.0.3
...truncate
[Container] 2024/02/08 14:00:47.625763 Running command pact-go -l DEBUG install
2024/02/08 14:00:47 [INFO] package libpact_ffi not found
2024/02/08 14:00:47 [INFO] downloading library from https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v0.4.15/libpact_ffi-linux-x86_64.so.gz to /usr/local/lib/libpact_ffi.so&{}
2024/02/08 14:00:48 [DEBUG] obtaining hash for file /usr/local/lib/libpact_ffi.so
2024/02/08 14:00:48 [DEBUG] error reading file /root/.pact/pact-go.yml error:  open /root/.pact/pact-go.yml: no such file or directory
2024/02/08 14:00:48 [DEBUG] writing config {map[libpact_ffi:{libpact_ffi 0.4.15 f6f4064cad0423a21423122287344c0c}]}
2024/02/08 14:00:48 [DEBUG] writing yaml config to file libraries:
  libpact_ffi:
    libname: libpact_ffi
    version: 0.4.15
    hash: f6f4064cad0423a21423122287344c0c
2024/02/08 14:00:48 [INFO] package libpact_ffi found
2024/02/08 14:00:48 [INFO] checking version 0.4.15 of libpact_ffi against semver constraint >= 0.4.0, < 1.0.0
2024/02/08 14:00:48 [DEBUG] 0.4.15 satisfies constraints 0.4.15 >= 0.4.0, < 1.0.0
2024/02/08 14:00:48 [INFO] package libpact_ffi is correctly installed
2024/02/08 14:00:48 [DEBUG] skip checking ffi version() call because FFI not loaded. This is expected when running the 'pact-go' command.

My guess is using a jwt inside the pact below will recreate the error. Alternatively a testcase on the suspected code in ffi library might also easily recreate it.

Pact

{
  "consumer": {
    "name": "BarClient"
  },
  "interactions": [{
      "_id": "redacted",
      "description": "a request to /GetFoo",
      "providerStates": [{
          "name": "An external auth with",
          "params": {
            "authorization": "redacted-encoded-jwt-token",
            "tenant_id": "pact-tenant"
          }
        }, {
          "name": "A default foo",
          "params": {
            "foo_id": "generated",
          }
        }],
      "request": {
        "body": {
        },
        "generators": {
          "header": {
            "$.authorization[0]": {
              "expression": "authorization",
              "type": "ProviderState"
            }
          }
        },
        "headers": {
          "Content-Type": "application/json",
          "authorization": "redacted-encoded-jwt-token"
        },
        "matchingRules": {
          "body": {
            "$": {
              "combine": "AND",
              "matchers": [{
                  "match": "type"
                }]
            }
          },
          "header": {
            "$.authorization[0]": {
              "combine": "AND",
              "matchers": [{
                  "match": "type"
                }]
            }
          }
        },
        "method": "POST",
        "path": "/GetFoo"
      },
      "response": {
        "body": {
          "addressLine1": "123 Wolseley Road",
        },
        "headers": {
          "content-type": "application/json"
        },
        "matchingRules": {
          "body": {
            "$": {
              "combine": "AND",
              "matchers": [{
                  "match": "type"
                }]
            }
          },
          "header": {
          }
        },
        "status": 200
      }
    }],
  "metadata": {
    "pact-js": {
      "version": "11.0.2"
    },
    "pactRust": {
      "ffi": "0.4.0",
      "models": "1.0.4"
    },
    "pactSpecification": {
      "version": "3.0.0"
    }
  },
  "provider": {
    "name": "FooService"
  },
  "createdAt": "2024-07-25T15:26:48+00:00"
}

Relevent log files

conversation from pact-go slack
Please ensure you set logging to DEBUG and attach any relevant log files here (or link from a gist).

@YOU54F
Copy link
Member

YOU54F commented Jul 30, 2024

Hey @hborham,

Thanks for raising.

Just for reference, a canonical link for the slack conversiontion is archived over on linen.dev - and can be found here

https://www.linen.dev/s/pact-foundation/t/16381085

Ok so taking a look between the pact-go release tags

diff between v2.0.2 and 2.0.3

highlights this commit which bumps libpact_ffi from 0.4.5 -> 0.4.15

That is obviously a big jump and contains a swathe of changes

pact-foundation/pact-reference@libpact_ffi-v0.4.5...libpact_ffi-v0.4.15

Alternatively a testcase on the suspected code in ffi library might also easily recreate it.

This seems like a sensible approach, you can create a test at the ffi barrier here

https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/tests/tests.rs

which would be useful for anyone looking to solve, and allows us to fix forward rather than having to try and find the route cause in that long commit history

@YOU54F
Copy link
Member

YOU54F commented Jul 30, 2024

Noted that the pact was generated from a js client, I wonder if a pact generated with a later version of the pact_ffi may help, as that pact was generated with 0.4.0 with an older version of pact-js

https://www.npmjs.com/package/@pact-foundation/pact/v/11.0.2

The latest version will contain libpact_ffi 0.4.22.

the latest release of pact-go v2.0.6 contains libpact_ffi 0.4.21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants