Search in sources :

Example 16 with BackupConfigReview

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

the class BackupConfigSourceValidatorTest method givenNonExistentAccessKeyKeyForAzureBlobStorageCredentialsKeyOnCreation_shouldFail.

@Test
void givenNonExistentAccessKeyKeyForAzureBlobStorageCredentialsKeyOnCreation_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()));
    when(secretFinder.findByNameAndNamespace(accessKeyName, namespace)).thenReturn(Optional.of(new SecretBuilder(secret).withData(ImmutableMap.of(accessKeyKey + "-wrong", ResourceUtil.encodeSecret("accessKey"))).build()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, key " + accessKeyKey + " of secret " + accessKeyName + " for accessKey of azureblob credentials not found", ex.getResult().getMessage());
    verify(secretFinder).findByNameAndNamespace(eq(accountName), eq(namespace));
    verify(secretFinder).findByNameAndNamespace(eq(accessKeyName), 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 17 with BackupConfigReview

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

the class BackupConfigSourceValidatorTest method getEmptyReview.

private BackupConfigReview getEmptyReview() {
    BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/create.json", BackupConfigReview.class);
    review.getRequest().getObject().getSpec().setStorage(new BackupStorage());
    return review;
}
Also used : BackupStorage(io.stackgres.common.crd.storages.BackupStorage) BackupConfigReview(io.stackgres.operator.common.BackupConfigReview)

Example 18 with BackupConfigReview

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

the class BackupConfigSourceValidatorTest method givenNonExistentSecretAccessKeyKeyForS3StorageCredentialsKeyOnCreation_shouldFail.

@Test
void givenNonExistentSecretAccessKeyKeyForS3StorageCredentialsKeyOnCreation_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";
    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 + "-wrong", ResourceUtil.encodeSecret("secretAccessKey"))).build()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, key " + secretAccessKeyKey + " of secret " + secretAccessKeyName + " for secretAccessKey of s3 credentials not found", ex.getResult().getMessage());
    verify(secretFinder).findByNameAndNamespace(eq(accessKeyIdName), eq(namespace));
    verify(secretFinder).findByNameAndNamespace(eq(secretAccessKeyName), 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 19 with BackupConfigReview

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

the class BackupConfigSourceValidatorTest method givenNonExistentSecretAccessKeySecretForS3CompatibleStorageCredentialsOnCreation_shouldFail.

@Test
void givenNonExistentSecretAccessKeySecretForS3CompatibleStorageCredentialsOnCreation_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, ResourceUtil.encodeSecret("accessKeyId"))).build()));
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, secret " + secretAccessKeyName + " for secretAccessKey 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 20 with BackupConfigReview

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

the class BackupConfigSourceValidatorTest method givenNonExistentAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail.

@Test
void givenNonExistentAccountSecretForAzureBlobStorageCredentialsOnCreation_shouldFail() throws ValidationFailed {
    final BackupConfigReview review = getEmptyReview();
    String accountName = "secret1";
    String accountKey = "key1";
    String accessKeyName = "secret2";
    String accessKeyKey = "key2";
    setAzureBlobCredentials(review, accountName, accountKey, accessKeyName, accessKeyKey);
    ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
    assertEquals("Invalid backup configuration, secret " + accountName + " for account of azureblob 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)

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