diff --git a/src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs b/src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs index 5e8eafbaa381ad..6e2d7322f53504 100644 --- a/src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs +++ b/src/libraries/System.Security.Cryptography/tests/AesTests.Browser.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Reflection; using Xunit; namespace System.Security.Cryptography.Tests @@ -58,5 +59,17 @@ public static void Aes_InvalidKeySize_192_Browser() Assert.Throws(() => aes.CreateDecryptor(key192, s_iv)); } } + + [Fact] + public static void EnsureSubtleCryptoIsUsed() + { + bool canUseSubtleCrypto = (bool)Type.GetType("Interop+BrowserCrypto, System.Security.Cryptography") + .GetField("CanUseSubtleCrypto", BindingFlags.NonPublic | BindingFlags.Static) + .GetValue(null); + + bool expectedCanUseSubtleCrypto = Environment.GetEnvironmentVariable("TEST_EXPECT_SUBTLE_CRYPTO") == "true"; + + Assert.Equal(expectedCanUseSubtleCrypto, canUseSubtleCrypto); + } } } diff --git a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj index 8334efeb1621de..f65e9056134c8c 100644 --- a/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj +++ b/src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj @@ -9,8 +9,12 @@ $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) + + + wasm.helix.targets - wasm.helix.targets + $(WasmXHarnessMonoArgs) --setenv=TEST_EXPECT_SUBTLE_CRYPTO=true + $(WasmXHarnessArgs) --web-server-use-cop true diff --git a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets index ecb37438b651b1..e14095c075678b 100644 --- a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets +++ b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets @@ -21,8 +21,8 @@ $(HelixCommand) $(_workItemTimeout) - set "WasmXHarnessArgs=%WasmXHarnessArgs% --web-server-use-cop" - export "WasmXHarnessArgs=$WasmXHarnessArgs --web-server-use-cop" + set "WasmXHarnessArgs=%WasmXHarnessArgs% --web-server-use-cop" & set "WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true" + export "WasmXHarnessArgs=$WasmXHarnessArgs --web-server-use-cop" && export "WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true" <_CryptoHelixItem Include="@(HelixWorkItem)"