Search in sources :

Example 16 with GenericKafkaListenerBuilder

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder in project strimzi by strimzi.

the class ListenersValidatorTest method testValidateThrowsException.

@ParallelTest
public void testValidateThrowsException() {
    GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).build();
    GenericKafkaListener listener2 = new GenericKafkaListenerBuilder().withName("listener2").withPort(9900).withType(KafkaListenerType.INTERNAL).build();
    List<GenericKafkaListener> listeners = asList(listener1, listener2);
    Exception exception = assertThrows(InvalidResourceException.class, () -> ListenersValidator.validate(Reconciliation.DUMMY_RECONCILIATION, 3, listeners));
    assertThat(exception.getMessage(), containsString("every listener needs to have a unique port number"));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 17 with GenericKafkaListenerBuilder

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder in project strimzi 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));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) KafkaListenerAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 18 with GenericKafkaListenerBuilder

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder in project strimzi by strimzi.

the class ListenersValidatorTest method testValidateCustomClaimCheckOauth.

@ParallelTest
public void testValidateCustomClaimCheckOauth() {
    KafkaListenerAuthenticationOAuthBuilder authBuilder = new KafkaListenerAuthenticationOAuthBuilder().withCustomClaimCheck("invalid");
    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: 'customClaimCheck' value not a valid JsonPath filter query - Failed to parse filter query: \"invalid\"")));
    // set valid JsonPath query
    authBuilder.withCustomClaimCheck("@.valid == 'value'");
    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: 'customClaimCheck' value not a valid JsonPath filter query - Failed to parse query: \"invalid\" at position: 0"))));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) KafkaListenerAuthenticationOAuthBuilder(io.strimzi.api.kafka.model.listener.KafkaListenerAuthenticationOAuthBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 19 with GenericKafkaListenerBuilder

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder in project strimzi by strimzi.

the class ListenersValidatorTest method testLoadBalancerListener.

@ParallelTest
public void testLoadBalancerListener() {
    String name = "lb";
    GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName(name).withPort(9092).withType(KafkaListenerType.LOADBALANCER).withNewConfiguration().withIngressClass("my-ingress").withUseServiceDnsDomain(true).withExternalTrafficPolicy(ExternalTrafficPolicy.LOCAL).withIpFamilyPolicy(IpFamilyPolicy.REQUIRE_DUAL_STACK).withIpFamilies(IpFamily.IPV4, IpFamily.IPV6).withPreferredNodePortAddressType(NodeAddressType.INTERNAL_DNS).withLoadBalancerSourceRanges(asList("10.0.0.0/8", "130.211.204.1/32")).withFinalizers(asList("service.kubernetes.io/load-balancer-cleanup")).withNewBootstrap().withAlternativeNames(asList("my-name-1", "my-name-2")).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).endBootstrap().withBrokers(new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(0).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).build(), new GenericKafkaListenerConfigurationBrokerBuilder().withBroker(1).withAdvertisedHost("advertised-host").withAdvertisedPort(9092).withLoadBalancerIP("130.211.204.1").withNodePort(32189).withHost("my-host").withAnnotations(Collections.singletonMap("dns-anno", "dns-value")).build()).endConfiguration().build();
    List<GenericKafkaListener> listeners = asList(listener1);
    List<String> expectedErrors = asList("listener " + name + " cannot configure ingressClass because it is not Ingress based listener", "listener " + name + " cannot configure useServiceDnsDomain because it is not internal listener", "listener " + name + " cannot configure preferredAddressType because it is not NodePort based listener", "listener " + name + " cannot configure bootstrap.host because it is not Route ot Ingress based listener", "listener " + name + " cannot configure bootstrap.nodePort because it is not NodePort based listener", "listener " + name + " cannot configure brokers[].host because it is not Route ot Ingress based listener", "listener " + name + " cannot configure brokers[].nodePort because it is not NodePort based listener");
    assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder(expectedErrors.toArray()));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) GenericKafkaListenerConfigurationBrokerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Example 20 with GenericKafkaListenerBuilder

use of io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder in project strimzi by strimzi.

the class ListenersValidatorTest method testValidateDuplicatePorts.

@ParallelTest
public void testValidateDuplicatePorts() {
    GenericKafkaListener listener1 = new GenericKafkaListenerBuilder().withName("listener1").withPort(9900).withType(KafkaListenerType.INTERNAL).build();
    GenericKafkaListener listener2 = new GenericKafkaListenerBuilder().withName("listener2").withPort(9901).withType(KafkaListenerType.INTERNAL).build();
    GenericKafkaListener listener3 = new GenericKafkaListenerBuilder().withName("listener3").withPort(9901).withType(KafkaListenerType.INTERNAL).build();
    List<GenericKafkaListener> listeners = asList(listener1, listener2, listener3);
    assertThat(ListenersValidator.validateAndGetErrorMessages(3, listeners), containsInAnyOrder("every listener needs to have a unique port number"));
}
Also used : GenericKafkaListener(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) ParallelTest(io.strimzi.test.annotations.ParallelTest)

Aggregations

GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)352 ParallelTest (io.strimzi.test.annotations.ParallelTest)180 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)124 Kafka (io.strimzi.api.kafka.model.Kafka)122 GenericKafkaListener (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListener)110 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)110 Tag (org.junit.jupiter.api.Tag)86 ParallelNamespaceTest (io.strimzi.systemtest.annotations.ParallelNamespaceTest)82 GenericKafkaListenerConfigurationBrokerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBrokerBuilder)80 Matchers.containsString (org.hamcrest.Matchers.containsString)74 KafkaUser (io.strimzi.api.kafka.model.KafkaUser)62 InternalKafkaClient (io.strimzi.systemtest.kafkaclients.clients.InternalKafkaClient)56 Service (io.fabric8.kubernetes.api.model.Service)52 GenericKafkaListenerConfigurationBroker (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerConfigurationBroker)50 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)48 Reconciliation (io.strimzi.operator.common.Reconciliation)48 KafkaListenerType (io.strimzi.api.kafka.model.listener.arraylistener.KafkaListenerType)46 Labels (io.strimzi.operator.common.model.Labels)46 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)44 ArrayList (java.util.ArrayList)44