File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
src/Identity/test/Identity.Test Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -41,14 +41,16 @@ public static IEnumerable<object[]> ScriptWithIntegrityData
41
41
[ MemberData ( nameof ( ScriptWithIntegrityData ) ) ]
42
42
public async Task IdentityUI_ScriptTags_SubresourceIntegrityCheck ( ScriptTag scriptTag )
43
43
{
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 ) ;
46
46
}
47
47
48
- private async Task < string > GetShaIntegrity ( ScriptTag scriptTag , HashAlgorithm algorithm , string prefix )
48
+ private async Task < string > GetShaIntegrity ( ScriptTag scriptTag )
49
49
{
50
+ var isSha256 = scriptTag . Integrity . StartsWith ( "sha256" ) ;
51
+ var prefix = isSha256 ? "sha256" : "sha384" ;
50
52
using ( var respStream = await _httpClient . GetStreamAsync ( scriptTag . Src ) )
51
- using ( var alg = SHA256 . Create ( ) )
53
+ using ( var alg = isSha256 ? SHA256 . Create ( ) : SHA384 . Create ( ) )
52
54
{
53
55
var hash = alg . ComputeHash ( respStream ) ;
54
56
return $ "{ prefix } -" + Convert . ToBase64String ( hash ) ;
You can’t perform that action at this time.
0 commit comments