use of io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testValidateOauthPlain.
@ParallelTest
public void testValidateOauthPlain() {
KafkaListenerAuthenticationOAuthBuilder authBuilder = new KafkaListenerAuthenticationOAuthBuilder().withEnableOauthBearer(false);
GenericKafkaListenerBuilder listenerBuilder = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(authBuilder.build());
GenericKafkaListener listener = listenerBuilder.withAuth(authBuilder.build()).build();
List<GenericKafkaListener> listeners = asList(listener);
Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
assertThat(exception.getMessage(), allOf(containsString("listener listener1: At least one of 'enablePlain', 'enableOauthBearer' has to be set to 'true'")));
// enable plain with neither introspectionEndpointUri nor jwksEndpointUri set
authBuilder.withEnablePlain(true);
listener = listenerBuilder.withAuth(authBuilder.build()).build();
List<GenericKafkaListener> listeners2 = asList(listener);
exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners2));
assertThat(exception.getMessage(), allOf(containsString("listener listener1: Introspection endpoint URI or JWKS endpoint URI has to be specified")));
// enable plain with jwksEndpointUri set but tokenEndpointUri not set
authBuilder.withJwksEndpointUri("http://localhost:8080/jwks").withCheckIssuer(false);
listener = listenerBuilder.withAuth(authBuilder.build()).build();
List<GenericKafkaListener> listeners3 = asList(listener);
assertDoesNotThrow(() -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners3));
}
use of io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testValidateAudienceOauth.
@ParallelTest
public void testValidateAudienceOauth() {
KafkaListenerAuthenticationOAuthBuilder authBuilder = new KafkaListenerAuthenticationOAuthBuilder().withCheckAudience(true);
GenericKafkaListenerBuilder listenerBuilder = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(authBuilder.build());
GenericKafkaListener listener = listenerBuilder.withAuth(authBuilder.build()).build();
List<GenericKafkaListener> listeners = asList(listener);
Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
assertThat(exception.getMessage(), allOf(containsString("listener listener1: 'clientId' has to be configured when 'checkAudience' is 'true'")));
// set clientId
authBuilder.withClientId("kafka");
listener = listenerBuilder.withAuth(authBuilder.build()).build();
List<GenericKafkaListener> listeners2 = asList(listener);
exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners2));
assertThat(exception.getMessage(), allOf(not(containsString("listener listener1: 'clientId' has to be configured when 'checkAudience' is 'true'"))));
}
use of io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder in project strimzi-kafka-operator by strimzi.
the class ListenersValidatorTest method testValidateOauth.
@ParallelTest
public void testValidateOauth() {
GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).withAuth(new KafkaListenerAuthenticationOAuthBuilder().build()).build();
List<GenericKafkaListener> listeners = asList(listener1);
Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
assertThat(exception.getMessage(), allOf(containsString("listener listener1: Introspection endpoint URI or JWKS endpoint URI has to be specified"), containsString("listener listener1: Valid Issuer URI has to be specified or 'checkIssuer' set to 'false'")));
}
use of io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaClusterOAuthValidationTest method testOAuthValidationWithConnectTimeout.
@ParallelTest
public void testOAuthValidationWithConnectTimeout() {
assertThrows(InvalidResourceException.class, () -> {
KafkaListenerAuthenticationOAuth auth = new KafkaListenerAuthenticationOAuthBuilder().withValidIssuerUri("http://valid-issuer").withJwksEndpointUri("http://jwks-endpoint").withConnectTimeoutSeconds(0).build();
ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, getListeners(auth));
});
}
use of io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder in project strimzi-kafka-operator by strimzi.
the class KafkaClusterOAuthValidationTest method testOAuthValidationWithOAuthWithIntrospectionWithNoTypeCheck.
@ParallelTest
public void testOAuthValidationWithOAuthWithIntrospectionWithNoTypeCheck() {
assertThrows(InvalidResourceException.class, () -> {
KafkaListenerAuthenticationOAuth auth = new KafkaListenerAuthenticationOAuthBuilder().withValidIssuerUri("http://valid-issuer").withClientId("my-kafka-id").withNewClientSecret().withSecretName("my-secret-secret").withKey("my-secret-key").endClientSecret().withIntrospectionEndpointUri("http://introspection-endpoint").withCheckAccessTokenType(false).build();
ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, getListeners(auth));
});
}
Aggregations