public async Task ProcessAsync_Script_AddsHashToHttpContextForMultiLineSnippets() { // Arrange var id = Guid.NewGuid().ToString(); var tagName = "script"; var tagHelperContext = GetTagHelperContext(id, tagName); var tagHelper = new HashTagHelper() { CSPHashType = CSPHashType.SHA256, ViewContext = GetViewContext(), }; var output = new TagHelperOutput( tagName, attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetHtmlContent(scriptSnippet); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); // Act await tagHelper.ProcessAsync(tagHelperContext, output); // Assert var hash = Assert.Single(tagHelper.ViewContext.HttpContext.GetScriptCSPHashes()); var expected = "'sha256-Oro8tit8euyKzxqyJteBRTdQBlipvXGQWfS5epMHmUU='"; Assert.Equal(expected, hash); }
public async Task ProcessAsync_Script_GeneratesExpectedOutput() { // Arrange var id = Guid.NewGuid().ToString(); var tagName = "script"; var tagHelperContext = GetTagHelperContext(id, tagName); var tagHelper = new HashTagHelper() { CSPHashType = CSPHashType.SHA256, ViewContext = GetViewContext(), }; var output = new TagHelperOutput( tagName, attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetHtmlContent(scriptSnippet); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); output.Content.SetHtmlContent(shortSnippet); // Act await tagHelper.ProcessAsync(tagHelperContext, output); // Assert Assert.Equal(tagName, output.TagName); Assert.Empty(output.Attributes); Assert.Equal(shortSnippet, output.Content.GetContent()); }
public async Task ProcessAsync_Script_AddsHashToHttpContextForOneLineSnippets() { // Arrange var id = Guid.NewGuid().ToString(); var tagName = "script"; var tagHelperContext = GetTagHelperContext(id, tagName); var tagHelper = new HashTagHelper() { CSPHashType = CSPHashType.SHA256, ViewContext = GetViewContext(), }; var output = new TagHelperOutput( tagName, attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetHtmlContent(shortSnippet); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); // Act await tagHelper.ProcessAsync(tagHelperContext, output); // Assert var hash = Assert.Single(tagHelper.ViewContext.HttpContext.GetScriptCSPHashes()); var expected = "'sha256-1yLcYHZUiV92moZ6snTrg6e0yBO8emEEpUSB2wlMFz8='"; Assert.Equal(expected, hash); }
public async Task ProcessAsync_Style_AddsHashToHttpContextForOneLineSnippets() { // Arrange var id = Guid.NewGuid().ToString(); var tagName = "style"; var tagHelperContext = GetTagHelperContext(id, tagName); var tagHelper = new HashTagHelper() { CSPHashType = CSPHashType.SHA256, ViewContext = GetViewContext(), }; var output = new TagHelperOutput( tagName, attributes: new TagHelperAttributeList(), getChildContentAsync: (useCachedResult, encoder) => { var tagHelperContent = new DefaultTagHelperContent(); tagHelperContent.SetHtmlContent(styleSnippet); return(Task.FromResult <TagHelperContent>(tagHelperContent)); }); // Act await tagHelper.ProcessAsync(tagHelperContext, output); // Assert var hash = Assert.Single(tagHelper.ViewContext.HttpContext.GetStyleCSPHashes()); var expected = "'sha256-Wz9o8J/ijdXtAzs95rmQ8OtBacYk6JfYTXQlM8yxIjg='"; Assert.Equal(expected, hash); }