use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class SslValidatorTest method givenACreationUsingCertificateFromNonexistentSecretKey_shouldFail.
@Test
void givenACreationUsingCertificateFromNonexistentSecretKey_shouldFail() {
final StackGresClusterReview review = getCreationReview();
when(secretFinder.findByNameAndNamespace("secret1", "default")).thenReturn(Optional.of(secret1));
prepareForSsl(review);
review.getRequest().getObject().getSpec().getPostgres().getSsl().getCertificateSecretKeySelector().setKey("test1");
ValidationUtils.assertValidationFailed(() -> validator.validate(review), ErrorType.INVALID_CR_REFERENCE, "Certificate Secret secret1 or key test1 not found");
verify(secretFinder, times(1)).findByNameAndNamespace("secret1", "default");
verify(secretFinder, times(0)).findByNameAndNamespace("secret2", "default");
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class StorageClassValidatorTest method giveAnAttemptToUpdateToAKnownStorageClass_shouldNotFail.
@Test
void giveAnAttemptToUpdateToAKnownStorageClass_shouldNotFail() throws ValidationFailed {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/storage_class_config_update.json", StackGresClusterReview.class);
String storageClass = review.getRequest().getObject().getSpec().getPod().getPersistentVolume().getStorageClass();
when(storageClassFinder.findByName(storageClass)).thenReturn(Optional.of(DEFAULT_STORAGE_CLASS));
validator.validate(review);
verify(storageClassFinder).findByName(eq(storageClass));
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class StorageClassValidatorTest method giveInvalidStorageClassOnCreation_shouldFail.
@Test
void giveInvalidStorageClassOnCreation_shouldFail() {
final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/valid_creation.json", StackGresClusterReview.class);
String storageClass = review.getRequest().getObject().getSpec().getPod().getPersistentVolume().getStorageClass();
when(storageClassFinder.findByName(storageClass)).thenReturn(Optional.empty());
ValidationFailed ex = assertThrows(ValidationFailed.class, () -> {
validator.validate(review);
});
String resultMessage = ex.getMessage();
assertEquals("Storage class " + storageClass + " not found", resultMessage);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method validScriptFromConfigMapAndSecret_shouldFail.
@Test
void validScriptFromConfigMapAndSecret_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setConfigMapKeyRef(new ConfigMapKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setName("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getConfigMapKeyRef().setKey("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setSecretKeyRef(new SecretKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setName("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setKey("test");
checkErrorCause(StackGresClusterScriptFrom.class, new String[] { "spec.initData.scripts[0].scriptFrom.secretKeyRef", "spec.initData.scripts[0].scriptFrom.configMapKeyRef" }, "isSecretKeySelectorAndConfigMapKeySelectorMutuallyExclusiveAndRequired", review, AssertTrue.class);
}
use of io.stackgres.operator.common.StackGresClusterReview in project stackgres by ongres.
the class ClusterConstraintValidatorTest method scriptFromSecretWithEmptyKey_shouldFail.
@Test
void scriptFromSecretWithEmptyKey_shouldFail() {
StackGresClusterReview review = getValidReview();
review.getRequest().getObject().getSpec().setInitData(new StackGresClusterInitData());
review.getRequest().getObject().getSpec().getInitData().setScripts(new ArrayList<>());
review.getRequest().getObject().getSpec().getInitData().getScripts().add(new StackGresClusterScriptEntry());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).setScriptFrom(new StackGresClusterScriptFrom());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().setSecretKeyRef(new SecretKeySelector());
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setName("test");
review.getRequest().getObject().getSpec().getInitData().getScripts().get(0).getScriptFrom().getSecretKeyRef().setKey("");
checkErrorCause(SecretKeySelector.class, "spec.initData.scripts[0].scriptFrom.secretKeyRef.key", "isKeyNotEmpty", review, AssertTrue.class);
}
Aggregations