Example #1
0
        public static void doMainSetup(TestContext context)
        {
            Util.COut("\n\n\nRUNNING: NetworkConfigIT.\n");

            TestUtils.TestUtils.ResetConfig();
            configHelper.CustomizeConfig();

            // Use the appropriate TLS/non-TLS network config file
            networkConfig = NetworkConfig.FromYamlFile(testConfig.GetTestNetworkConfigFileYAML());

            networkConfig.OrdererNames.ForEach(ordererName =>
            {
                try
                {
                    Properties ordererProperties = networkConfig.GetOrdererProperties(ordererName);
                    Properties testProp          = testConfig.GetEndPointProperties("orderer", ordererName);
                    ordererProperties.Set("clientCertFile", testProp.Get("clientCertFile"));
                    ordererProperties.Set("clientKeyFile", testProp.Get("clientKeyFile"));
                    networkConfig.SetOrdererProperties(ordererName, ordererProperties);
                }
                catch (ArgumentException e)
                {
                    throw new System.Exception(e.Message, e);
                }
            });

            networkConfig.PeerNames.ForEach(peerName =>
            {
                try
                {
                    Properties peerProperties = networkConfig.GetPeerProperties(peerName);
                    Properties testProp       = testConfig.GetEndPointProperties("peer", peerName);
                    peerProperties.Set("clientCertFile", testProp.Get("clientCertFile"));
                    peerProperties.Set("clientKeyFile", testProp.Get("clientKeyFile"));
                    networkConfig.SetPeerProperties(peerName, peerProperties);
                }
                catch (ArgumentException e)
                {
                    throw new System.Exception(e.Message, e);
                }
            });

            networkConfig.EventHubNames.ForEach(eventhubName =>
            {
                try
                {
                    Properties eventHubsProperties = networkConfig.GetEventHubsProperties(eventhubName);
                    Properties testProp            = testConfig.GetEndPointProperties("peer", eventhubName);
                    eventHubsProperties.Set("clientCertFile", testProp.Get("clientCertFile"));
                    eventHubsProperties.Set("clientKeyFile", testProp.Get("clientKeyFile"));
                    networkConfig.SetEventHubProperties(eventhubName, eventHubsProperties);
                }
                catch (ArgumentException e)
                {
                    throw new System.Exception(e.Message, e);
                }
            });

            //Check if we get access to defined CAs!
            NetworkConfig.OrgInfo org    = networkConfig.GetOrganizationInfo("Org1");
            NetworkConfig.CAInfo  caInfo = org.CertificateAuthorities[0];

            HFCAClient hfcaClient = HFCAClient.Create(caInfo);

            Assert.AreEqual(hfcaClient.CAName, caInfo.CAName);
            HFCAInfo info = hfcaClient.Info(); //makes actual REST call.

            Assert.AreEqual(caInfo.CAName, info.CAName);

            List <NetworkConfig.UserInfo> registrars = caInfo.Registrars;

            Assert.IsTrue(registrars.Count > 0);
            NetworkConfig.UserInfo registrar = registrars.First();
            registrar.Enrollment = hfcaClient.Enroll(registrar.Name, registrar.EnrollSecret);
            TestUtils.TestUtils.MockUser mockuser = TestUtils.TestUtils.GetMockUser(org.Name + "_mock_" + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), registrar.MspId);
            RegistrationRequest          rr       = new RegistrationRequest(mockuser.Name, "org1.department1");

            mockuser.EnrollmentSecret = hfcaClient.Register(rr, registrar);
            mockuser.Enrollment       = hfcaClient.Enroll(mockuser.Name, mockuser.EnrollmentSecret);
            orgRegisteredUsers.Add(org.Name, mockuser);

            org    = networkConfig.GetOrganizationInfo("Org2");
            caInfo = org.CertificateAuthorities[0];

            hfcaClient = HFCAClient.Create(caInfo);
            Assert.AreEqual(hfcaClient.CAName, caInfo.CAName);
            info = hfcaClient.Info(); //makes actual REST call.
            Assert.AreEqual(info.CAName, "");

            registrars = caInfo.Registrars;
            Assert.IsTrue(registrars.Count > 0);
            registrar            = registrars.First();
            registrar.Enrollment = hfcaClient.Enroll(registrar.Name, registrar.EnrollSecret);
            mockuser             = TestUtils.TestUtils.GetMockUser(org.Name + "_mock_" + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), registrar.MspId);
            rr = new RegistrationRequest(mockuser.Name, "org1.department1");
            mockuser.EnrollmentSecret = hfcaClient.Register(rr, registrar);
            mockuser.Enrollment       = hfcaClient.Enroll(mockuser.Name, mockuser.EnrollmentSecret);
            orgRegisteredUsers.Add(org.Name, mockuser);

            DeployChaincodeIfRequired();
        }
Example #2
0
        public void TestLoadFromConfigFileYamlOverrides()
        {
            // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration
            string        f      = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate());
            NetworkConfig config = NetworkConfig.FromYamlFile(f);

            foreach (string peerName in config.PeerNames)
            {
                Properties peerProperties = config.GetPeerProperties(peerName);

                //example of setting keepAlive to avoid timeouts on inactive http2 connections.
                // Under 5 minutes would require changes to server side to accept faster ping rates.
                peerProperties.Set("grpc.keepalive_time_ms", 5 * 60 * 1000);
                peerProperties.Set("grpc.keepalive_timeout_ms", 8 * 1000);
//            peerProperties.Set("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", "true");
                config.SetPeerProperties(peerName, peerProperties);
            }

            foreach (string orderName in config.OrdererNames)
            {
                Properties ordererProperties = config.GetOrdererProperties(orderName);
                ordererProperties.Set("grpc.max_receive_message_length", 9000000);
                //ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[] {false});
                config.SetOrdererProperties(orderName, ordererProperties);
            }

            //HFClient client = HFClient.loadFromConfig(f);
            Assert.IsNotNull(config);

            HFClient client = HFClient.Create();

            client.CryptoSuite = Factory.Instance.GetCryptoSuite();
            client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID);

            Channel channel = client.LoadChannelFromConfig("foo", config);

            Assert.IsNotNull(channel);

            Assert.IsTrue(channel.Peers.Count > 0);

            foreach (Peer peer in channel.Peers)
            {
                Properties properties = peer.Properties;

                Assert.IsNotNull(properties);
                Assert.IsNotNull(properties.Get("grpc.keepalive_time_ms"));
                Assert.IsNotNull(properties.Get("grpc.keepalive_timeout_ms"));
                //Assert.IsNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls"));

                Endpoint      ep               = new Endpoint(peer.Url, properties);
                ChannelOption keepalive        = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.keepalive_time_ms");
                ChannelOption keepalivetimeout = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.keepalive_timeout_ms");
                Assert.IsNotNull(keepalive);
                Assert.IsNotNull(keepalivetimeout);
                Assert.AreEqual(5 * 60 * 1000, keepalive.IntValue);
                Assert.AreEqual(8 * 1000, keepalivetimeout.IntValue);
            }

            foreach (Orderer orderer in channel.Orderers)
            {
                Properties properties = orderer.Properties;

                Assert.IsNotNull(properties);
                Assert.IsNotNull(properties.Get("grpc.max_receive_message_length"));
                //Assert.IsNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls"));

                Endpoint      ep    = new Endpoint(orderer.Url, properties);
                ChannelOption msize = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.max_receive_message_length");
                Assert.IsNotNull(msize);
                Assert.AreEqual(9000000, msize.IntValue);
            }
        }