Skip to content

Commit

Permalink
Add a test that ensures we are using SubtleCrypto in WASM crypto tests (
Browse files Browse the repository at this point in the history
#72892)

* Add a test that ensures we are using SubtleCrypto in WASM crypto tests

Fix #69740

* Update src/libraries/System.Security.Cryptography/tests/wasm.helix.targets

* Update src/libraries/System.Security.Cryptography/tests/wasm.helix.targets

* Update src/libraries/System.Security.Cryptography/tests/wasm.helix.targets

* Update src/libraries/System.Security.Cryptography/tests/System.Security.Cryptography.Tests.csproj

* Fix typos

Co-authored-by: Ankit Jain <[email protected]>
  • Loading branch information
eerhardt and radical authored Jul 27, 2022
1 parent 8abc251 commit 75cc8fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -58,5 +59,17 @@ public static void Aes_InvalidKeySize_192_Browser()
Assert.Throws<ArgumentException>(() => 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
<HelixTargetsFile>wasm.helix.targets</HelixTargetsFile>

<HelixTargetsFile Condition="'$(TargetOS)' == 'Browser'">wasm.helix.targets</HelixTargetsFile>
<WasmXHarnessMonoArgs Condition="'$(ContinuousIntegrationBuild)' != 'true' and '$(UseSubtleCryptoForTests)' == 'true'">$(WasmXHarnessMonoArgs) --setenv=TEST_EXPECT_SUBTLE_CRYPTO=true</WasmXHarnessMonoArgs>
<WasmXHarnessArgs Condition="'$(ContinuousIntegrationBuild)' != 'true' and '$(UseSubtleCryptoForTests)' == 'true'">$(WasmXHarnessArgs) --web-server-use-cop</WasmXHarnessArgs>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'Android'">
<UseAndroidCrypto>true</UseAndroidCrypto>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<Command>$(HelixCommand)</Command>
<Timeout>$(_workItemTimeout)</Timeout>

<PreCommands Condition="'$(OS)' == 'Windows_NT'">set &quot;WasmXHarnessArgs=%WasmXHarnessArgs% --web-server-use-cop&quot;</PreCommands>
<PreCommands Condition="'$(OS)' != 'Windows_NT'">export &quot;WasmXHarnessArgs=$WasmXHarnessArgs --web-server-use-cop&quot;</PreCommands>
<PreCommands Condition="'$(OS)' == 'Windows_NT'">set &quot;WasmXHarnessArgs=%WasmXHarnessArgs% --web-server-use-cop&quot; &amp; set &quot;WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true&quot;</PreCommands>
<PreCommands Condition="'$(OS)' != 'Windows_NT'">export &quot;WasmXHarnessArgs=$WasmXHarnessArgs --web-server-use-cop&quot; &amp;&amp; export &quot;WasmXHarnessMonoArgs=--setenv=TEST_EXPECT_SUBTLE_CRYPTO=true&quot;</PreCommands>
</HelixWorkItem>

<_CryptoHelixItem Include="@(HelixWorkItem)"
Expand Down

0 comments on commit 75cc8fa

Please sign in to comment.