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 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 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); }