public void AggregationRequestPduWithHeaderNotFirst() { TlvException ex = Assert.Throws <TlvException>(delegate { new AggregationRequestPdu(new TlvTagBuilder(Constants.AggregationRequestPdu.TagType, false, false, new ITlvTag[] { new AggregationRequestPayload(new TlvTagBuilder(Constants.AggregationRequestPayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduPayload.RequestIdTagType, false, false, 1), new ImprintTag(Constants.AggregationRequestPayload.RequestHashTagType, false, 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 })), new IntegerTag(Constants.AggregationRequestPayload.RequestLevelTagType, false, false, 0), }).BuildTag()), new PduHeader(new TlvTagBuilder(Constants.PduHeader.TagType, false, false, new ITlvTag[] { new StringTag(Constants.PduHeader.LoginIdTagType, false, false, "Test Login Id"), new IntegerTag(Constants.PduHeader.InstanceIdTagType, false, false, 1), new IntegerTag(Constants.PduHeader.MessageIdTagType, false, false, 2) }).BuildTag()), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Header must be the first element in PDU")); }
public void AggregationResponsePduWithHeaderNotFirst() { TlvException ex = Assert.Throws <TlvException>(delegate { new AggregationResponsePdu(new TlvTagBuilder(Constants.AggregationResponsePdu.TagType, false, false, new ITlvTag[] { new AggregationResponsePayload(new TlvTagBuilder(Constants.AggregationResponsePayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduPayload.RequestIdTagType, false, false, 1), new IntegerTag(Constants.PduPayload.StatusTagType, false, false, 0), }).BuildTag()), new PduHeader(new TlvTagBuilder(Constants.PduHeader.TagType, false, false, new ITlvTag[] { new StringTag(Constants.PduHeader.LoginIdTagType, false, false, "Test Login Id"), new IntegerTag(Constants.PduHeader.InstanceIdTagType, false, false, 1), new IntegerTag(Constants.PduHeader.MessageIdTagType, false, false, 2) }).BuildTag()), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Header must be the first element in PDU")); }
public void TestTlvTagCreateFromInvalidEncodeTlvTag() { TlvException ex = Assert.Throws <TlvException>(delegate { new RawTag(new InvalidEncodeTlvTag(0x0, false, false)); }); Assert.That(ex.Message, Does.StartWith("Invalid TLV element encoded value: null")); }
public void PublicationDataFromPublicationStringTooShortTest() { TlvException ex = Assert.Throws <TlvException>(delegate { PublicationData pub = new PublicationData("AAAAAA"); }); Assert.That(ex.Message.StartsWith("Publication string base 32 decode failed"), "Unexpected exception message: " + ex.Message); }
public void PublicationDataFromPublicationStringInvalidCrc32Test() { TlvException ex = Assert.Throws <TlvException>(delegate { PublicationData pub = new PublicationData("AAAAAA-CVZ2AQ-AANGVK-SV7GJL-36LN65-AVJYZR-6XRZSL-HIMRH3-6GU7WR-YNRY7C-X2XECY-WFQXRA"); }); Assert.That(ex.Message.StartsWith("Publication string CRC 32 check failed"), "Unexpected exception message: " + ex.Message); }
public void AggregationRequestPduWithoutPayload() { TlvException ex = Assert.Throws <TlvException>(delegate { new AggregationRequestPdu(new TlvTagBuilder(Constants.AggregationRequestPdu.TagType, false, false, new ITlvTag[] { }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Payloads are missing in PDU")); }
public void TestReadDataWithInvalidLength() { using (TlvReader reader = new TlvReader(new MemoryStream(new byte[] { 0x21, 0x2 }))) { TlvException ex = Assert.Throws <TlvException>(delegate { reader.ReadTag(); }); Assert.That(ex.Message, Does.StartWith("Could not read TLV data with expected length")); } }
public void TestReadTooShortTag() { using (TlvReader reader = new TlvReader(new MemoryStream(new byte[] { 0x21 }))) { TlvException ex = Assert.Throws <TlvException>(delegate { reader.ReadTag(); }); Assert.That(ex.Message, Does.StartWith("Premature end of input data")); } }
public void PduHeaderWithoutRequestId() { TlvException ex = Assert.Throws <TlvException>(delegate { new PduHeader(new TlvTagBuilder(Constants.PduHeader.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduHeader.InstanceIdTagType, false, false, 2), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Exactly one login id must exist in PDU header")); }
public void ExtendRequestPayloadWithoutAggregationTime() { TlvException ex = Assert.Throws <TlvException>(delegate { new ExtendRequestPayload(new TlvTagBuilder(Constants.ExtendRequestPayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduPayload.RequestIdTagType, false, false, 1), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Exactly one aggregation time must exist in extend request payload")); }
public void ExtendResponsePayloadWithoutRequestId() { TlvException ex = Assert.Throws <TlvException>(delegate { new ExtendResponsePayload(new TlvTagBuilder(Constants.ExtendResponsePayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduPayload.StatusTagType, false, false, 0), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Exactly one request id must exist in response payload")); }
public void AggregationRequestPayloadWithoutRequestHash() { TlvException ex = Assert.Throws <TlvException>(delegate { new AggregationRequestPayload(new TlvTagBuilder(Constants.AggregationRequestPayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduPayload.RequestIdTagType, false, false, 1), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Exactly one request hash must exist in aggregation request payload")); }
public void AggregatorConfigResponsePayloadWithMultipleMaxRequests() { TlvException ex = Assert.Throws <TlvException>(delegate { new AggregatorConfigResponsePayload(new TlvTagBuilder(Constants.AggregatorConfigResponsePayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.AggregatorConfigResponsePayload.MaxRequestsTagType, false, false, 1), new IntegerTag(Constants.AggregatorConfigResponsePayload.MaxRequestsTagType, false, false, 2), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Only one max requests tag is allowed in aggregator config response payload.")); }
public void ExtenderConfigResponsePayloadWithMultipleCalendarLastTimes() { TlvException ex = Assert.Throws <TlvException>(delegate { new ExtenderConfigResponsePayload(new TlvTagBuilder(Constants.ExtenderConfigResponsePayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.ExtenderConfigResponsePayload.CalendarLastTimeTagType, false, false, 1), new IntegerTag(Constants.ExtenderConfigResponsePayload.CalendarLastTimeTagType, false, false, 2), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Only one calendar last time tag is allowed in extender config response payload")); }
public void PduHeaderWithoutMultipleMessageIds() { TlvException ex = Assert.Throws <TlvException>(delegate { new PduHeader(new TlvTagBuilder(Constants.PduHeader.TagType, false, false, new ITlvTag[] { new StringTag(Constants.PduHeader.LoginIdTagType, false, false, "TestLoginId"), new IntegerTag(Constants.PduHeader.MessageIdTagType, false, false, 2), new IntegerTag(Constants.PduHeader.MessageIdTagType, false, false, 2) }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Only one message id is allowed in PDU header")); }
public void PublicationsFileHeaderWithoutCreationTimeTest() { TlvException ex = Assert.Throws <TlvException>(delegate { new PublicationsFileHeader(new TlvTagBuilder(Constants.PublicationsFileHeader.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PublicationsFileHeader.VersionTagType, false, false, 1), new StringTag(Constants.PublicationsFileHeader.RepositoryUriTagType, false, false, "Test repository uri"), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Exactly one creation time must exist in publications file header.")); }
public void TestIsInvalidStructure() { TlvException ex = Assert.Throws <TlvException>(delegate { new CompositeTestTag(0x1, false, false, new ITlvTag[] { new RawTag(0x2, false, false, new byte[] { 0x4, 0x5 }), new RawTag(0x3, false, false, new byte[] { 0x6, 0x7 }) }); }); Assert.That(ex.Message, Does.StartWith("Unknown tag type (0x2)")); }
public void AggregationRequestPayloadWithoutRequestId() { TlvException ex = Assert.Throws <TlvException>(delegate { new AggregationRequestPayload(new TlvTagBuilder(Constants.AggregationRequestPayload.TagType, false, false, new ITlvTag[] { new ImprintTag(Constants.AggregationRequestPayload.RequestHashTagType, false, 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()); }); Assert.That(ex.Message, Does.StartWith("Exactly one request id must exist in aggregation request payload")); }
public void CertificationRecordWithoutCertTest() { TlvException ex = Assert.Throws <TlvException>(delegate { TlvTagBuilder builder = new TlvTagBuilder(Constants.CertificateRecord.TagType, false, false, new ITlvTag[] { new RawTag(Constants.CertificateRecord.CertificateIdTagType, false, false, new byte[] { 0x2 }), }); CertificateRecord tag = new CertificateRecord(builder.BuildTag()); }); Assert.That(ex.Message.StartsWith("Exactly one certificate must exist in certificate record"), "Unexpected exception message: " + ex.Message); }
public void ExtendResponsePayloadWithMultipleErrors() { TlvException ex = Assert.Throws <TlvException>(delegate { new ExtendResponsePayload(new TlvTagBuilder(Constants.ExtendResponsePayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduPayload.StatusTagType, false, false, 0), new StringTag(Constants.PduPayload.ErrorMessageTagType, false, false, "Test error message 1."), new StringTag(Constants.PduPayload.ErrorMessageTagType, false, false, "Test error message 2."), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Only one error message is allowed in response payload")); }
public void ExtendRequestPayloadWithMultiplePublicationTimes() { TlvException ex = Assert.Throws <TlvException>(delegate { new ExtendRequestPayload(new TlvTagBuilder(Constants.ExtendRequestPayload.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PduPayload.RequestIdTagType, false, false, 1), new IntegerTag(Constants.ExtendRequestPayload.AggregationTimeTagType, false, false, 2), new IntegerTag(Constants.ExtendRequestPayload.PublicationTimeTagType, false, false, 3), new IntegerTag(Constants.ExtendRequestPayload.PublicationTimeTagType, false, false, 3), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Only one publication time is allowed in extend request payload.")); }
public void PublicationsFileHeaderWithMultipleRepositoryUrisTest() { TlvException ex = Assert.Throws <TlvException>(delegate { new PublicationsFileHeader(new TlvTagBuilder(Constants.PublicationsFileHeader.TagType, false, false, new ITlvTag[] { new IntegerTag(Constants.PublicationsFileHeader.VersionTagType, false, false, 1), new IntegerTag(Constants.PublicationsFileHeader.CreationTimeTagType, false, false, 2), new StringTag(Constants.PublicationsFileHeader.RepositoryUriTagType, false, false, "Test repository uri 1"), new StringTag(Constants.PublicationsFileHeader.RepositoryUriTagType, false, false, "Test repository uri 2"), }).BuildTag()); }); Assert.That(ex.Message, Does.StartWith("Only one repository uri is allowed in publications file header.")); }
public void TcpProcessorInvalidWithUnknownCriticalTlvTest() { TcpAsyncResultCollection asyncResultCollection = new TcpAsyncResultCollection(); TcpResponseProcessor processor = new TcpResponseProcessor(asyncResultCollection); byte[] data = Base16.Decode( // 01 - header, 67 - unknown critical, 04 - aggr config, 1F - mac "8221004A 01120105616E6F6E0002045809EBFA030331926A 070101 040E0101110201010302019004020400 1F21012526C7B579BFB93263BDFE421CB29A8AFE81C65E9C8773CBAD8AC691B3C2A89C" .Replace(" ", "")); TlvException ex = Assert.Throws <TlvException>(delegate { processor.ProcessReceivedData(data, data.Length); }); Assert.That(ex.Message.StartsWith("Unknown tag type (0x7)"), "Unexpected exception message: " + ex.Message); }
public void CreateFromPartsWithoutCalendarHashChainFailTest() { KsiSignatureFactory signatureFactory = new KsiSignatureFactory(); IKsiSignature signature; using (FileStream stream = new FileStream(Path.Combine(TestSetup.LocalPath, Resources.KsiSignature_Ok), FileMode.Open)) { signature = new KsiSignatureFactory().Create(stream); } // create signature without calendar hash chain but with calendar auth record. TlvException ex = Assert.Throws <TlvException>(delegate { signatureFactory.Create(signature.GetAggregationHashChains(), null, signature.CalendarAuthenticationRecord, signature.PublicationRecord, signature.Rfc3161Record, signature.InputHash); }); Assert.That(ex.Message, Does.StartWith("No publication record or calendar authentication record is allowed in KSI signature if there is no calendar hash chain")); }