use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigSourceValidatorTest method givenNonExistentSecretAccessKeyKeyForS3CompatibleStorageCredentialsKeyOnCreation_shouldFail.
@Test
void givenNonExistentSecretAccessKeyKeyForS3CompatibleStorageCredentialsKeyOnCreation_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()));
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 s3compatible credentials not found", ex.getResult().getMessage());
verify(secretFinder).findByNameAndNamespace(eq(accessKeyIdName), eq(namespace));
verify(secretFinder).findByNameAndNamespace(eq(secretAccessKeyName), eq(namespace));
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigSourceValidatorTest method givenExistentSecretsAndKeysForAzureBlobStorageCredentialsOnCreation_shouldNotFail.
@Test
void givenExistentSecretsAndKeysForAzureBlobStorageCredentialsOnCreation_shouldNotFail() 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, ResourceUtil.encodeSecret("accessKey"))).build()));
validator.validate(review);
verify(secretFinder).findByNameAndNamespace(eq(accountName), eq(namespace));
verify(secretFinder).findByNameAndNamespace(eq(accessKeyName), eq(namespace));
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigSourceValidatorTest method givenNonExistentAccountKeyForAzureBlobStorageCredentialsOnCreation_shouldFail.
@Test
void givenNonExistentAccountKeyForAzureBlobStorageCredentialsOnCreation_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 + "-wrong", ResourceUtil.encodeSecret("account"))).build()));
ValidationFailed ex = ValidationUtils.assertErrorType(ErrorType.INVALID_SECRET, () -> validator.validate(review));
assertEquals("Invalid backup configuration, key " + accountKey + " of secret " + accountName + " for account of azureblob credentials not found", ex.getResult().getMessage());
verify(secretFinder).findByNameAndNamespace(eq(accountName), eq(namespace));
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigValidationPipelineTest method getConstraintViolatingReview.
@Override
public BackupConfigReview getConstraintViolatingReview() {
final BackupConfigReview review = JsonUtil.readFromJson("backupconfig_allow_request/create.json", BackupConfigReview.class);
review.getRequest().getObject().getSpec().getBaseBackups().setRetention(0);
return review;
}
use of io.stackgres.operator.common.BackupConfigReview in project stackgres by ongres.
the class BackupConfigConstraintValidationTest method nullSpec_shouldFail.
@Test
void nullSpec_shouldFail() {
BackupConfigReview review = getInvalidReview();
checkNotNullErrorCause(StackGresBackupConfig.class, "spec", review);
}
Aggregations