public void TcpProcessorOkWithUnknownNonCriticalTlvTest() { TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection(); TcpKsiServiceAsyncResult asyncResult = new TcpKsiServiceAsyncResult(KsiServiceRequestType.AggregatorConfig, null, 123, null, null); asyncResultCollection.Add(123, asyncResult); TcpResponseProcessor processor = new TcpResponseProcessor(asyncResultCollection); byte[] data = new TlvTagBuilder(Constants.AggregationResponsePdu.TagType, false, false, new ITlvTag[] { new CompositeTestTag(Constants.PduHeader.TagType, true, false, new ITlvTag[] { new StringTag(Constants.PduHeader.LoginIdTagType, true, false, "Test Login Id"), new IntegerTag(Constants.PduHeader.InstanceIdTagType, true, false, 1), new IntegerTag(Constants.PduHeader.MessageIdTagType, true, false, 2) }), new CompositeTestTag(Constants.AggregatorConfigResponsePayload.TagType, true, false, new ITlvTag[] { }), new CompositeTestTag(0xAA, true, true, new ITlvTag[] { }), // unknown tag new ImprintTag(Constants.Pdu.MacTagType, true, false, new DataHash(HashAlgorithm.Sha2256, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 })), }).BuildTag().Encode(); processor.ProcessReceivedData(data, data.Length); Assert.IsTrue(Util.IsArrayEqual(data, asyncResult.ResultStream.ToArray()), "Invalid async result stream content."); Assert.AreEqual(0, asyncResultCollection.Count(), "Invalid Async collection count."); Assert.IsTrue(Util.IsArrayEqual(data, asyncResult.ResultStream.ToArray()), "Invalid async result stream content."); Assert.IsTrue(asyncResult.IsCompleted, "Async result must be completed."); }
public void TcpProcessorInvalidNoPayloadTest() { TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection(); TcpKsiServiceAsyncResult asyncResult = new TcpKsiServiceAsyncResult(KsiServiceRequestType.AggregatorConfig, null, 123, null, null); asyncResultCollection.Add(123, asyncResult); TcpResponseProcessor processor = new TcpResponseProcessor(asyncResultCollection); byte[] data = new TlvTagBuilder(Constants.AggregationResponsePdu.TagType, false, false, new ITlvTag[] { }).BuildTag().Encode(); processor.ProcessReceivedData(data, data.Length); Assert.AreEqual(1, asyncResultCollection.Count(), "Invalid Async collection count."); Assert.AreEqual(0, asyncResult.ResultStream.Length, "Invalid async result stream content."); Assert.IsFalse(asyncResult.IsCompleted, "Async result must not be completed."); }
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 TcpProcessorExtenderConfigOkTest() { TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection(); TcpKsiServiceAsyncResult asyncResult = new TcpKsiServiceAsyncResult(KsiServiceRequestType.ExtenderConfig, null, 123, null, null); asyncResultCollection.Add(123, asyncResult); TcpResponseProcessor processor = new TcpResponseProcessor(asyncResultCollection); byte[] data = new TlvTagBuilder(Constants.ExtendResponsePdu.TagType, false, false, new ITlvTag[] { new CompositeTestTag(Constants.ExtenderConfigResponsePayload.TagType, true, false, new ITlvTag[] { }), }).BuildTag().Encode(); processor.ProcessReceivedData(data, data.Length); Assert.AreEqual(0, asyncResultCollection.Count(), "Invalid Async collection count."); Assert.IsTrue(Util.IsArrayEqual(data, asyncResult.ResultStream.ToArray()), "Invalid async result stream content."); Assert.IsTrue(asyncResult.IsCompleted, "Async result must be completed."); }