Search in sources :

Example 21 with MockKube

use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.

the class ConfigTest method testTlsEnabledConfig.

@Test
public void testTlsEnabledConfig() {
    Map<String, String> map = new HashMap<>(MANDATORY);
    map.put(Config.TLS_ENABLED.key, "true");
    MockKube mockKube = new MockKube();
    KubernetesClient kubeClient = mockKube.build();
    Config config = new Config(map);
    Session session = new Session(kubeClient, config);
    Properties adminClientProps = session.adminClientProperties();
    assertThat(adminClientProps.getProperty(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG), is("HTTPS"));
    assertThat(adminClientProps.getProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG), is("SSL"));
}
Also used : MockKube(io.strimzi.test.mockkube.MockKube) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HashMap(java.util.HashMap) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 22 with MockKube

use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.

the class ConfigTest method testInvalidKeystoreConfig.

@Test
public void testInvalidKeystoreConfig() {
    Map<String, String> map = new HashMap<>(MANDATORY);
    map.put(Config.TLS_ENABLED.key, "true");
    map.put(Config.TLS_TRUSTSTORE_PASSWORD.key, "password");
    MockKube mockKube = new MockKube();
    KubernetesClient kubeClient = mockKube.build();
    Config config = new Config(map);
    Session session = new Session(kubeClient, config);
    assertThrows(InvalidConfigurationException.class, () -> session.adminClientProperties());
}
Also used : MockKube(io.strimzi.test.mockkube.MockKube) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HashMap(java.util.HashMap) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) Test(org.junit.jupiter.api.Test)

Example 23 with MockKube

use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.

the class ConfigTest method testScramSaslConfig.

@Test
public void testScramSaslConfig() {
    Map<String, String> map = new HashMap<>(MANDATORY);
    map.put(Config.SASL_ENABLED.key, "true");
    String username = "admin";
    String password = "password";
    map.put(Config.SASL_USERNAME.key, username);
    map.put(Config.SASL_PASSWORD.key, password);
    String scramJaasConfig = "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"" + username + "\" password=\"" + password + "\";";
    String plainJaasConfig = "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"" + username + "\" password=\"" + password + "\";";
    MockKube mockKube = new MockKube();
    KubernetesClient kubeClient = mockKube.build();
    map.put(Config.SASL_MECHANISM.key, "scram-sha-256");
    Config configSHA256 = new Config(map);
    Session sessionSHA256 = new Session(kubeClient, configSHA256);
    Properties adminClientPropsSHA256 = sessionSHA256.adminClientProperties();
    assertThat(adminClientPropsSHA256.getProperty(SaslConfigs.SASL_MECHANISM), is("SCRAM-SHA-256"));
    assertThat(adminClientPropsSHA256.getProperty(SaslConfigs.SASL_JAAS_CONFIG), is(scramJaasConfig));
    map.put(Config.SASL_MECHANISM.key, "scram-sha-512");
    Config configSHA512 = new Config(map);
    Session sessionSHA512 = new Session(kubeClient, configSHA512);
    Properties adminClientPropsSHA512 = sessionSHA512.adminClientProperties();
    assertThat(adminClientPropsSHA512.getProperty(SaslConfigs.SASL_MECHANISM), is("SCRAM-SHA-512"));
    assertThat(adminClientPropsSHA512.getProperty(SaslConfigs.SASL_JAAS_CONFIG), is(scramJaasConfig));
    map.put(Config.SASL_MECHANISM.key, "plain");
    Config configPlain = new Config(map);
    Session sessionPlain = new Session(kubeClient, configPlain);
    Properties adminClientPropsPlain = sessionPlain.adminClientProperties();
    assertThat(adminClientPropsPlain.getProperty(SaslConfigs.SASL_MECHANISM), is("PLAIN"));
    assertThat(adminClientPropsPlain.getProperty(SaslConfigs.SASL_JAAS_CONFIG), is(plainJaasConfig));
}
Also used : MockKube(io.strimzi.test.mockkube.MockKube) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HashMap(java.util.HashMap) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 24 with MockKube

use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.

the class ConfigTest method testSecurityProtocolConfig.

