From 37218de65023fd67be2b767dac112e92eb232d76 Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Mon, 20 Jul 2026 19:40:08 +0300 Subject: [PATCH] Reduce EncryptedXml encoded DTD test workload The encoded DTD payload used 111 transforms, causing tests that execute the chain to time out. Keep it at 21 transforms, one above the default limit, and assert that boundary in the test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 21e761a9-3212-499c-b2b6-28d666f5bebd --- .../tests/EncryptedXmlSample5.xml | 90 ------------------- .../tests/EncryptedXmlTests.cs | 7 +- 2 files changed, 4 insertions(+), 93 deletions(-) diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlSample5.xml b/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlSample5.xml index 7f176e58daf0b1..cdbbf4001a8bf0 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlSample5.xml +++ b/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlSample5.xml @@ -25,96 +25,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlTests.cs b/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlTests.cs index 2bb5d2557590cf..458a8cf6d5b26a 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlTests.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/EncryptedXmlTests.cs @@ -15,6 +15,7 @@ namespace System.Security.Cryptography.Xml.Tests public static class EncryptedXmlTests { private const string AllowDangerousEncryptedXmlTransformsAppContextSwitch = "System.Security.Cryptography.Xml.AllowDangerousEncryptedXmlTransforms"; + private const int DefaultMaxTransformsPerChain = 20; private const string MaxTransformsPerChainAppContextSwitch = "System.Security.Cryptography.Xml.MaxTransformsPerChain"; private const string MalformedTransformsMessage = "Malformed element Transforms."; @@ -281,9 +282,9 @@ public static void EncryptedXml_LoadDeepFile() [Fact] public static void EncryptedXml_DecryptedEncodedDtd() { - // The payload contains more transforms than the default limit, so - // deserialization of the transform chain should fail. - Assert.True(GetEncodedDtdPayloadTransformCount() > 20); + // Keep the payload just above the default limit so deserialization fails + // without executing an unnecessarily expensive transform chain. + Assert.Equal(DefaultMaxTransformsPerChain + 1, GetEncodedDtdPayloadTransformCount()); EncryptedXml encryptedXml = CreateEncryptedXmlWithEncodedDtdPayload(); CryptographicException ex = Assert.Throws(() => encryptedXml.DecryptDocument());