use of io.strimzi.api.kafka.model.KafkaUserBuilder in project strimzi by strimzi.
the class KafkaUserModelTest method testFromCrdScramShaUserWithPasswordParsing.
@Test
public void testFromCrdScramShaUserWithPasswordParsing() {
KafkaUser user = new KafkaUserBuilder(scramShaUser).editSpec().withNewKafkaUserScramSha512ClientAuthentication().withNewPassword().withNewValueFrom().withNewSecretKeyRef("my-password", "my-secret", false).endValueFrom().endPassword().endKafkaUserScramSha512ClientAuthentication().endSpec().build();
KafkaUserModel model = KafkaUserModel.fromCrd(user, UserOperatorConfig.DEFAULT_SECRET_PREFIX, UserOperatorConfig.DEFAULT_STRIMZI_ACLS_ADMIN_API_SUPPORTED);
assertThat(model.isUserWithDesiredPassword(), is(true));
assertThat(model.desiredPasswordSecretKey(), is("my-password"));
assertThat(model.desiredPasswordSecretName(), is("my-secret"));
}
use of io.strimzi.api.kafka.model.KafkaUserBuilder in project strimzi by strimzi.
the class KafkaUserModelTest method testGenerateSecretWithMetadataOverrides.
@Test
public void testGenerateSecretWithMetadataOverrides() {
KafkaUser userWithTemplate = new KafkaUserBuilder(tlsUser).editSpec().withNewTemplate().withNewSecret().withNewMetadata().withLabels(singletonMap("label1", "value1")).withAnnotations(singletonMap("anno1", "value1")).endMetadata().endSecret().endTemplate().endSpec().build();
KafkaUserModel model = KafkaUserModel.fromCrd(userWithTemplate, UserOperatorConfig.DEFAULT_SECRET_PREFIX, UserOperatorConfig.DEFAULT_STRIMZI_ACLS_ADMIN_API_SUPPORTED);
model.maybeGenerateCertificates(Reconciliation.DUMMY_RECONCILIATION, mockCertManager, passwordGenerator, clientsCaCert, clientsCaKey, null, 365, 30);
Secret generatedSecret = model.generateSecret();
assertThat(generatedSecret.getData().keySet(), is(set("ca.crt", "user.crt", "user.key", "user.p12", "user.password")));
assertThat(generatedSecret.getMetadata().getName(), is(ResourceUtils.NAME));
assertThat(generatedSecret.getMetadata().getNamespace(), is(ResourceUtils.NAMESPACE));
assertThat(generatedSecret.getMetadata().getLabels(), is(Labels.fromMap(ResourceUtils.LABELS).withStrimziKind(KafkaUser.RESOURCE_KIND).withKubernetesName(KafkaUserModel.KAFKA_USER_OPERATOR_NAME).withKubernetesInstance(ResourceUtils.NAME).withKubernetesPartOf(ResourceUtils.NAME).withKubernetesManagedBy(KafkaUserModel.KAFKA_USER_OPERATOR_NAME).withAdditionalLabels(singletonMap("label1", "value1")).toMap()));
assertThat(generatedSecret.getMetadata().getAnnotations(), is(singletonMap("anno1", "value1")));
// Check owner reference
checkOwnerReference(model.createOwnerReference(), generatedSecret);
}
use of io.strimzi.api.kafka.model.KafkaUserBuilder in project strimzi by strimzi.
the class KafkaUserModelTest method testGenerateSecretUseDesiredPasswordIsEmpty.
@Test
public void testGenerateSecretUseDesiredPasswordIsEmpty() {
KafkaUser user = new KafkaUserBuilder(scramShaUser).editSpec().withNewKafkaUserScramSha512ClientAuthentication().withNewPassword().withNewValueFrom().withNewSecretKeyRef("my-password", "my-secret", false).endValueFrom().endPassword().endKafkaUserScramSha512ClientAuthentication().endSpec().build();
Secret desiredPasswordSecret = new SecretBuilder().withNewMetadata().withName("my-secret").endMetadata().addToData("my-password", Base64.getEncoder().encodeToString("".getBytes(StandardCharsets.UTF_8))).build();
KafkaUserModel model = KafkaUserModel.fromCrd(user, UserOperatorConfig.DEFAULT_SECRET_PREFIX, UserOperatorConfig.DEFAULT_STRIMZI_ACLS_ADMIN_API_SUPPORTED);
InvalidResourceException e = assertThrows(InvalidResourceException.class, () -> {
model.maybeGeneratePassword(Reconciliation.DUMMY_RECONCILIATION, passwordGenerator, null, desiredPasswordSecret);
});
assertThat(e.getMessage(), is("The requested user password is empty."));
}
use of io.strimzi.api.kafka.model.KafkaUserBuilder in project strimzi by strimzi.
the class KafkaUserModelTest method testFromCrdTlsUserWith65CharTlsUsernameThrows.
@Test
public void testFromCrdTlsUserWith65CharTlsUsernameThrows() {
KafkaUser tooLong = new KafkaUserBuilder(tlsUser).editMetadata().withName("User-123456789012345678901234567890123456789012345678901234567890").endMetadata().build();
assertThrows(InvalidResourceException.class, () -> {
// 65 characters => Should throw exception with TLS
KafkaUserModel.fromCrd(tooLong, UserOperatorConfig.DEFAULT_SECRET_PREFIX, UserOperatorConfig.DEFAULT_STRIMZI_ACLS_ADMIN_API_SUPPORTED);
});
}
use of io.strimzi.api.kafka.model.KafkaUserBuilder in project strimzi by strimzi.
the class KafkaUserModelTest method testFromCrdScramShaUserWith65CharSaslUsernameValid.
@Test
public void testFromCrdScramShaUserWith65CharSaslUsernameValid() {
// 65 characters => should work with SCRAM-SHA-512
KafkaUser tooLong = new KafkaUserBuilder(scramShaUser).editMetadata().withName("User-123456789012345678901234567890123456789012345678901234567890").endMetadata().build();
KafkaUserModel.fromCrd(tooLong, UserOperatorConfig.DEFAULT_SECRET_PREFIX, UserOperatorConfig.DEFAULT_STRIMZI_ACLS_ADMIN_API_SUPPORTED);
}
Aggregations