Skip to content

Commit a47139f

Browse files
ryanbrandenburgmkArtakMSFT
authored andcommitted
Fix sha tests
1 parent f8dea0e commit a47139f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Identity/test/Identity.Test/IdentityUIScriptsTest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ public static IEnumerable<object[]> ScriptWithIntegrityData
4141
[MemberData(nameof(ScriptWithIntegrityData))]
4242
public async Task IdentityUI_ScriptTags_SubresourceIntegrityCheck(ScriptTag scriptTag)
4343
{
44-
var sha256Integrity = await GetShaIntegrity(scriptTag, SHA256.Create(), "sha256");
45-
Assert.Equal(scriptTag.Integrity, sha256Integrity);
44+
var integrity = await GetShaIntegrity(scriptTag);
45+
Assert.Equal(scriptTag.Integrity, integrity);
4646
}
4747

48-
private async Task<string> GetShaIntegrity(ScriptTag scriptTag, HashAlgorithm algorithm, string prefix)
48+
private async Task<string> GetShaIntegrity(ScriptTag scriptTag)
4949
{
50+
var isSha256 = scriptTag.Integrity.StartsWith("sha256");
51+
var prefix = isSha256 ? "sha256" : "sha384";
5052
using (var respStream = await _httpClient.GetStreamAsync(scriptTag.Src))
51-
using (var alg = SHA256.Create())
53+
using (var alg = isSha256 ? SHA256.Create() : SHA384.Create())
5254
{
5355
var hash = alg.ComputeHash(respStream);
5456
return $"{prefix}-" + Convert.ToBase64String(hash);

0 commit comments

Comments
 (0)