Search in sources :

Example 16 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class ClusterConstraintValidatorTest method invalidNames_shouldFail.

@ParameterizedTest
@ValueSource(strings = { "stackgres.io/", "*9stackgres", "1143", "1143a", "-1143a", ".demo", "123-primary", "123-primary", "primary*", "stackgres-demo_1" })
void invalidNames_shouldFail(String name) {
    StackGresClusterReview review = getValidReview();
    review.getRequest().getObject().getMetadata().setName(name);
    ValidationFailed message = assertThrows(ValidationFailed.class, () -> validator.validate(review));
    assertEquals("Name must consist of lower case alphanumeric " + "characters or '-', start with an alphabetic character, " + "and end with an alphanumeric character", message.getMessage());
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class BackupConfigSourceValidatorTest method givenNonExistentAccessKeyIdKeyForS3CompatibleStorageCredentialsOnCreation_shouldFail.

@Test
void givenNonExistentAccessKeyIdKeyForS3CompatibleStorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
    final BackupConfigReview review = getEmptyReview();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    String accessKeyIdName = "secret1";
    String accessKeyIdKey = "key1";
    String secretAccessKeyName = "secret2";
    String secretAccessKeyKey = "key2";
    setS3CompatibleCredentials(review, accessKeyIdName, accessKeyIdKey, secretAccessKeyName, secretAccessKeyKey);
    when(secretFinder.findByNameAndNamespace(accessKeyIdName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(accessKeyIdKey + "-wrong", ResourceUtil.encodeSecret("accessKeyId"))).build()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, key " + accessKeyIdKey + " of secret " + accessKeyIdName + " for accessKeyId of s3compatible credentials not found", ex.getResult().getMessage());
    verify(secretFinder).findByNameAndNamespace(eq(accessKeyIdName), eq(namespace));
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Example 18 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class BackupConfigSourceValidatorTest method givenNonExistentAccessKeyIdSecretForS3StorageCredentialsOnCreation_shouldFail.

@Test
void givenNonExistentAccessKeyIdSecretForS3StorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
    final BackupConfigReview review = getEmptyReview();
    String accessKeyIdName = "secret1";
    String accessKeyIdKey = "key1";
    String secretAccessKeyName = "secret2";
    String secretAccessKeyKey = "key2";
    setS3Credentials(review, accessKeyIdName, accessKeyIdKey, secretAccessKeyName, secretAccessKeyKey);
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, secret " + accessKeyIdName + " for accessKeyId of s3 credentials not found", ex.getResult().getMessage());
}
Also used : ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Example 19 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class BackupConfigSourceValidatorTest method givenNonExistentServiceAccountJsonKeyKeyForGcsStorageCredentialsOnCreation_shouldFail.

@Test
void givenNonExistentServiceAccountJsonKeyKeyForGcsStorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
    final BackupConfigReview review = getEmptyReview();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    String serviceAccountJsonKeyName = "secret1";
    String serviceAccountJsonKeyKey = "key1";
    setGcsCredentials(review, serviceAccountJsonKeyName, serviceAccountJsonKeyKey);
    when(secretFinder.findByNameAndNamespace(serviceAccountJsonKeyName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(serviceAccountJsonKeyKey + "-wrong", ResourceUtil.encodeSecret("serviceAccountJsonKey"))).build()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, key " + serviceAccountJsonKeyKey + " of secret " + serviceAccountJsonKeyName + " for serviceAccountJsonKey of gcs credentials not found", ex.getResult().getMessage());
    verify(secretFinder).findByNameAndNamespace(eq(serviceAccountJsonKeyName), eq(namespace));
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Example 20 with ValidationFailed

use of io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed in project stackgres by ongres.

the class BackupConfigSourceValidatorTest method givenNonExistentSecretAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail.

@Test
void givenNonExistentSecretAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
    final BackupConfigReview review = getEmptyReview();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    String accountName = "secret1";
    String accountKey = "key1";
    String accessKeyName = "secret2";
    String accessKeyKey = "key2";
    setAzureBlobCredentials(review, accountName, accountKey, accessKeyName, accessKeyKey);
    when(secretFinder.findByNameAndNamespace(accountName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(accountKey, ResourceUtil.encodeSecret("account"))).build()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, secret " + accessKeyName + " for accessKey of azureblob credentials not found", ex.getResult().getMessage());
    verify(secretFinder).findByNameAndNamespace(eq(accountName), eq(namespace));
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ValidationFailed(io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)61 Test (org.junit.jupiter.api.Test)46 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)24 BackupConfigReview (io.stackgres.operator.common.BackupConfigReview)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)10 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)5 Status (io.fabric8.kubernetes.api.model.Status)4 StackGresPostgresConfig (io.stackgres.common.crd.sgpgconfig.StackGresPostgresConfig)4 StatusBuilder (io.fabric8.kubernetes.api.model.StatusBuilder)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 StatusDetailsBuilder (io.fabric8.kubernetes.api.model.StatusDetailsBuilder)2 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)2 PgConfigReview (io.stackgres.operator.common.PgConfigReview)2 StackGresDbOpsReview (io.stackgres.operator.common.StackGresDbOpsReview)2 Operation (io.stackgres.operatorframework.admissionwebhook.Operation)2 List (java.util.List)2 ImmutableList (com.google.common.collect.ImmutableList)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1