public void Constructor_ReadsConfigurationFromDisk() { // Arrange var path = Path.GetTempFileName() + ".json"; var existing = new List <HostKeyPair>() { new HostKeyPair { Host = "example0", PublicKey = new byte[] { 0, 0, 0 } }, new HostKeyPair { Host = "example1", PublicKey = new byte[] { 1, 1, 1 } }, new HostKeyPair { Host = "example2", PublicKey = new byte[] { 2, 2, 2 } }, }; var serializer = new DataContractJsonSerializer(typeof(List <HostKeyPair>)); using (var fileStream = File.OpenWrite(path)) { serializer.WriteObject(fileStream, existing); } // Act var instance = new FileSystemKeyStore(path); // Assert Assert.IsTrue(instance.MatchesExisting(existing[0].Host, existing[0].PublicKey)); Assert.IsTrue(instance.MatchesExisting(existing[1].Host, existing[1].PublicKey)); Assert.IsTrue(instance.MatchesExisting(existing[2].Host, existing[2].PublicKey)); }
public void Constructor_Path_ExpandsEnvironmentVariables() { // Arrange var tempDir = Environment.OSVersion.Platform == PlatformID.Win32Windows ? "%temp%" : "$TMPDIR"; // Act var instance = new FileSystemKeyStore(tempDir + @"\foo\pins.json"); // Assert Assert.AreEqual(Environment.ExpandEnvironmentVariables(tempDir) + @"\foo\pins.json", instance.Path); }
public async Task AutoSave_WhenInterval0_DoesNotAutoSave() { // Arrange var path = Path.GetTempFileName() + ".json"; var pk = new byte[] { 0, 1, 2, 3, 4 }; var instance = new FileSystemKeyStore(path); instance.PinForHost("jmaxxz.com", pk); // Act instance.AutoSaveInterval = TimeSpan.FromSeconds(0); await Task.Delay(2000); // Assert Assert.IsFalse(File.Exists(path)); }
public void Save_WritesConfigurationToDist() { // Arrange var path = Path.GetTempFileName() + ".json"; var pk = new byte[] { 0, 1, 2, 3, 4 }; var instance = new FileSystemKeyStore(path); instance.PinForHost("jmaxxz.com", pk); // Act instance.Save(); // Assert var secondInstance = new FileSystemKeyStore(path); secondInstance.Reload(); Assert.IsTrue(secondInstance.MatchesExisting("jmaxxz.com", pk)); }
public async Task AutoSave_OnInterval_CommitsToDisk() { // Arrange var path = Path.GetTempFileName() + ".json"; var pk = new byte[] { 0, 1, 2, 3, 4 }; var instance = new FileSystemKeyStore(path); instance.PinForHost("jmaxxz.com", pk); // Act instance.AutoSaveInterval = TimeSpan.FromSeconds(0.5); await Task.Delay(2000); // Assert var secondInstance = new FileSystemKeyStore(path); secondInstance.Reload(); Assert.IsTrue(secondInstance.MatchesExisting("jmaxxz.com", pk)); }