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

Incorrect header matching rules key in v2 pact files #449

Closed
mefellows opened this issue Jun 21, 2024 · 3 comments
Closed

Incorrect header matching rules key in v2 pact files #449

mefellows opened this issue Jun 21, 2024 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@mefellows
Copy link
Member

mefellows commented Jun 21, 2024

Sample (modified) but discovered by the V2 specs from the terraform client

{
  "consumer": {
    "name": "terraform-client"
  },
  "interactions": [
    {
      "description": "a request to create a system account",
      "request": {
        "method": "GET",
        "path": "/foo"
      },
      "response": {
        "matchingRules": {
          "$.header.Example": {
            "match": "type"
          }
        },
        "headers": {
          "Example": "value"
        },
        "status": 200
      }
    }
 ],
  "metadata": {
    "pactRust": {
      "ffi": "0.4.16",
      "mockserver": "1.2.5",
      "models": "1.1.19"
    },
    "pactSpecification": {
      "version": "2.0.0"
    }
  },
  "provider": {
    "name": "pactflow-application-saas"
  }
}

The field should be $.headers.<key> not $.header.<key> as per https://github.com/pact-foundation/pact-specification/blob/version-2/testcases/response/headers/matches%20with%20regex.json#L10.

@mefellows mefellows added the bug Indicates an unexpected problem or unintended behavior label Jun 21, 2024
@Saup21
Copy link

Saup21 commented Jun 21, 2024

@rholshausen
Copy link
Contributor

This has been around for a very long time. It was fixed in Pact-JVM in 2019 pact-foundation/pact-jvm#882

rholshausen added a commit that referenced this issue Jul 31, 2024
@YOU54F
Copy link
Member

YOU54F commented Sep 4, 2024

This is resolved in the now released 0.4.23 version of libpact_ffi

The following pact, was generated from https://github.com/pact-foundation/pact-workshop-go, with an update to pact-go v2.0.8, which contains libpact_ffi 0.4.23

{
  "consumer": {
    "name": "GoAdminService"
  },
  "interactions": [
    {
      "description": "A request to login with user 'sally'",
      "providerState": "User is not authenticated",
      "request": {
        "matchingRules": {
          "$.path": {
            "match": "regex",
            "regex": "/user/[0-9]+"
          }
        },
        "method": "GET",
        "path": "/user/10"
      },
      "response": {
        "headers": {
          "Content-Type": "application/json",
          "X-Api-Correlation-Id": "100"
        },
        "matchingRules": {
          "$.headers['Content-Type']": {
            "match": "regex",
            "regex": "application\\/json"
          },
          "$.headers['X-Api-Correlation-Id']": {
            "match": "type"
          }
        },
        "status": 401
      }
    },
    {
      "description": "A request to login with user 'sally'",
      "providerState": "User sally does not exist",
      "request": {
        "headers": {
          "Authorization": "Bearer 2019-01-01"
        },
        "matchingRules": {
          "$.headers.Authorization": {
            "match": "type"
          },
          "$.path": {
            "match": "regex",
            "regex": "/user/[0-9]+"
          }
        },
        "method": "GET",
        "path": "/user/10"
      },
      "response": {
        "headers": {
          "Content-Type": "application/json",
          "X-Api-Correlation-Id": "100"
        },
        "matchingRules": {
          "$.headers['Content-Type']": {
            "match": "regex",
            "regex": "application\\/json"
          },
          "$.headers['X-Api-Correlation-Id']": {
            "match": "type"
          }
        },
        "status": 404
      }
    },
    {
      "description": "A request to login with user 'sally'",
      "providerState": "User sally exists",
      "request": {
        "headers": {
          "Authorization": "Bearer 2019-01-01"
        },
        "matchingRules": {
          "$.headers.Authorization": {
            "match": "type"
          },
          "$.path": {
            "match": "regex",
            "regex": "/user/[0-9]+"
          }
        },
        "method": "GET",
        "path": "/user/10"
      },
      "response": {
        "body": {
          "firstName": "Sally",
          "id": 10,
          "lastName": "McSmiley Face😀😍",
          "type": "admin",
          "username": "sally"
        },
        "headers": {
          "Content-Type": "application/json",
          "X-Api-Correlation-Id": "100"
        },
        "matchingRules": {
          "$.body.firstName": {
            "match": "type"
          },
          "$.body.id": {
            "match": "type"
          },
          "$.body.lastName": {
            "match": "type"
          },
          "$.body.type": {
            "match": "regex",
            "regex": "^(admin|user|guest)$"
          },
          "$.body.username": {
            "match": "type"
          },
          "$.headers['Content-Type']": {
            "match": "regex",
            "regex": "application\\/json"
          },
          "$.headers['X-Api-Correlation-Id']": {
            "match": "type"
          }
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pactRust": {
      "ffi": "0.4.23",
      "mockserver": "1.2.10",
      "models": "1.2.5"
    },
    "pactSpecification": {
      "version": "2.0.0"
    }
  },
  "provider": {
    "name": "GoUserService"
  }
}

@YOU54F YOU54F closed this as completed Sep 4, 2024
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

4 participants