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