use of org.apache.kafka.common.message.ApiVersionsRequestData in project kafka by apache.
the class RequestResponseTest method testApiVersionsRequestBeforeV3Validation.
@Test
public void testApiVersionsRequestBeforeV3Validation() {
for (short version = 0; version < 3; version++) {
ApiVersionsRequest request = new ApiVersionsRequest(new ApiVersionsRequestData(), version);
assertTrue(request.isValid());
}
}
use of org.apache.kafka.common.message.ApiVersionsRequestData in project kafka by apache.
the class SaslAuthenticatorTest method testInvalidApiVersionsRequest.
/**
* Tests that invalid ApiVersionRequest is handled by the server correctly and
* returns an INVALID_REQUEST error.
*/
@Test
public void testInvalidApiVersionsRequest() throws Exception {
short handshakeVersion = ApiKeys.SASL_HANDSHAKE.latestVersion();
SecurityProtocol securityProtocol = SecurityProtocol.SASL_PLAINTEXT;
configureMechanisms("PLAIN", Arrays.asList("PLAIN"));
server = createEchoServer(securityProtocol);
// Send ApiVersionsRequest with invalid version and validate error response.
String node = "1";
short version = ApiKeys.API_VERSIONS.latestVersion();
createClientConnection(SecurityProtocol.PLAINTEXT, node);
RequestHeader header = new RequestHeader(ApiKeys.API_VERSIONS, version, "someclient", 1);
ApiVersionsRequest request = new ApiVersionsRequest(new ApiVersionsRequestData().setClientSoftwareName(" ").setClientSoftwareVersion(" "), version);
selector.send(new NetworkSend(node, request.toSend(header)));
ByteBuffer responseBuffer = waitForResponse();
ResponseHeader.parse(responseBuffer, ApiKeys.API_VERSIONS.responseHeaderVersion(version));
ApiVersionsResponse response = ApiVersionsResponse.parse(responseBuffer, version);
assertEquals(Errors.INVALID_REQUEST.code(), response.data().errorCode());
// Send ApiVersionsRequest with a supported version. This should succeed.
sendVersionRequestReceiveResponse(node);
// Test that client can authenticate successfully
sendHandshakeRequestReceiveResponse(node, handshakeVersion);
authenticateUsingSaslPlainAndCheckConnection(node, handshakeVersion > 0);
}
use of org.apache.kafka.common.message.ApiVersionsRequestData in project kafka by apache.
the class RequestResponseTest method testInvalidCase.
private void testInvalidCase(String name, String version) {
ApiVersionsRequest request = new ApiVersionsRequest(new ApiVersionsRequestData().setClientSoftwareName(name).setClientSoftwareVersion(version), API_VERSIONS.latestVersion());
assertFalse(request.isValid());
}
Aggregations