Esempio n. 1
0
        public void AddingScriptAddsHashToHeaderValue()
        {
            var testPolicy = ContentSecurityPolicy.Empty();

            var scriptContents = "console.log('example script');";

            var scriptBytes = Encoding.UTF8.GetBytes(scriptContents);

            var hashedContents = SHA256Managed.Create().ComputeHash(scriptBytes).Select(x => x.ToString("x2")).Aggregate((a, b) => $"{a}{b}");

            Assert.AreEqual($"script-src 'sha256-{hashedContents}';", testPolicy.AddScript(scriptContents).GetHeaderValue());
        }
Esempio n. 2
0
        public void AddingScriptReturnsNewPolicy()
        {
            var testPolicy = ContentSecurityPolicy.Empty();

            Assert.AreNotSame(testPolicy, testPolicy.AddScript("console.log('example script');"));
        }