@Override public ApiVersionsResponse getErrorResponse(int throttleTimeMs, Throwable e) { short version = version(); switch (version) { case 0: return new ApiVersionsResponse(Errors.forException(e), Collections.emptyList()); case 1: case 2: return new ApiVersionsResponse(throttleTimeMs, Errors.forException(e), Collections.emptyList()); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", version, this.getClass().getSimpleName(), ApiKeys.API_VERSIONS.latestVersion())); } }
@Override protected Struct toStruct() { return new Struct(ApiKeys.API_VERSIONS.requestSchema(version())); }
/** * Tests that ApiVersionsRequest after Kafka SASL handshake request flow, * but prior to actual SASL authentication, results in authentication failure. * This is similar to {@link #testUnauthenticatedApiVersionsRequest(SecurityProtocol, short)} * where a non-SASL client is used to send requests that are processed by * {@link SaslServerAuthenticator} of the server prior to client authentication. */ @Test public void testInvalidApiVersionsRequestSequence() throws Exception { SecurityProtocol securityProtocol = SecurityProtocol.SASL_PLAINTEXT; configureMechanisms("PLAIN", Arrays.asList("PLAIN")); server = createEchoServer(securityProtocol); // Send handshake request followed by ApiVersionsRequest String node1 = "invalid1"; createClientConnection(SecurityProtocol.PLAINTEXT, node1); sendHandshakeRequestReceiveResponse(node1, (short) 1); ApiVersionsRequest request = createApiVersionsRequestV0(); RequestHeader versionsHeader = new RequestHeader(ApiKeys.API_VERSIONS, request.version(), "someclient", 2); selector.send(request.toSend(node1, versionsHeader)); NetworkTestUtils.waitForChannelClose(selector, node1, ChannelState.READY.state()); selector.close(); // Test good connection still works createAndCheckClientConnection(securityProtocol, "good1"); }
send(apiVersionsRequest.toSend(node, nextRequestHeader(ApiKeys.API_VERSIONS, apiVersionsRequest.version()))); setSaslState(SaslState.RECEIVE_APIVERSIONS_RESPONSE); break;