public void HAAggregatorConfigRequestUsingEventHandlerTest()
        {
            // Test getting aggregator configuration with 1 successful and 2 unsuccessful sub-service responses.
            // Get response using AggregatorConfigChanged event handler

            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727638),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregatorConfigResponsePdu)), 1584727637),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637)
            },
                    null, null);

            ManualResetEvent waitHandle       = new ManualResetEvent(false);
            AggregatorConfig aggregatorConfig = null;

            haService.AggregatorConfigChanged += delegate(object sender, AggregatorConfigChangedEventArgs e)
            {
                aggregatorConfig = e.AggregatorConfig;
                waitHandle.Set();
            };
            haService.GetAggregatorConfig();
            waitHandle.WaitOne(1000);
            Assert.IsNotNull(aggregatorConfig, "Could not get aggregator config using event handler.");

            Assert.AreEqual(17, aggregatorConfig.MaxLevel, "Unexpected max level value");
            Assert.AreEqual(1, aggregatorConfig.AggregationAlgorithm, "Unexpected algorithm value");
            Assert.AreEqual(400, aggregatorConfig.AggregationPeriod, "Unexpected aggregation period value");
            Assert.AreEqual(1024, aggregatorConfig.MaxRequests, "Unexpected max requests value");
            Assert.AreEqual(0, aggregatorConfig.ParentsUris.Count, "Unexpected parent uri count");
        }
Beispiel #2
0
        public void HAAsyncSignTest()
        {
            HAKsiService haService = new HAKsiService(SigningServices, ExtendingServices, PublicationsFileService);

            DataHash         dataHash            = new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"));
            ManualResetEvent waitHandle          = new ManualResetEvent(false);
            IKsiSignature    signature           = null;
            object           testObject          = new object();
            bool             isAsyncStateCorrect = false;

            haService.BeginSign(dataHash, delegate(IAsyncResult ar)
            {
                try
                {
                    isAsyncStateCorrect = ar.AsyncState == testObject;
                    signature           = haService.EndSign(ar);
                }
                finally
                {
                    waitHandle.Set();
                }
            }, testObject);

            Assert.IsTrue(waitHandle.WaitOne(10000), "Wait handle timed out.");

            Assert.IsNotNull(signature, "Signature should not be null.");
            Assert.AreEqual(true, isAsyncStateCorrect, "Unexpected async state.");
        }
Beispiel #3
0
        public void HARequestSubClientsTest()
        {
            HAKsiService haService = new HAKsiService(SigningServices, ExtendingServices, PublicationsFileService);

            Assert.AreEqual(ExtendingServices, haService.ExtendingServices);
            Assert.AreEqual(SigningServices, haService.SigningServices);
        }
Beispiel #4
0
        public void HttpAsyncGetPublicationsFileTest()
        {
            HAKsiService haService = new HAKsiService(SigningServices, ExtendingServices, PublicationsFileService);

            ManualResetEvent  waitHandle = new ManualResetEvent(false);
            IPublicationsFile pubFile    = null;

            object testObject     = new object();
            bool   isAsyncCorrect = false;

            haService.BeginGetPublicationsFile(delegate(IAsyncResult ar)
            {
                try
                {
                    isAsyncCorrect = ar.AsyncState == testObject;
                    pubFile        = haService.EndGetPublicationsFile(ar);
                }
                finally
                {
                    waitHandle.Set();
                }
            }, testObject);

            Assert.IsTrue(waitHandle.WaitOne(10000), "Wait handle timed out.");

            Assert.IsNotNull(pubFile, "Publications file should not be null.");
            Assert.AreEqual(true, isAsyncCorrect, "Unexpected async state.");
        }
Beispiel #5
0
        public void HAAsyncExtendTest()
        {
            HAKsiService haService = new HAKsiService(SigningServices, ExtendingServices, PublicationsFileService);

            ManualResetEvent  waitHandle = new ManualResetEvent(false);
            CalendarHashChain cal        = null;

            object testObject     = new object();
            bool   isAsyncCorrect = false;

            haService.BeginExtend(1455400000, delegate(IAsyncResult ar)
            {
                try
                {
                    isAsyncCorrect = ar.AsyncState == testObject;
                    cal            = haService.EndExtend(ar);
                }
                finally
                {
                    waitHandle.Set();
                }
            }, testObject);

            Assert.IsTrue(waitHandle.WaitOne(10000), "Wait handle timed out.");

            Assert.IsNotNull(cal, "Calendar hash chain should not be null.");
            Assert.AreEqual(true, isAsyncCorrect, "Unexpected async state.");
        }
