Search in sources :

Example 6 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.

the class BackupConfigConstraintValidationTest method nullStorageType_shouldFail.

@Test
void nullStorageType_shouldFail() {
    BackupConfigReview review = getValidReview();
    review.getRequest().getObject().getSpec().getStorage().setType(null);
    checkNotNullErrorCause(BackupStorage.class, "spec.storage.type", review);
}
Also used : BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ConstraintValidationTest(io.stackgres.operator.validation.ConstraintValidationTest)

Example 7 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview 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 8 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview 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 9 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview 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 10 with BackupConfigReview

use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.

the class BackupConfigSourceValidatorTest method givenExistentSecretsAndKeysForS3StorageCredentialsOnCreation_shouldNotFail.

@Test
void givenExistentSecretsAndKeysForS3StorageCredentialsOnCreation_shouldNotFail() 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";
    setS3Credentials(review, accessKeyIdName, accessKeyIdKey, secretAccessKeyName, secretAccessKeyKey);
    when(secretFinder.findByNameAndNamespace(accessKeyIdName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(accessKeyIdKey, ResourceUtil.encodeSecret("accessKeyId"))).build()));
    when(secretFinder.findByNameAndNamespace(secretAccessKeyName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(secretAccessKeyKey, ResourceUtil.encodeSecret("secretAccessKey"))).build()));
    validator.validate(review);
    verify(secretFinder).findByNameAndNamespace(eq(accessKeyIdName), eq(namespace));
    verify(secretFinder).findByNameAndNamespace(eq(secretAccessKeyName), eq(namespace));
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview) Test(org.junit.jupiter.api.Test)

Aggregations

BackupConfigReview (io.stackgres.operator.common.BackupConfigReview)31 Test (org.junit.jupiter.api.Test)25 ValidationFailed (io.stackgres.operatorframework.admissionwebhook.validating.ValidationFailed)17 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ConstraintValidationTest (io.stackgres.operator.validation.ConstraintValidationTest)4 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)1 StackGresBackupConfigSpec (io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfigSpec)1 AwsS3Storage (io.stackgres.common.crd.storages.AwsS3Storage)1 BackupStorage (io.stackgres.common.crd.storages.BackupStorage)1 DefaultValuesMutatorTest (io.stackgres.operator.mutation.DefaultValuesMutatorTest)1 Random (java.util.Random)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1