use of org.mockserver.model.OpenAPIDefinition in project mockserver by mock-server.
the class HttpRequestsPropertiesMatcherTest method shouldMatchByPlainTextBody.
// - PLAIN TEXT BODY (via JsonSchema)
@Test
public void shouldMatchByPlainTextBody() {
// given
HttpRequestsPropertiesMatcher httpRequestsPropertiesMatcher = new HttpRequestsPropertiesMatcher(configuration, mockServerLogger);
// when
httpRequestsPropertiesMatcher.update(new Expectation(new OpenAPIDefinition().withSpecUrlOrPayload("---" + NEW_LINE + "openapi: 3.0.0" + NEW_LINE + "paths:" + NEW_LINE + " \"/somePath\":" + NEW_LINE + " post:" + NEW_LINE + " operationId: someOperation" + NEW_LINE + " requestBody:" + NEW_LINE + " required: true" + NEW_LINE + " content:" + NEW_LINE + " application/json:" + NEW_LINE + " schema:" + NEW_LINE + " type: object" + NEW_LINE + " required:" + NEW_LINE + " - id" + NEW_LINE + " - name" + NEW_LINE + " properties:" + NEW_LINE + " id:" + NEW_LINE + " type: integer" + NEW_LINE + " format: int64" + NEW_LINE + " name:" + NEW_LINE + " type: string" + NEW_LINE + " plain/text:" + NEW_LINE + " schema:" + NEW_LINE + " type: object" + NEW_LINE + " required:" + NEW_LINE + " - id" + NEW_LINE + " - name" + NEW_LINE + " properties:" + NEW_LINE + " id:" + NEW_LINE + " type: integer" + NEW_LINE + " format: int64" + NEW_LINE + " name:" + NEW_LINE + " type: string" + NEW_LINE)));
// then
assertTrue(httpRequestsPropertiesMatcher.matches(request().withHeader("content-type", "plain/text").withBody(exact("{ \"id\": 1, \"name\": \"abc\" }"))));
assertTrue(httpRequestsPropertiesMatcher.matches(request().withHeader("content-type", "plain/text; charset=utf-8").withBody(exact("{ \"id\": 1, \"name\": \"abc\" }"))));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withHeader("content-type", "plain/text").withBody(exact("{ \"id\": 1, \"name\": 1 }"))));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withHeader("content-type", "plain/text").withBody(exact("{ \"id\": \"abc\", \"name\": \"abc\" }"))));
}
use of org.mockserver.model.OpenAPIDefinition in project mockserver by mock-server.
the class HttpRequestsPropertiesMatcherTest method shouldMatchBySecuritySchemeInCookieWithBasic.
// COOKIE (SECURITY SCHEMES)
@Test
public void shouldMatchBySecuritySchemeInCookieWithBasic() {
// given
HttpRequestsPropertiesMatcher httpRequestsPropertiesMatcher = new HttpRequestsPropertiesMatcher(configuration, mockServerLogger);
// when
httpRequestsPropertiesMatcher.update(new Expectation(new OpenAPIDefinition().withSpecUrlOrPayload("---" + NEW_LINE + "openapi: 3.0.0" + NEW_LINE + "paths:" + NEW_LINE + " \"/somePath\":" + NEW_LINE + " get:" + NEW_LINE + " operationId: someOperation" + NEW_LINE + " security:" + NEW_LINE + " - BasicAuth: []" + NEW_LINE + "components:" + NEW_LINE + " securitySchemes:" + NEW_LINE + " BasicAuth:" + NEW_LINE + " type: http" + NEW_LINE + " in: cookie" + NEW_LINE + " scheme: basic" + NEW_LINE)));
// then
assertTrue(httpRequestsPropertiesMatcher.matches(request().withCookie("Authorization", "basic " + UUID.randomUUID())));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withCookie("Authorization", "basic")));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withCookie("Authorization", "wrong_scheme " + UUID.randomUUID())));
assertFalse(httpRequestsPropertiesMatcher.matches(request()));
}
use of org.mockserver.model.OpenAPIDefinition in project mockserver by mock-server.
the class HttpRequestsPropertiesMatcherTest method shouldMatchBySecuritySchemeInHeaderWithMultiAuthorizationHeaderSchemes.
@Test
public void shouldMatchBySecuritySchemeInHeaderWithMultiAuthorizationHeaderSchemes() {
// given
HttpRequestsPropertiesMatcher httpRequestsPropertiesMatcher = new HttpRequestsPropertiesMatcher(configuration, mockServerLogger);
// when
httpRequestsPropertiesMatcher.update(new Expectation(new OpenAPIDefinition().withSpecUrlOrPayload("---" + NEW_LINE + "openapi: 3.0.0" + NEW_LINE + "paths:" + NEW_LINE + " \"/somePath\":" + NEW_LINE + " get:" + NEW_LINE + " operationId: someOperation" + NEW_LINE + " security:" + NEW_LINE + " - BasicAuth: []" + NEW_LINE + " - BearerAuth: []" + NEW_LINE + "components:" + NEW_LINE + " securitySchemes:" + NEW_LINE + " BasicAuth:" + NEW_LINE + " type: http" + NEW_LINE + " scheme: basic" + NEW_LINE + " BearerAuth:" + NEW_LINE + " type: http" + NEW_LINE + " scheme: bearer" + NEW_LINE)));
// then
assertTrue(httpRequestsPropertiesMatcher.matches(request().withHeader("Authorization", "basic " + UUIDService.getUUID())));
assertTrue(httpRequestsPropertiesMatcher.matches(request().withHeader("Authorization", "bearer " + UUIDService.getUUID())));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withHeader("Authorization", "bearer")));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withHeader("Authorization", "wrong_scheme " + UUIDService.getUUID())));
assertFalse(httpRequestsPropertiesMatcher.matches(request()));
}
use of org.mockserver.model.OpenAPIDefinition in project mockserver by mock-server.
the class HttpRequestsPropertiesMatcherTest method shouldMatchByPathWithLabelExplodedPathParameter.
@Test
public void shouldMatchByPathWithLabelExplodedPathParameter() {
// given
HttpRequestsPropertiesMatcher httpRequestsPropertiesMatcher = new HttpRequestsPropertiesMatcher(configuration, mockServerLogger);
// when
httpRequestsPropertiesMatcher.update(new Expectation(new OpenAPIDefinition().withSpecUrlOrPayload("---" + NEW_LINE + "openapi: 3.0.0" + NEW_LINE + "paths:" + NEW_LINE + " \"/somePath/{.someParam}\":" + NEW_LINE + " get:" + NEW_LINE + " operationId: someOperation" + NEW_LINE + " parameters:" + NEW_LINE + " - in: path" + NEW_LINE + " name: someParam" + NEW_LINE + " required: true" + NEW_LINE + " style: label" + NEW_LINE + " explode: true" + NEW_LINE + " schema:" + NEW_LINE + " type: integer" + NEW_LINE + " minimum: 1")));
// then
assertTrue(httpRequestsPropertiesMatcher.matches(request().withPath("/somePath/.1.2.3")));
assertTrue(httpRequestsPropertiesMatcher.matches(request().withPath("/somePath/.1")));
assertTrue(httpRequestsPropertiesMatcher.matches(request().withPath("/somePath/.1.2.3.4")));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withPath("/somePath/.0.1.2")));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withPath("/somePath/.a.1.2")));
assertFalse(httpRequestsPropertiesMatcher.matches(request().withPath("/somePath")));
}
use of org.mockserver.model.OpenAPIDefinition in project mockserver by mock-server.
the class HttpRequestsPropertiesMatcherTest method shouldMatchAnyOperationInOpenAPI.
@Test
public void shouldMatchAnyOperationInOpenAPI() {
// given
HttpRequestsPropertiesMatcher httpRequestsPropertiesMatcher = new HttpRequestsPropertiesMatcher(configuration, mockServerLogger);
httpRequestsPropertiesMatcher.update(new Expectation(new OpenAPIDefinition().withSpecUrlOrPayload("org/mockserver/openapi/openapi_petstore_example.json").withOperationId("")));
HttpRequest httpRequest = request().withMethod("GET").withPath("/v1/pets").withQueryStringParameter("limit", "10");
MatchDifference context = new MatchDifference(configuration.detailedMatchFailures(), httpRequest);
// when
boolean matches = httpRequestsPropertiesMatcher.matches(context, httpRequest);
// then
thenMatchesEmptyFieldDifferences(context, matches, true);
}
Aggregations