Search in sources :

Example 1 with ApiVersionsRequestData

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());
    }
}
Also used : ApiVersionsRequestData(org.apache.kafka.common.message.ApiVersionsRequestData) Test(org.junit.jupiter.api.Test)

Example 2 with ApiVersionsRequestData

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);
}
Also used : ApiVersionsResponse(org.apache.kafka.common.requests.ApiVersionsResponse) SecurityProtocol(org.apache.kafka.common.security.auth.SecurityProtocol) RequestHeader(org.apache.kafka.common.requests.RequestHeader) NetworkSend(org.apache.kafka.common.network.NetworkSend) ApiVersionsRequest(org.apache.kafka.common.requests.ApiVersionsRequest) ApiVersionsRequestData(org.apache.kafka.common.message.ApiVersionsRequestData) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 3 with ApiVersionsRequestData

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());
}
Also used : ApiVersionsRequestData(org.apache.kafka.common.message.ApiVersionsRequestData)

Aggregations

ApiVersionsRequestData (org.apache.kafka.common.message.ApiVersionsRequestData)3 Test (org.junit.jupiter.api.Test)2 ByteBuffer (java.nio.ByteBuffer)1 NetworkSend (org.apache.kafka.common.network.NetworkSend)1 ApiVersionsRequest (org.apache.kafka.common.requests.ApiVersionsRequest)1 ApiVersionsResponse (org.apache.kafka.common.requests.ApiVersionsResponse)1 RequestHeader (org.apache.kafka.common.requests.RequestHeader)1 SecurityProtocol (org.apache.kafka.common.security.auth.SecurityProtocol)1