public void TcpExtendesWithDisposedServiceProtocolTest()
        {
            KsiService service         = GetTcpKsiService();
            ulong      aggregationTime = 1455478441;

            IAsyncResult ar1 = service.BeginExtend(aggregationTime, null, null);
            IAsyncResult ar2 = service.BeginExtend(aggregationTime, null, null);

            service.EndExtend(ar1);

            TcpKsiExtendingServiceProtocol tcp = GetTcpProtocol(service);

            Assert.IsNotNull(GetExtendingSocket(tcp), "Socket should not be null");
            tcp.Dispose();

            Assert.IsNull(GetExtendingSocket(tcp), "Socket should be null");

            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                service.EndExtend(ar2);
            });

            Assert.That(ex.Message.StartsWith("TCP KSI service protocol is disposed."), "Unexpected exception message: " + ex.Message);

            ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                service.BeginExtend(aggregationTime, null, null);
            });

            Assert.That(ex.Message.StartsWith("TCP KSI service protocol is disposed."), "Unexpected exception message: " + ex.Message);
        }
        public void CreateHttpServiceProtocolWithInvalidTimeout()
        {
            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                new TcpKsiSigningServiceProtocol(new IPAddress(new byte[] { 127, 0, 0, 1 }), 0, 0, 0);
            });

            Assert.That(ex.Message.StartsWith("Buffer size should be a positive integer"), "Unexpected exception message: " + ex.Message);
        }
        public void CreateHttpServiceProtocolWithInvalidTimeout()
        {
            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                new HttpKsiServiceProtocol(null, null, null, -1);
            });

            Assert.That(ex.Message.StartsWith("Request timeout should be in milliseconds"), "Unexpected exception message: " + ex.Message);
        }
Example #4
0
        public void HttpKsiServiceProtocolEndGetPublicationsFileInvalidAsyncResultTest()
        {
            HttpKsiServiceProtocol protocol = new HttpKsiServiceProtocol(null, null, null);

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

            Assert.That(ex.Message.StartsWith("Invalid IAsyncResult"), "Unexpected exception message: " + ex.Message);
        }
        public void EndSignInvalidAsyncResultTest()
        {
            TcpKsiSigningServiceProtocol protocol = new TcpKsiSigningServiceProtocol(new IPAddress(new byte[] { 127, 0, 0, 1 }), 0);

            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                protocol.EndSign(new TestAsyncResult());
            });

            Assert.That(ex.Message.StartsWith("Invalid IAsyncResult"), "Unexpected exception message: " + ex.Message);
        }
        public void TcpProcessorUnknowndResponsePduTypeTest()
        {
            TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection();
            TcpResponseProcessor     processor             = new TcpResponseProcessor(asyncResultCollection);

            byte[] data = new StringTag(0, false, false, "asdf").Encode();
            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                processor.ProcessReceivedData(data, data.Length);
            });

            Assert.That(ex.Message.StartsWith("Unknown response PDU type"), "Unexpected exception message: " + ex.Message);
        }
        public void EndSignWithAsyncResultDisposedTest()
        {
            TcpKsiSigningServiceProtocol protocol    = new TcpKsiSigningServiceProtocol(new IPAddress(new byte[] { 127, 0, 0, 1 }), 0);
            KsiServiceAsyncResult        asyncResult = new TcpKsiServiceAsyncResult(KsiServiceRequestType.Sign, new byte[] { 1, 2, 3 }, 12345, null, null);

            asyncResult.Dispose();

            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                protocol.EndSign(asyncResult);
            });

            Assert.That(ex.Message.StartsWith("Provided async result is already disposed. Possibly using the same async result twice when ending request"),
                        "Unexpected exception message: " + ex.Message);
        }
        public void TcpProcessorExtendResponseInvalidNoRequestIdTest()
        {
            TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection();
            TcpResponseProcessor     processor             = new TcpResponseProcessor(asyncResultCollection);

            byte[] data = new TlvTagBuilder(Constants.ExtendResponsePdu.TagType, false, false,
                                            new ITlvTag[]
            {
                new CompositeTestTag(Constants.ExtendResponsePayload.TagType, true, false, new ITlvTag[] { }),
            }).BuildTag().Encode();

            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                processor.ProcessReceivedData(data, data.Length);
            });

            Assert.That(ex.Message.StartsWith("Cannot find request id tag from extender response payload"), "Unexpected exception message: " + ex.Message);
        }
        public void TcpSignHashesWithDisposedServiceProtocolTest()
        {
            KsiService service = GetTcpKsiService();

            IAsyncResult ar1 = service.BeginSign(new DataHash(HashAlgorithm.Sha2256, Base16.Decode("1f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")), null,
                                                 null);
            IAsyncResult ar2 = service.BeginSign(new DataHash(HashAlgorithm.Sha2256, Base16.Decode("2f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")), null,
                                                 null);

            service.EndSign(ar1);

            TcpKsiSigningServiceProtocol tcp = GetTcpProtocol(service);

            Assert.IsNotNull(GetSigningSocket(tcp), "Socket should not be null");
            tcp.Dispose();

            Assert.IsNull(GetSigningSocket(tcp), "Socket should be null");

            KsiServiceProtocolException ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                tcp.Dispose();
            });

            Assert.That(ex.Message.StartsWith("TCP KSI service protocol is already disposed."), "Unexpected exception message: " + ex.Message);

            ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                service.EndSign(ar2);
            });

            Assert.That(ex.Message.StartsWith("TCP KSI service protocol is disposed."), "Unexpected exception message: " + ex.Message);

            ex = Assert.Throws <KsiServiceProtocolException>(delegate
            {
                service.BeginSign(new DataHash(HashAlgorithm.Sha2256, Base16.Decode("3f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")), null, null);
            });

            Assert.That(ex.Message.StartsWith("TCP KSI service protocol is disposed."), "Unexpected exception message: " + ex.Message);
        }