Beispiel #6
0
        public void HAExtenderConfigRequestUsingEventHandlerTest()
        {
            // Test getting extender configuration with 1 successful and 2 unsuccessful sub-service responses.
            // Get response using ExtenderConfigChanged event handler

            IKsiService haService =
                new HAKsiService(
                    null,
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101455),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtenderConfigResponsePdu)), 1584727637),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101454)
            },
                    null);

            ManualResetEvent waitHandle = new ManualResetEvent(false);
            ExtenderConfig   config     = null;

            haService.ExtenderConfigChanged += delegate(object sender, ExtenderConfigChangedEventArgs e)
            {
                config = e.ExtenderConfig;
                waitHandle.Set();
            };
            haService.GetExtenderConfig();
            waitHandle.WaitOne(1000);
            Assert.IsNotNull(config, "Could not get extender config using event handler.");

            Assert.AreEqual(273, config.MaxRequests, "Unexpected max requests value");
            Assert.AreEqual(0, config.ParentsUris.Count, "Unexpected parent uri count");
            Assert.AreEqual(1455478441, config.CalendarFirstTime, "Unexpected calendar first time value");
            Assert.AreEqual(1455478442, config.CalendarLastTime, "Unexpected calendar last time value");
        }
        public void HASignWithInvalidResultTlvFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregatorConfigResponsePdu)),
                                    1584727637)
            },
                    null, null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                HAAsyncResult asyncResult = (HAAsyncResult)haService.BeginSign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")),
                                                                               null, null);

                // add invalid result
                FieldInfo memberInfo  = typeof(HARequestRunner).GetField("_resultTlvs", BindingFlags.NonPublic | BindingFlags.Instance);
                List <object> results = (List <object>)memberInfo.GetValue(asyncResult.RequestRunner);
                results.Add(new IntegerTag(1, false, false, 1));

                haService.EndSign(asyncResult);
            });

            Assert.That(ex.Message.StartsWith("Could not get request response of type " + typeof(KsiSignature)), "Unexpected exception message: " + ex.Message);
        }
Beispiel #8
0
        public void HAGetConfigResultsAndRemoveAllTest()
        {
            // A configuration request with 2 successful sub-requests is made.
            // Then a new configuration request is made with 2 unsuccessful sub-requests.
            // Both configuration are removed from cache.
            // ExtenderConfigChanged event handler should get result containing an exception.

            HAKsiService haService = GetHAService(
                new List <PduPayload>()
            {
                GetExtenderConfigResponsePayload(4, new List <string>()
                {
                    "uri-1"
                }, 1136073600, 2136073600)
            },
                new List <PduPayload>()
            {
                GetExtenderConfigResponsePayload(4, new List <string>()
                {
                    "uri-2"
                }, 1136073600, 2136073600)
            });

            haService.GetExtenderConfig();

            // change first service response so that request fails
            ((TestKsiService)haService.ExtendingServices[0]).ExtendingServiceProtocol.RequestResult =
                File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455));

            // change second service response so that request fails
            ((TestKsiService)haService.ExtendingServices[1]).ExtendingServiceProtocol.RequestResult =
                File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455));

            ExtenderConfigChangedEventArgs args = null;
            ManualResetEvent waitHandle         = new ManualResetEvent(false);

            haService.ExtenderConfigChanged += delegate(object sender, ExtenderConfigChangedEventArgs e)
            {
                args = e;
                waitHandle.Set();
            };

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.GetExtenderConfig();
            });

            Assert.That(ex.Message.StartsWith("Could not get extender configuration"), "Unexpected exception message: " + ex.Message);

            waitHandle.WaitOne(1000);

            Assert.IsNotNull(args, "ExtenderConfigChangedEventArgs cannot be null.");
            Assert.IsNull(args.ExtenderConfig, "ExtenderConfigChangedEventArgs.ExtenderConfig cannot have value.");
            Assert.IsNotNull(args.Exception, "ExtenderConfigChangedEventArgs.Exception cannot be null.");
            Assert.AreEqual(haService, args.KsiService, "Unexpected ExtenderConfigChangedEventArgs.KsiService");
            Assert.That(args.Exception.Message.StartsWith("Could not get extender configuration"), "Unexpected exception message: " + args.Exception.Message);
        }
        public void HASignWithInvalidTypeAsyncResultFailTest()
        {
            IKsiService haService = new HAKsiService(null, null, null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                IAsyncResult ar = GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)),
                                                      1584727637).BeginSign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")), null, null);
                haService.EndSign(ar);
            });

            Assert.That(ex.Message.StartsWith("Invalid asyncResult, could not cast to correct object"), "Unexpected exception message: " + ex.Message);
        }
        public void HASignWithSingleServiceTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637)
            },
                    null, null);

            DataHash      inputHash = new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"));
            IKsiSignature signature = haService.Sign(inputHash);

            Assert.AreEqual(inputHash, signature.InputHash, "Unexpected signature input hash.");
        }
        public void HAPublicationsFileRequestFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    null,
                    null,
                    GetPublicationsFileService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)))
                    );

            PublicationsFileException ex = Assert.Throws <PublicationsFileException>(delegate
            {
                haService.GetPublicationsFile();
            });

            Assert.That(ex.Message, Does.StartWith("Publications file header is incorrect. Invalid publications file magic bytes"));
        }
        public void HAPublicationsFileRequestTest()
        {
            IKsiService haService =
                new HAKsiService(
                    null,
                    null,
                    GetPublicationsFileService()
                    );

            Assert.AreEqual("test.publications.file.address", haService.PublicationsFileAddress,
                            "Unexpected publications file address.");

            IPublicationsFile publicationsFile = haService.GetPublicationsFile();

            Assert.AreEqual(1515974400, publicationsFile.GetLatestPublication().PublicationData.PublicationTime, "Unexpected last publication time");
        }
