public void RemveKeyWithInvalidValidatorShouldFail() { string validator = "0x00000005476534"; string pubKey = "TREHXCAVSOYJULSDVGFDs="; JsonPublicKeySource pubKeySourceObj = new JsonPublicKeySource(); string randFileName = JsonPublicKeySourceTests.RandomString(6) + ".json"; pubKeySourceObj.LoadFromFile(randFileName, true); //Independently adding key for removal test pubKeySourceObj.AddKey(validator, pubKey); ConfigurationBuilder cb = new ConfigurationBuilder(); string[] args = { "test", validator }; IConfigurationRoot configObj = cb.AddCommandLine(args).Build(); KeyManagement km = new KeyManagement(configObj, pubKeySourceObj); km.ProcessKeyCommand("remove"); //check the keys should not be removed pubKeySourceObj.GetKeyForNode(validator).Should().Be(pubKey); //removing temp file File.Delete(randFileName); }
public void RemveKeyWithValidValidatorShouldPass() { string validator = "0x00000005476534"; string pubKey = "TREHXCAVSOYJULSDVGFDs="; JsonPublicKeySource pubKeySourceObj = new JsonPublicKeySource(); string randFileName = JsonPublicKeySourceTests.RandomString(6) + ".json"; pubKeySourceObj.LoadFromFile(randFileName, true); //Independently adding key for removal test pubKeySourceObj.AddKey(validator, pubKey); ConfigurationBuilder cb = new ConfigurationBuilder(); string[] args = { "--validator", validator }; IConfigurationRoot configObj = cb.AddCommandLine(args).Build(); KeyManagement km = new KeyManagement(configObj, pubKeySourceObj); km.ProcessKeyCommand("remove"); //check the keys should be removed var exception = Assert.Throws <KeyNotFoundException>(() => pubKeySourceObj.GetKeyForNode(validator)); Assert.NotNull(exception); exception.Message.Should().Contain("Public key not available"); //removing temp file File.Delete(randFileName); }
public void AddKeyShouldPassWithValidArgs() { string validator = "0x0000000965"; string pubKey = "ASDFASdFFDJDY4356SDFGFDs="; JsonPublicKeySource pubKeySourceObj = new JsonPublicKeySource(); string randFileName = JsonPublicKeySourceTests.RandomString(6) + ".json"; pubKeySourceObj.LoadFromFile(randFileName, true); ConfigurationBuilder cb = new ConfigurationBuilder(); string[] args = { "--validator", validator, "--publickey", pubKey }; IConfigurationRoot configObj = cb.AddCommandLine(args).Build(); KeyManagement km = new KeyManagement(configObj, pubKeySourceObj); km.ProcessKeyCommand("add"); //Now check file independently that key Registration was success JsonPublicKeySource obj = new JsonPublicKeySource(); obj.LoadFromFile(randFileName, true); string key = obj.GetKeyForNode(validator); Assert.Equal(key, pubKey); //removing temp file File.Delete(randFileName); }
public void PublicKeySourceNullPathShouldFail() { JsonPublicKeySource obj = new JsonPublicKeySource(); var exception = Assert.Throws <ArgumentNullException>(() => obj.LoadFromFile("")); Assert.NotNull(exception); Assert.Contains("path can't be null or empty", exception.Message); }
public void PublicKeySourceNoFileShouldFail() { JsonPublicKeySource obj = new JsonPublicKeySource(); var exception = Assert.Throws <ArgumentException>(() => obj.LoadFromFile("\\etc\\file.json")); Assert.NotNull(exception); Assert.Contains("No file at path: ", exception.Message); }
public void CreateFileFileShouldPass() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; obj.LoadFromFile(randFileName, true); Assert.True(File.Exists(randFileName)); //removing temp file File.Delete(randFileName); }
public void SaveToFileNoFileExistFail() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; obj.LoadFromFile(randFileName, true); File.Delete(randFileName); var exceptionStf = Assert.Throws <FileNotFoundException>(() => obj.SaveToFile()); Assert.NotNull(exceptionStf); Assert.Contains("Source file no longer exists.", exceptionStf.Message); }
public void ProgramKeyCommandShouldPass() { string validator = "0x0000000965"; string pubKey = "ASDFASdFFDJDY4356SDFGFDs="; string[] args = { "--keycmd", "add", "--validator", validator, "--publickey", pubKey }; Program.Main(args); JsonPublicKeySource obj = new JsonPublicKeySource(); obj.LoadFromFile("keyfile.json", true); string key = obj.GetKeyForNode(validator); Assert.Equal(key, pubKey); }
public void ZeroKeysShouldFail() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; File.WriteAllText(randFileName, "[]"); var exception = Assert.Throws <KeyLoadException>(() => obj.LoadFromFile(randFileName)); Assert.NotNull(exception); Assert.Contains("JSON contains no keys", exception.Message); //removing temp file File.Delete(randFileName); }
public void InvalidKeysShouldFail() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; File.WriteAllText(randFileName, "{nodewe=w1"); var exception = Assert.Throws <KeyLoadException>(() => obj.LoadFromFile(randFileName)); Assert.NotNull(exception); Assert.Contains("Unable to load keys from json", exception.Message); //removing temp file File.Delete(randFileName); }
public void EmptyFileShouldFail() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; File.WriteAllText(randFileName, ""); var exception = Assert.Throws <FileEmptyException>(() => obj.LoadFromFile(randFileName)); Assert.NotNull(exception); Assert.Contains("is empty", exception.Message); //removing temp file File.Delete(randFileName); }
public void GetKeyForNodeShouldPasslForKeyFound() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; File.WriteAllText(randFileName, "[ {\"nodeid\": \"node-3\",\"key\": \"BdrwegfSDFG=\"},{\"nodeid\": \"node-12\",\"key\": \"BgIA345nlikrwegfSDFG=\"}]"); obj.LoadFromFile(randFileName, true); string key = obj.GetKeyForNode("node-12"); Assert.Equal("BgIA345nlikrwegfSDFG=", key); //removing temp file File.Delete(randFileName); }
public void InvalidArgsShouldFail(string command) { JsonPublicKeySource pubKeySourceObj = new JsonPublicKeySource(); string randFileName = JsonPublicKeySourceTests.RandomString(6) + ".json"; pubKeySourceObj.LoadFromFile(randFileName, true); KeyManagement km = new KeyManagement(null, null); km.ProcessKeyCommand(command); string fileData = File.ReadAllText(randFileName); //there is no change in pub key data file fileData.Should().Contain("[]"); //removing temp file File.Delete(randFileName); }
public void AddKeyShouldFailWithoutValidator() { JsonPublicKeySource pubKeySourceObj = new JsonPublicKeySource(); string randFileName = JsonPublicKeySourceTests.RandomString(6) + ".json"; pubKeySourceObj.LoadFromFile(randFileName, true); IConfigurationRoot configObj = new ConfigurationBuilder().Build(); KeyManagement km = new KeyManagement(configObj, pubKeySourceObj); km.ProcessKeyCommand("add"); string fileData = File.ReadAllText(randFileName); fileData.Should().Contain("[]"); //removing temp file File.Delete(randFileName); }
public void GetKeyForNodeShouldFailForKeyNotFound() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; File.WriteAllText(randFileName, "[ {\"nodeid\": \"node-3\",\"key\": \"BgIA345nlikrwegfSDFG=\"}]"); obj.LoadFromFile(randFileName, true); var exception = Assert.Throws <KeyNotFoundException>(() => obj.GetKeyForNode("Node-12")); Assert.NotNull(exception); Assert.Contains("Public key not available", exception.Message); //removing temp file File.Delete(randFileName); }
public void AddRemoveKeyShouldPassAndNonExistintKeyShouldFail() { JsonPublicKeySource obj = new JsonPublicKeySource(); string randFileName = RandomString(6) + ".json"; obj.LoadFromFile(randFileName, true); string nodeId = "0x00000000012"; string pubKey = "SADDFAJIONJKASD234ASDASNK34234="; obj.AddKey(nodeId, pubKey); string key = obj.GetKeyForNode(nodeId); Assert.Equal(key, pubKey); string nodeId2 = "0x00000000003"; string pubKey2 = "SASADDFAJIONJKASD234ASDASNK34234DDFAJIONJKASD234ASDASNK34234="; obj.AddKey(nodeId2, pubKey2); string key2 = obj.GetKeyForNode(nodeId2); Assert.Equal(key2, pubKey2); //now removing key obj.RemoveKey(nodeId2); //verifying that key is removed var exception = Assert.Throws <KeyNotFoundException>(() => obj.RemoveKey(nodeId2)); Assert.NotNull(exception); Assert.Contains("Node key is not known", exception.Message); //removing temp file File.Delete(randFileName); }