Open gbmarc1 opened 2 years ago
Got the same issue...
I can't reproduce this even with an OpenAPI specification with a multipart/form-data
field.
Perhaps there is an issue related to your specific OpenAPI specification or your specification includes a request that would match the curl you're making.
Please provide the specification so I can test with that.
Hi, I get the same issue.
If content is multipart/form-data
, httpRequestPropertiesMatcher
is not added to httpRequestPropertiesMatchers
.
https://github.com/mock-server/mockserver/blob/master/mockserver-core/src/main/java/org/mockserver/matchers/HttpRequestsPropertiesMatcher.java#L438
if (contentType.equals("multipart/form-data")) {
logEntries.add(
new LogEntry()
.setLogLevel(ERROR)
.setMessageFormat("multipart form data is not supported on requestBody, skipping operation:{}method:{}in open api:{}")
.setArguments(methodOperationPair.getRight().getOperationId(), methodOperationPair.getLeft(), openAPIDefinition)
);
return;
}
When httpRequestPropertiesMatchers
is empty, always return true
.
https://github.com/mock-server/mockserver/blob/master/mockserver-core/src/main/java/org/mockserver/matchers/HttpRequestsPropertiesMatcher.java#L504
public boolean matches(MatchDifference context, RequestDefinition requestDefinition) {
boolean result = false;
if (httpRequestPropertiesMatchers != null && !httpRequestPropertiesMatchers.isEmpty()) {
for (HttpRequestPropertiesMatcher httpRequestPropertiesMatcher : httpRequestPropertiesMatchers) {
if (context == null) {
if (MockServerLogger.isEnabled(Level.TRACE) && requestDefinition instanceof HttpRequest) {
context = new MatchDifference(configuration.detailedMatchFailures(), requestDefinition);
}
result = httpRequestPropertiesMatcher.matches(context, requestDefinition);
} else {
MatchDifference singleMatchDifference = new MatchDifference(configuration.detailedMatchFailures(), context.getHttpRequest());
result = httpRequestPropertiesMatcher.matches(singleMatchDifference, requestDefinition);
context.addDifferences(singleMatchDifference.getAllDifferences());
}
if (result) {
break;
}
}
} else {
result = true;
}
return result;
}
I think also multipart/form-data
has to have httpRequestPropertiesMatcher
.
Describe the issue I have an openapi spec that creates multiple expectations. When calling an endpoint that does not exist (that does should not match any expectation), I would assume that the mock server would return 404. However, it always returns a reponse of a specific expectation that does NOT match.
For example: Request:
curl --user name:password -v GET "http://localhost:1080/idontexists"
Response:
The default response comes from a "not supported" operation that is added. It seems that its response becomes the default when not found.
If I remove that operation in the .yaml file, the mock server behaves properly.
MockServer version I used mockserver/mockserver:mockserver-5.13.2 and mockserver/mockserver:latest and both have the same behaviour.
MockServer Log