From 7fa872cbedcf82d3161e3e7f6cfea57f37ab8575 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 26 Jul 2022 23:21:35 +0000 Subject: [PATCH 1/6] Add a test that ensures we are using SubtleCrypto in WASM crypto tests Fix #69740 --- .../tests/AesTests.Browser.cs | 13 +++++++++++++ .../tests/System.Security.Cryptography.Tests.csproj | 8 ++++++-- .../tests/wasm.helix.targets | 8 ++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) 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..f40ca2dae91e2e 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..2e8ed39598ee14 100644 --- a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets +++ b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets @@ -21,8 +21,12 @@ $(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)" + <_CryptoHelixItem Include="@(HelixWorkItem)" From f94faa5c42815ae4e3c55ce68945dc6e9a59e596 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 26 Jul 2022 20:39:47 -0400 Subject: [PATCH 2/6] Update src/libraries/System.Security.Cryptography/tests/wasm.helix.targets --- .../System.Security.Cryptography/tests/wasm.helix.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets index 2e8ed39598ee14..194879ced5e525 100644 --- a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets +++ b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets @@ -22,7 +22,7 @@ $(_workItemTimeout) 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" + export "WasmXHarnessArgs=$WasmXHarnessArgs "--web-server-use-cop" && export "WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true" <_CryptoHelixItem Include="@(HelixWorkItem)" From abd812d51c62ded5217178c4ed25b027cfc59452 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 26 Jul 2022 20:39:53 -0400 Subject: [PATCH 3/6] Update src/libraries/System.Security.Cryptography/tests/wasm.helix.targets --- .../System.Security.Cryptography/tests/wasm.helix.targets | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets index 194879ced5e525..cea32317bad488 100644 --- a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets +++ b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets @@ -23,10 +23,6 @@ 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)" - <_CryptoHelixItem Include="@(HelixWorkItem)" From 43c2dc7ff8282e4fe53f654c9aa0562693599281 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 26 Jul 2022 20:40:59 -0400 Subject: [PATCH 4/6] Update src/libraries/System.Security.Cryptography/tests/wasm.helix.targets --- .../System.Security.Cryptography/tests/wasm.helix.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets index cea32317bad488..0c2f2f79e07554 100644 --- a/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets +++ b/src/libraries/System.Security.Cryptography/tests/wasm.helix.targets @@ -21,7 +21,7 @@ $(HelixCommand) $(_workItemTimeout) - set "WasmXHarnessArgs=%WasmXHarnessArgs% --web-server-use-cop" & set "WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true" + 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" From 1d4591f136e253b87720e04a3beea207a1ba542c Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 26 Jul 2022 20:43:31 -0400 Subject: [PATCH 5/6] Update src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj --- .../tests/System.Security.Cryptography.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 f40ca2dae91e2e..9fde0855882073 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 @@ -14,7 +14,7 @@ wasm.helix.targets $(WasmXHarnessMonoArgs) --setenv=TEST_EXPECT_SUBTLE_CRYPTO=true - $(WasmXHarnessArgs) --web-server-use-cop" + $(WasmXHarnessArgs) "--web-server-use-cop" true From f09de0beba95af9793f5e62d8544b06f30996894 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Wed, 27 Jul 2022 00:46:19 +0000 Subject: [PATCH 6/6] Fix typos --- .../tests/System.Security.Cryptography.Tests.csproj | 4 ++-- .../System.Security.Cryptography/tests/wasm.helix.targets | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) 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 9fde0855882073..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 @@ -12,9 +12,9 @@ wasm.helix.targets - + $(WasmXHarnessMonoArgs) --setenv=TEST_EXPECT_SUBTLE_CRYPTO=true - $(WasmXHarnessArgs) "--web-server-use-cop" + $(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 0c2f2f79e07554..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" & set "WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true" - export "WasmXHarnessArgs=$WasmXHarnessArgs "--web-server-use-cop" && export "WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true" + 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)"