public void GetTransferRecordWithNullRequiredFieldsTest() { using var cryptoManager = new CryptoProvider(); var hashProvider = new HashUtils(EnvId, false, Encoding.UTF8); var transformer = new DtoTransformer(cryptoManager, hashProvider); var exception = Assert.Throws <StorageServerException>(() => transformer.GetRecord(new TransferRecord(null))); Assert.AreEqual("Null required record fields: recordKey", exception.Message); exception = Assert.Throws <StorageServerException>(() => transformer.GetRecord(new TransferRecord("recordKey"))); Assert.AreEqual("Null required record fields: body", exception.Message); }
public void GetSecretsDataNegativeTest() { using var cryptoManager = new CryptoProvider(); var hashProvider = new HashUtils(EnvId, false, Encoding.UTF8); const string errorMessage = "testError"; var transformer = new DtoTransformer(cryptoManager, hashProvider, true, () => throw new StorageClientException(errorMessage)); var exception = Assert.Throws <StorageClientException>(() => transformer.GetRecord(new TransferRecord("recordKey", "recordBody"))); Assert.AreEqual(errorMessage, exception.Message); transformer = new DtoTransformer(cryptoManager, hashProvider, true, () => throw new NotImplementedException()); exception = Assert.Throws <StorageClientException>(() => transformer.GetRecord(new TransferRecord("recordKey", "recordBody"))); Assert.AreEqual("Unexpected error", exception.Message); Assert.IsNotNull(exception.InnerException); Assert.IsInstanceOf <NotImplementedException>(exception.InnerException); transformer = new DtoTransformer(cryptoManager, hashProvider, true, () => null); exception = Assert.Throws <StorageClientException>(() => transformer.GetRecord(new TransferRecord("recordKey", "recordBody"))); Assert.AreEqual("Secret accessor returns null secret", exception.Message); }
public void GetRecordFromNullTest() { using var cryptoManager = new CryptoProvider(); var hashProvider = new HashUtils(EnvId, false, Encoding.UTF8); var transformer = new DtoTransformer(cryptoManager, hashProvider); var record = transformer.GetRecord(null); Assert.IsNull(record); }
public async Task <Record> ReadAsync(string country, string recordKey) { s_helper.Check <StorageClientException>(string.IsNullOrEmpty(recordKey), Messages.Storage.s_errNullRecordKey); var transferRecord = await _dao.ReadRecordAsync(country?.ToLowerInvariant(), _hashUtils.GetSha256Hash(recordKey)) .ConfigureAwait(false); return(_transformer.GetRecord(transferRecord)); }
public void GetTransferRecordWithNullBodyTest() { const string recordKey = "someRecordKey"; var record = new Record(recordKey); using var cryptoManager = new CryptoProvider(); var hashProvider = new HashUtils(EnvId, false, Encoding.UTF8); var transformer = new DtoTransformer(cryptoManager, hashProvider); var transferRecord = transformer.GetTransferRecord(record); Assert.NotNull(transferRecord); Assert.AreEqual("6717f3b00ef569e5604566335ff0b10a58a236a07a066372ede034ed5b732690", transferRecord.RecordKey); Assert.NotNull(transferRecord.Body); var restoredRecord = transformer.GetRecord(transferRecord); Assert.NotNull(restoredRecord); Assert.AreEqual(recordKey, restoredRecord.RecordKey); Assert.IsNull(restoredRecord.Body); }