Beispiel #13
0
        public void HAExtendingWithSingleServiceTest()
        {
            IKsiService haService =
                new HAKsiService(
                    null,
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101455)
            },
                    null);

            CalendarHashChain cal = haService.Extend(123);

            Assert.AreEqual(1455478441, cal.AggregationTime, "Unexpected aggregation time.");
            Assert.AreEqual(1455494400, cal.PublicationTime, "Unexpected publication time.");
        }
        public void HASignWithMutlipleServicesTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727638),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637)
            },
                    null, null);

            Assert.AreEqual("test.aggregator.address; test.aggregator.address; test.aggregator.address; ", haService.AggregatorAddress, "Unexpected aggregator address.");
            IKsiSignature signature = haService.Sign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")));

            Assert.IsNotNull(signature, "Signature cannot be null.");
        }
        public void HASignWithPayloadResponseAndWaitTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727638),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637)
            },
                    null, null);

            IAsyncResult ar = haService.BeginSign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")), null, null);
            SignRequestResponsePayload payload = haService.GetSignResponsePayload(ar);

            Assert.IsNotNull(payload, "Sign request response payload cannot be null.");
        }
        public void HACreateServiceWith4SubServicesFailTest()
        {
            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                IKsiService haService =
                    new HAKsiService(
                        new List <IKsiService>()
                {
                    GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1),
                    GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 2),
                    GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1043101455),
                    GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1043101455)
                },
                        null, null);
            });

            Assert.That(ex.Message.StartsWith("Cannot use more than 3 signing services"), "Unexpected exception message: " + ex.Message);
        }
        public void HASignWithAsyncResultNullFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    null,
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101455)
            },
                    null);

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(delegate
            {
                haService.EndSign(null);
            });

            Assert.AreEqual("asyncResult", ex.ParamName, "Unexpected exception: " + ex.Message);
        }
        public void HASignWithoutServicesFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    null,
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1),
            },
                    GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1));

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.Sign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")));
            });

            Assert.That(ex.Message.StartsWith("Sub-services are missing"), "Unexpected exception message: " + ex.Message);
        }
Beispiel #19
0
        public void HAExtedWithoutServicesFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1),
            },
                    null,
                    GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1)
                    );

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.Extend(123);
            });

            Assert.That(ex.Message.StartsWith("Sub-services are missing"), "Unexpected exception message: " + ex.Message);
        }
        public void HASignWithOneSubServiceTimeoutTest()
        {
            TestKsiServiceProtocol protocol = new TestKsiServiceProtocol
            {
                RequestResult     = File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)),
                DelayMilliseconds = 3000
            };

            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(protocol, 1584727637),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637)
            },
                    null, null, 1000);

            haService.Sign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")));
        }
Beispiel #21
0
        public void HAExtendWithOneSubServiceTimeoutTest()
        {
            TestKsiServiceProtocol protocol = new TestKsiServiceProtocol
            {
                RequestResult     = File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)),
                DelayMilliseconds = 3000
            };

            IKsiService haService =
                new HAKsiService(
                    null, new List <IKsiService>()
            {
                GetStaticKsiService(protocol, 1043101455),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101455),
            },
                    null, 1000);

            haService.Extend(123);
        }
        public void HAGetSignResponsePayloadWithInvalidAsyncResultFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    null,
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101455)
            },
                    null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                IAsyncResult ar = haService.BeginExtend(1455494400, null, null);
                // use extending async result
                haService.GetSignResponsePayload(ar);
            });

            Assert.That(ex.Message.StartsWith("Invalid async result. Containing invalid request runner"), "Unexpected exception message: " + ex.Message);
        }
