use of org.apache.kafka.common.errors.SaslAuthenticationException in project apache-kafka-on-k8s by banzaicloud.
the class ClientAuthenticationFailureTest method testAdminClientWithInvalidCredentials.
@Test
public void testAdminClientWithInvalidCredentials() {
Map<String, Object> props = new HashMap<>(saslClientConfigs);
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + server.port());
try (AdminClient client = AdminClient.create(props)) {
DescribeTopicsResult result = client.describeTopics(Collections.singleton("test"));
result.all().get();
fail("Expected an authentication error!");
} catch (Exception e) {
assertTrue("Expected SaslAuthenticationException, got " + e.getCause().getClass(), e.getCause() instanceof SaslAuthenticationException);
}
}
use of org.apache.kafka.common.errors.SaslAuthenticationException in project apache-kafka-on-k8s by banzaicloud.
the class ClientAuthenticationFailureTest method testTransactionalProducerWithInvalidCredentials.
@Test
public void testTransactionalProducerWithInvalidCredentials() throws Exception {
Map<String, Object> props = new HashMap<>(saslClientConfigs);
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + server.port());
props.put(ProducerConfig.TRANSACTIONAL_ID_CONFIG, "txclient-1");
props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, "true");
StringSerializer serializer = new StringSerializer();
try (KafkaProducer<String, String> producer = new KafkaProducer<>(props, serializer, serializer)) {
producer.initTransactions();
fail("Expected an authentication error!");
} catch (SaslAuthenticationException e) {
// expected exception
}
}
use of org.apache.kafka.common.errors.SaslAuthenticationException in project apache-kafka-on-k8s by banzaicloud.
the class SaslAuthenticatorTest method createAndCheckClientAuthenticationFailure.
private void createAndCheckClientAuthenticationFailure(SecurityProtocol securityProtocol, String node, String mechanism, String expectedErrorMessage) throws Exception {
ChannelState finalState = createAndCheckClientConnectionFailure(securityProtocol, node);
Exception exception = finalState.exception();
assertTrue("Invalid exception class " + exception.getClass(), exception instanceof SaslAuthenticationException);
if (expectedErrorMessage == null)
expectedErrorMessage = "Authentication failed due to invalid credentials with SASL mechanism " + mechanism;
assertEquals(expectedErrorMessage, exception.getMessage());
}
Aggregations