mockserver icon indicating copy to clipboard operation
mockserver copied to clipboard

MockServerClient.verify(RequestDefinition requestDefinition, VerificationTimes times) not works correctly after update to 5.14.0

Open dorohovichandrey opened this issue 3 years ago • 2 comments

Describe the issue After the update from 5.13.2 to 5.14.0 MockServerClient.verify(RequestDefinition requestDefinition, VerificationTimes times) start working not correctly in the cases, where expectations were defined with Path Parameters

What you are trying to do https://github.com/dorohovichandrey/mockserver-example/blob/5.13.2/src/test/kotlin/com/example/MockserverVerifyTests.kt - tests passed on MockServer version 5.13.2

https://github.com/dorohovichandrey/mockserver-example/blob/5.14.0/src/test/kotlin/com/example/MockserverVerifyTests.kt - tests failed on MockServer version 5.14.0

To Reproduce Steps to reproduce the issue:

  1. define expectation with path parameter
  2. call mocked endpoint
  3. invoke MockServerClient.verify(RequestDefinition requestDefinition, VerificationTimes times) https://github.com/dorohovichandrey/mockserver-example/blob/5.14.0/src/test/kotlin/com/example/MockserverVerifyTests.kt

How you are running MockServer (i.e maven plugin, docker, etc) In Docker by the Testcontainers (tested in both ARM and AMD envs)

What error you saw

Request not found exactly once, expected:<{
  "method" : "GET",
  "path" : "/something/{id}"
}> but was:<{
  "headers" : {
    "content-length" : [ "0" ],
    "Accept" : [ "*/*" ],
    "content-encoding" : [ ".*" ],
    "Connection" : [ "Keep-Alive" ],
    "User-Agent" : [ "Apache-HttpClient/4.5.13 (Java/17.0.3)" ],
    "Host" : [ "localhost:60503" ],
    "Accept-Encoding" : [ "gzip,deflate" ]
  },
  "keepAlive" : true,
  "method" : "GET",
  "path" : "/something/123",
  "secure" : false
}>
<Click to see difference>

java.lang.AssertionError: Request not found exactly once, expected:<{
  "method" : "GET",
  "path" : "/something/{id}"
}> but was:<{
  "headers" : {
    "content-length" : [ "0" ],
    "Accept" : [ "*/*" ],
    "content-encoding" : [ ".*" ],
    "Connection" : [ "Keep-Alive" ],
    "User-Agent" : [ "Apache-HttpClient/4.5.13 (Java/17.0.3)" ],
    "Host" : [ "localhost:60503" ],
    "Accept-Encoding" : [ "gzip,deflate" ]
  },
  "keepAlive" : true,
  "method" : "GET",
  "path" : "/something/123",
  "secure" : false
}>

Expected behavior Tests should pass (as it was on version 5.13.2)

MockServer Log Logs that can point to route cause (full logs attached test_execution_plus_container_debug_logs.txt ):

2022-10-11 13:40:57 5.14.0 INFO 1080 verifying requests that match:

  {
    "httpRequest" : {
      "method" : "GET",
      "path" : "/something/{id}",
      "pathParameters" : {
        "id" : [ ".*" ]
      }
    },
    "times" : {
      "atLeast" : 2,
      "atMost" : 2
    }
  }
 
2022-10-11 13:40:57 5.14.0 FINE error while matching regex [{id}] for string [.*] Illegal repetition near index 1
{id}
 ^ 
java.util.regex.PatternSyntaxException: Illegal repetition near index 1
{id}
 ^
	at java.base/java.util.regex.Pattern.error(Pattern.java:2028)
	at java.base/java.util.regex.Pattern.closure(Pattern.java:3309)
	at java.base/java.util.regex.Pattern.sequence(Pattern.java:2214)
	at java.base/java.util.regex.Pattern.expr(Pattern.java:2069)
	at java.base/java.util.regex.Pattern.compile(Pattern.java:1783)
	at java.base/java.util.regex.Pattern.<init>(Pattern.java:1430)
	at java.base/java.util.regex.Pattern.compile(Pattern.java:1095)
	at org.mockserver.model.NottableString.matches(NottableString.java:214)
	at org.mockserver.matchers.RegexStringMatcher.matchesByStrings(RegexStringMatcher.java:90)
	at org.mockserver.matchers.RegexStringMatcher.matchesByNottedStrings(RegexStringMatcher.java:68)
	at org.mockserver.matchers.RegexStringMatcher.matches(RegexStringMatcher.java:58)
	at org.mockserver.collections.SubSetMatcher.matchesIndexes(SubSetMatcher.java:43)
	at org.mockserver.collections.SubSetMatcher.containsSubset(SubSetMatcher.java:20)
	at org.mockserver.collections.NottableStringMultiMap.containsAll(NottableStringMultiMap.java:49)
	at org.mockserver.matchers.MultiValueMapMatcher.matches(MultiValueMapMatcher.java:50)
	at org.mockserver.matchers.MultiValueMapMatcher.matches(MultiValueMapMatcher.java:15)
	at org.mockserver.matchers.HttpRequestPropertiesMatcher.matches(HttpRequestPropertiesMatcher.java:487)
	at org.mockserver.matchers.HttpRequestPropertiesMatcher.matches(HttpRequestPropertiesMatcher.java:315)
	at org.mockserver.matchers.HttpRequestPropertiesMatcher.matches(HttpRequestPropertiesMatcher.java:202)
	at org.mockserver.log.model.LogEntry.matches(LogEntry.java:202)
	at org.mockserver.log.MockServerEventLog.lambda$null$28(MockServerEventLog.java:434)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
	at java.base/java.util.concurrent.ConcurrentLinkedDeque$CLDSpliterator.forEachRemaining(ConcurrentLinkedDeque.java:1483)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at org.mockserver.log.MockServerEventLog.lambda$retrieveRequests$14(MockServerEventLog.java:289)
	at org.mockserver.log.MockServerEventLog.lambda$retrieveLogEntries$29(MockServerEventLog.java:432)
	at org.mockserver.log.MockServerEventLog.lambda$startRingBuffer$7(MockServerEventLog.java:144)
	at com.lmax.disruptor.BatchEventProcessor.processEvents(BatchEventProcessor.java:168)
	at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:125)
	at java.base/java.lang.Thread.run(Thread.java:833)

dorohovichandrey avatar Oct 11 '22 13:10 dorohovichandrey

Same still happens on mockserver 5.15.0

joggeli34 avatar Feb 07 '23 10:02 joggeli34

Just FYI we back-ported the mentioned fix #1791 into our fork of this project, I didn't have a chance to test it yet but it might help, so feel free to check it out.

AB-xdev avatar Jun 05 '24 12:06 AB-xdev