public async Task GivenKeyVaultSecretStore_WhenGettingSecretThrowsKeyVaultErrorExceptionWithNonRetriableStatusCode_ThenItWillNotBeRetried(HttpStatusCode statusCode) { _retryCount = 3; _secretStore = GetSecretStore(_retryCount); AzureOperationResponse <SecretBundle> successfulResult = GetSuccessfulResult(); var exception = GetKeyVaultError(statusCode); _kvClient.GetSecretWithHttpMessagesAsync(_keyVaultUri.AbsoluteUri, SecretName, secretVersion: string.Empty, customHeaders: null, _cancellationToken) .Returns <AzureOperationResponse <SecretBundle> >( _ => throw exception, _ => successfulResult); await Assert.ThrowsAsync <SecretStoreException>(() => _secretStore.GetSecretAsync(SecretName, _cancellationToken)); }
public async Task GivenKeyVaultSecretStore_WhenDeletingSecretThrowsKeyVaultErrorExceptionWithNoResponse_ThenExceptionWillBeThrownWithInternalServerErrorStatusCode() { _retryCount = 0; _secretStore = GetSecretStore(_retryCount); KeyVaultErrorException exception = new KeyVaultErrorException(); _kvClient.DeleteSecretWithHttpMessagesAsync(_keyVaultUri.AbsoluteUri, SecretName, customHeaders: null, _cancellationToken) .Returns <AzureOperationResponse <DeletedSecretBundle> >( _ => throw exception); SecretStoreException sse = await Assert.ThrowsAsync <SecretStoreException>(() => _secretStore.DeleteSecretAsync(SecretName, _cancellationToken)); Assert.NotNull(sse); Assert.Equal(HttpStatusCode.InternalServerError, sse.ResponseStatusCode); }
public async Task GivenKeyVaultSecretStore_WhenSettingSecretThrowsKeyVaultErrorException_ThenExceptionWillBeThrownWithAppropriateStatusCode(HttpStatusCode keyVaultStatusCode, HttpStatusCode expectedStatusCode) { _retryCount = 0; _secretStore = GetSecretStore(_retryCount); KeyVaultErrorException exception = GetKeyVaultError(keyVaultStatusCode); _kvClient.SetSecretWithHttpMessagesAsync(_keyVaultUri.AbsoluteUri, SecretName, SecretValue, tags: null, contentType: null, secretAttributes: null, customHeaders: null, _cancellationToken) .Returns <AzureOperationResponse <SecretBundle> >( _ => throw exception); SecretStoreException sse = await Assert.ThrowsAsync <SecretStoreException>(() => _secretStore.SetSecretAsync(SecretName, SecretValue, _cancellationToken)); Assert.NotNull(sse); Assert.Equal(expectedStatusCode, sse.ResponseStatusCode); }
public async Task GivenKeyVaultSecretStore_WhenDeletingSecretThrowsKeyVaultErrorExceptionWithRetriableStatusCodeForMaxRetryCount_ThenExceptionWillBeThrown() { _retryCount = 2; _secretStore = GetSecretStore(_retryCount); var successfulResult = GetSuccessfulDeletedResult(); KeyVaultErrorException exception = GetKeyVaultError(HttpStatusCode.ServiceUnavailable); _kvClient.DeleteSecretWithHttpMessagesAsync(_keyVaultUri.AbsoluteUri, SecretName, customHeaders: null, _cancellationToken) .Returns <AzureOperationResponse <DeletedSecretBundle> >( _ => throw exception, _ => throw exception, _ => throw exception, _ => successfulResult); await Assert.ThrowsAsync <SecretStoreException>(() => _secretStore.DeleteSecretAsync(SecretName, _cancellationToken)); }
public async Task GivenKeyVaultSecretStore_WhenDeletingSecretThrowsKeyVaultErrorExceptionWithRetriableStatusCode_ThenItWillBeRetried(HttpStatusCode statusCode) { _retryCount = 3; _secretStore = GetSecretStore(_retryCount); var successfulResult = GetSuccessfulDeletedResult(); KeyVaultErrorException exception = GetKeyVaultError(statusCode); _kvClient.DeleteSecretWithHttpMessagesAsync(_keyVaultUri.AbsoluteUri, SecretName, customHeaders: null, _cancellationToken) .Returns <AzureOperationResponse <DeletedSecretBundle> >( _ => throw exception, _ => throw exception, _ => successfulResult); var result = await _secretStore.DeleteSecretAsync(SecretName, _cancellationToken); Assert.Null(result.SecretValue); }