コード例 #1
0
 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));
         }
 }
コード例 #2
0
        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");
        }
コード例 #3
0
        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");
        }