public Task StoreAsync(Credentials credentials) { m_storageProvider.ClearStorage(); using (var storage = m_storageProvider.GetStorage()) using (StreamWriter streamWriter = new StreamWriter(storage)) { var serializedCredentials = JsonConvert.SerializeObject(credentials); return(streamWriter.WriteAsync(serializedCredentials)); } }
public async Task CredentialsAreStored_StorageIsNotBeEmpty( [Frozen] ICredentialsStorageProvider storageProvider, Application.CredentialsNS.CredentialsRepository credentialsRepository) { // arrange var credentials = new Credentials("TestUsername", "TestPassword"); // act await credentialsRepository.StoreAsync(credentials); // assert storageProvider.GetStorage().Length.Should().BeGreaterThan(0, "credentials should have been stored"); }
public async Task CredentialsAreStored_CredentialsAreEncrypted( [Frozen] ICredentialsStorageProvider storageProvider, Application.CredentialsNS.CredentialsRepository credentialsRepository) { // arrange var credentials = new Credentials("TestUsername", "TestPassword"); // act await credentialsRepository.StoreAsync(credentials); // assert string credentialStorageAsString; using (var streamReader = new StreamReader(storageProvider.GetStorage())) { credentialStorageAsString = await streamReader.ReadToEndAsync(); } credentialStorageAsString.Should() .NotContainAny(new[] { credentials.Username, credentials.Password }, "Storing unencrypted credentials is unsafe"); }