Beispiel #23
0
        public void HAExtendAllServicesFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    null,
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 2),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637),
            },
                    null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.Extend(123);
            });

            Assert.That(ex.Message.StartsWith("All sub-requests failed"), "Unexpected exception message: " + ex.Message);
        }
Beispiel #24
0
        public void HAExtendWithInvalidAsyncResultFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637),
            },
                    null,
                    null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                IAsyncResult ar = haService.BeginSign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")), null, null);
                // send signing async result to extend ending
                haService.EndExtend(ar);
            });

            Assert.That(ex.Message.StartsWith("Invalid async result. Containing invalid request runner"), "Unexpected exception message: " + ex.Message);
        }
        public void HAEndPublicationsFileRequestWithoutServicesFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetPublicationsFileService()
            },
                    new List <IKsiService>()
            {
                GetPublicationsFileService()
            },
                    null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.EndGetPublicationsFile(new TestAsyncResult());
            });

            Assert.That(ex.Message.StartsWith("Publications file service is missing"), "Unexpected exception message: " + ex.Message);
        }
        public void HAAggregatorConfigRequestFailSTest()
        {
            // Test getting aggregator configuration with all 3 sub-services responses failing

            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 2),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 3)
            },
                    null, null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.GetAggregatorConfig();
            });

            Assert.That(ex.Message.StartsWith("Could not get aggregator configuration"), "Unexpected exception message: " + ex.Message);
        }
Beispiel #27
0
        public void HAExtenderConfigRequestTest()
        {
            // Test getting extender configuration with 1 successful and 2 unsuccessful sub-service responses

            IKsiService haService =
                new HAKsiService(
                    null,
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101455),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtenderConfigResponsePdu)), 1584727637),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101454)
            },
                    null);

            ExtenderConfig config = haService.GetExtenderConfig();

            Assert.AreEqual(273, config.MaxRequests, "Unexpected max requests value");
            Assert.AreEqual(0, config.ParentsUris.Count, "Unexpected parent uri count");
            Assert.AreEqual(1455478441, config.CalendarFirstTime, "Unexpected calendar first time value");
            Assert.AreEqual(1455478442, config.CalendarLastTime, "Unexpected calendar last time value");
        }
        public void HASignAllServicesFailTest()
        {
            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 2),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_ExtendResponsePdu_RequestId_1043101455)), 1043101455)
            },
                    null, null);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.Sign(new DataHash(Base16.Decode("019f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")));
            });

            Assert.That(ex.Message.StartsWith("All sub-requests failed"), "Unexpected exception message: " + ex.Message);
            Assert.AreEqual(3, ex.SubServiceExceptions.Count, "Unexpected sub-service exception count");
            Assert.That(ex.SubServiceExceptions[0].Message.StartsWith("Using sub-service failed"),
                        "Unexpected sub-service exception message: " + ex.SubServiceExceptions[0].Message);
        }
        public void HAAggregatorConfigRequestTest()
        {
            // Test getting aggregator configuration with 1 successful and 2 unsuccessful sub-service responses

            IKsiService haService =
                new HAKsiService(
                    new List <IKsiService>()
            {
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727638),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregatorConfigResponsePdu)), 1584727637),
                GetStaticKsiService(File.ReadAllBytes(Path.Combine(TestSetup.LocalPath, Resources.KsiService_AggregationResponsePdu_RequestId_1584727637)), 1584727637)
            },
                    null, null);

            AggregatorConfig config = haService.GetAggregatorConfig();

            Assert.AreEqual(17, config.MaxLevel, "Unexpected max level value");
            Assert.AreEqual(1, config.AggregationAlgorithm, "Unexpected algorithm value");
            Assert.AreEqual(400, config.AggregationPeriod, "Unexpected aggregation period value");
            Assert.AreEqual(1024, config.MaxRequests, "Unexpected max requests value");
            Assert.AreEqual(0, config.ParentsUris.Count, "Unexpected parent uri count");
        }
Beispiel #30
0
        public void HAGetExtenderConfigTimeoutTest()
        {
            TestKsiServiceProtocol protocol = new TestKsiServiceProtocol
            {
                RequestResult     = GetExtenderConfigResponsePayload(1, null, 123, 234).Encode(),
                DelayMilliseconds = 3000
            };

            IKsiService haService =
                new HAKsiService(
                    null, new List <IKsiService>()
            {
                GetStaticKsiService(protocol),
            },
                    null, 1000);

            HAKsiServiceException ex = Assert.Throws <HAKsiServiceException>(delegate
            {
                haService.GetExtenderConfig();
            });

            Assert.That(ex.Message.StartsWith("HA service request timed out"), "Unexpected exception message: " + ex.Message);
        }