public void LoadSignerKey_defaults_to_LoadNodeKey() { NodeKeyManagerTest test = CreateTest(); test.KeyStoreConfig.TestNodeKey = TestItem.PrivateKeyA.ToString(); test.NodeKeyManager.LoadSignerKey().Unprotect().Should().Be(TestItem.PrivateKeyA); }
public void LoadNodeKey_loads_key_for_EnodeAccount() { NodeKeyManagerTest test = CreateTest(); test.KeyStoreConfig.EnodeAccount = TestItem.AddressA.ToString(); test.PasswordProvider.GetPassword(TestItem.AddressA).Returns("p1".Secure()); test.KeyStore.GetProtectedKey(TestItem.AddressA, Arg.Any <SecureString>()).Returns( c => ((SecureString)c[1]).Unsecure() == "p1" ? (new ProtectedPrivateKey(TestItem.PrivateKeyA), Result.Success) : ((ProtectedPrivateKey)null, Result.Fail("nope"))); test.NodeKeyManager.LoadNodeKey().Unprotect().Should().Be(TestItem.PrivateKeyA); }
public void LoadNodeKey_loads_file(string filePath) { NodeKeyManagerTest test = CreateTest(); test.KeyStoreConfig.EnodeKeyFile = filePath; filePath ??= NodeKeyManager.UnsecuredNodeKeyFilePath; filePath = filePath.GetApplicationResourcePath(test.KeyStoreConfig.KeyStoreDirectory); test.FileSystem.File.ReadAllBytes(filePath).Returns(TestItem.PrivateKeyA.KeyBytes); test.FileSystem.File.Exists(filePath).Returns(true); PrivateKey nodeKey = test.NodeKeyManager.LoadNodeKey().Unprotect(); nodeKey.Should().Be(TestItem.PrivateKeyA); test.FileSystem.File.DidNotReceive().WriteAllBytes(filePath, nodeKey.KeyBytes); }
public void LoadNodeKey_creates_file(string filePath) { NodeKeyManagerTest test = CreateTest(); test.KeyStoreConfig.EnodeKeyFile = filePath; test.CryptoRandom.GenerateRandomBytes(32).Returns(TestItem.PrivateKeyA.KeyBytes); filePath ??= NodeKeyManager.UnsecuredNodeKeyFilePath; filePath = filePath.GetApplicationResourcePath(test.KeyStoreConfig.KeyStoreDirectory); test.FileSystem.File.ReadAllBytes(filePath).Returns(TestItem.PrivateKeyA.KeyBytes); PrivateKey nodeKey = test.NodeKeyManager.LoadNodeKey().Unprotect(); nodeKey.Should().Be(TestItem.PrivateKeyA); test.FileSystem.File.Received().WriteAllBytes(filePath, Arg.Is <byte[]>(a => a.SequenceEqual(nodeKey.KeyBytes))); }