leviysoft / mockingbird

Flexible mock server
Apache License 2.0
9 stars 3 forks source link

Fix Xpath to get correct equals method #64

Closed ashashev closed 5 months ago

ashashev commented 5 months ago

Problem

One can create multiple equal stubs if body request prerequisite contains xpath.

Stub example:

{
  "path": "/alpha/test/request",
  "name": "request",
  "labels": [],
  "method": "POST",
  "scope": "persistent",
  "request": {
    "headers": {},
    "query": {},
    "body": {
      "/Envelope/Body/loadData/data/request[@optype='02']": {
        "exists": true
      }
    },
    "extractors": {},
    "inlineCData": true,
    "mode": "xpath"
  },
  "response": {
    "code": 200,
    "headers": {
      "Content-Type": "application/xml"
    },
    "body": "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Body></soapenv:Body></soapenv:Envelope>",
    "delay": null,
    "mode": "xml"
  }
}

Solution

The problem is the equals method of XPathExpression return false for two equal instances. The solution is exclude the field toXPathExpr from the equals method of Xpath type.

@mockingbird/maintainers