use of org.mockserver.authentication.AuthenticationException in project mockserver by mock-server.
the class AuthenticatedControlPlaneUsingMTLSClientNotAuthenticatedIntegrationTest method clientOperationIsAuthenticated.
private void clientOperationIsAuthenticated(ThrowingRunnable throwingRunnable) {
// when
AuthenticationException authenticationException = assertThrows(AuthenticationException.class, throwingRunnable);
// then
assertThat(authenticationException.getMessage(), equalTo("Unauthorized for control plane - control plane request failed authentication no client certificates can be validated by control plane CA"));
}
use of org.mockserver.authentication.AuthenticationException in project mockserver by mock-server.
the class MockServerClient method verify.
/**
* Verify a list of requests have been sent in the order specified for example:
* <pre>
* mockServerClient
* .verify(
* request()
* .withPath("/first_request")
* .withBody("some_request_body"),
* request()
* .withPath("/second_request")
* .withBody("some_request_body")
* );
* </pre>
*
* @param expectationIds the http requests that must be matched for this verification to pass
* @throws AssertionError if the request has not been found
*/
public MockServerClient verify(ExpectationId... expectationIds) throws AssertionError {
if (expectationIds == null || expectationIds.length == 0 || expectationIds[0] == null) {
throw new IllegalArgumentException("verify(RequestDefinition...) requires a non-null non-empty array of RequestDefinition objects");
}
try {
VerificationSequence verificationSequence = new VerificationSequence().withExpectationIds(expectationIds);
String result = sendRequest(request().withMethod("PUT").withContentType(APPLICATION_JSON_UTF_8).withPath(calculatePath("verifySequence")).withBody(verificationSequenceSerializer.serialize(verificationSequence), StandardCharsets.UTF_8)).getBodyAsString();
if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
}
} catch (AuthenticationException authenticationException) {
throw authenticationException;
} catch (Throwable throwable) {
throw new AssertionError(throwable.getMessage());
}
return clientClass.cast(this);
}
use of org.mockserver.authentication.AuthenticationException in project mockserver by mock-server.
the class MockServerClient method verify.
/**
* Verify a request has been sent for example:
* <pre>
* mockServerClient
* .verify(
* request()
* .withPath("/some_path")
* .withBody("some_request_body"),
* VerificationTimes.exactly(3)
* );
* </pre>
* VerificationTimes supports multiple static factory methods:
* <p>
* once() - verify the request was only received once
* exactly(n) - verify the request was only received exactly n times
* atLeast(n) - verify the request was only received at least n times
*
* @param requestDefinition the http request that must be matched for this verification to pass
* @param times the number of times this request must be matched
* @throws AssertionError if the request has not been found
*/
@SuppressWarnings("DuplicatedCode")
public MockServerClient verify(RequestDefinition requestDefinition, VerificationTimes times) throws AssertionError {
if (requestDefinition == null) {
throw new IllegalArgumentException("verify(RequestDefinition, VerificationTimes) requires a non null RequestDefinition object");
}
if (times == null) {
throw new IllegalArgumentException("verify(RequestDefinition, VerificationTimes) requires a non null VerificationTimes object");
}
try {
Verification verification = verification().withRequest(requestDefinition).withTimes(times);
String result = sendRequest(request().withMethod("PUT").withContentType(APPLICATION_JSON_UTF_8).withPath(calculatePath("verify")).withBody(verificationSerializer.serialize(verification), StandardCharsets.UTF_8)).getBodyAsString();
if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
}
} catch (AuthenticationException authenticationException) {
throw authenticationException;
} catch (Throwable throwable) {
throw new AssertionError(throwable.getMessage());
}
return clientClass.cast(this);
}
use of org.mockserver.authentication.AuthenticationException in project mockserver by mock-server.
the class MockServerClient method verify.
/**
* Verify a list of requests have been sent in the order specified for example:
* <pre>
* mockServerClient
* .verify(
* request()
* .withPath("/first_request")
* .withBody("some_request_body"),
* request()
* .withPath("/second_request")
* .withBody("some_request_body")
* );
* </pre>
*
* @param requestDefinitions the http requests that must be matched for this verification to pass
* @throws AssertionError if the request has not been found
*/
public MockServerClient verify(RequestDefinition... requestDefinitions) throws AssertionError {
if (requestDefinitions == null || requestDefinitions.length == 0 || requestDefinitions[0] == null) {
throw new IllegalArgumentException("verify(RequestDefinition...) requires a non-null non-empty array of RequestDefinition objects");
}
try {
VerificationSequence verificationSequence = new VerificationSequence().withRequests(requestDefinitions);
String result = sendRequest(request().withMethod("PUT").withContentType(APPLICATION_JSON_UTF_8).withPath(calculatePath("verifySequence")).withBody(verificationSequenceSerializer.serialize(verificationSequence), StandardCharsets.UTF_8)).getBodyAsString();
if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
}
} catch (AuthenticationException authenticationException) {
throw authenticationException;
} catch (Throwable throwable) {
throw new AssertionError(throwable.getMessage());
}
return clientClass.cast(this);
}
use of org.mockserver.authentication.AuthenticationException in project mockserver by mock-server.
the class MockServerClient method verify.
/**
* Verify a request has been sent for example:
* <pre>
* mockServerClient
* .verify(
* request()
* .withPath("/some_path")
* .withBody("some_request_body"),
* VerificationTimes.exactly(3)
* );
* </pre>
* VerificationTimes supports multiple static factory methods:
* <p>
* once() - verify the request was only received once
* exactly(n) - verify the request was only received exactly n times
* atLeast(n) - verify the request was only received at least n times
*
* @param expectationId the http request that must be matched for this verification to pass
* @param times the number of times this request must be matched
* @throws AssertionError if the request has not been found
*/
@SuppressWarnings("DuplicatedCode")
public MockServerClient verify(ExpectationId expectationId, VerificationTimes times) throws AssertionError {
if (expectationId == null) {
throw new IllegalArgumentException("verify(RequestDefinition, VerificationTimes) requires a non null RequestDefinition object");
}
if (times == null) {
throw new IllegalArgumentException("verify(RequestDefinition, VerificationTimes) requires a non null VerificationTimes object");
}
try {
Verification verification = verification().withExpectationId(expectationId).withTimes(times);
String result = sendRequest(request().withMethod("PUT").withContentType(APPLICATION_JSON_UTF_8).withPath(calculatePath("verify")).withBody(verificationSerializer.serialize(verification), StandardCharsets.UTF_8)).getBodyAsString();
if (result != null && !result.isEmpty()) {
throw new AssertionError(result);
}
} catch (AuthenticationException authenticationException) {
throw authenticationException;
} catch (Throwable throwable) {
throw new AssertionError(throwable.getMessage());
}
return clientClass.cast(this);
}
Aggregations