@Test
public void testSecurityProtocolConfig() {
    Map<String, String> map = new HashMap<>(MANDATORY);
    map.put(Config.SECURITY_PROTOCOL.key, "SSL");
    MockKube mockKube = new MockKube();
    KubernetesClient kubeClient = mockKube.build();
    Config config = new Config(map);
    Session session = new Session(kubeClient, config);
    Properties adminClientProps = session.adminClientProperties();
    assertThat(adminClientProps.getProperty(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG), is("HTTPS"));
    assertThat(adminClientProps.getProperty(AdminClientConfig.SECURITY_PROTOCOL_CONFIG), is("SSL"));
}
Also used : MockKube(io.strimzi.test.mockkube.MockKube) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) HashMap(java.util.HashMap) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Example 25 with MockKube

use of io.strimzi.test.mockkube.MockKube in project strimzi by strimzi.

the class KafkaAssemblyOperatorMockTest method init.

/*
     * init is equivalent to a @BeforeEach method
     * since this is a parameterized set, the tests params are only available at test start
     * This must be called before each test
     */
private void init(Params params) {
    setFields(params);
    cluster = new KafkaBuilder().withNewMetadata().withName(CLUSTER_NAME).withNamespace(NAMESPACE).withLabels(singletonMap("foo", "bar")).endMetadata().withNewSpec().withNewKafka().withReplicas(kafkaReplicas).withStorage(kafkaStorage).withListeners(new GenericKafkaListenerBuilder().withName("plain").withPort(9092).withType(KafkaListenerType.INTERNAL).withTls(false).build(), new GenericKafkaListenerBuilder().withName("tls").withPort(9093).withType(KafkaListenerType.INTERNAL).withTls(true).build()).withResources(resources).endKafka().withNewZookeeper().withReplicas(zkReplicas).withStorage(zkStorage).endZookeeper().withNewEntityOperator().withNewTopicOperator().endTopicOperator().withNewUserOperator().endUserOperator().endEntityOperator().endSpec().build();
    CustomResourceDefinition kafkaAssemblyCrd = Crds.kafka();
    client = new MockKube().withCustomResourceDefinition(kafkaAssemblyCrd, Kafka.class, KafkaList.class).withInitialInstances(Collections.singleton(cluster)).end().withCustomResourceDefinition(Crds.strimziPodSet(), StrimziPodSet.class, StrimziPodSetList.class).end().build();
    PlatformFeaturesAvailability pfa = new PlatformFeaturesAvailability(true, kubernetesVersion);
    ResourceOperatorSupplier supplier = supplierWithMocks();
    ClusterOperatorConfig config = ResourceUtils.dummyClusterOperatorConfig(VERSIONS);
    operator = new KafkaAssemblyOperator(vertx, pfa, new MockCertManager(), new PasswordGenerator(10, "a", "a"), supplier, config);
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) MockKube(io.strimzi.test.mockkube.MockKube) MockCertManager(io.strimzi.operator.common.operator.MockCertManager) GenericKafkaListenerBuilder(io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition) PasswordGenerator(io.strimzi.operator.common.PasswordGenerator) KafkaBuilder(io.strimzi.api.kafka.model.KafkaBuilder) StrimziPodSetList(io.strimzi.api.kafka.StrimziPodSetList)

Aggregations

MockKube (io.strimzi.test.mockkube.MockKube)42 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)22 HashMap (java.util.HashMap)20 Test (org.junit.jupiter.api.Test)20 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)18 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)16 AdminClientConfig (org.apache.kafka.clients.admin.AdminClientConfig)16 BeforeEach (org.junit.jupiter.api.BeforeEach)14 CustomResourceDefinition (io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition)10 PasswordGenerator (io.strimzi.operator.common.PasswordGenerator)10 Reconciliation (io.strimzi.operator.common.Reconciliation)10 MockCertManager (io.strimzi.operator.common.operator.MockCertManager)10 KafkaList (io.strimzi.api.kafka.KafkaList)8 StrimziPodSetList (io.strimzi.api.kafka.StrimziPodSetList)8 Kafka (io.strimzi.api.kafka.model.Kafka)8 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)8 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)8 Checkpoint (io.vertx.junit5.Checkpoint)8 Properties (java.util.Properties)7 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)6