public void Parse_SchemeHostAndWildCardPort_ReturnsResult() { var result = CspUriSource.Parse("https://www.nwebsec.com:*"); Assert.Equal("https://www.nwebsec.com:*", result.ToString()); }
public void Parse_SchemeIdnHostPortAndPath_ReturnsResult() { var result = CspUriSource.Parse("https://www.üüüüüü.com:8000/some/path"); Assert.Equal("https://www.xn--tdaaaaaa.com:8000/some/path", result.ToString()); }
public void Parse_SchemeHostPortAndPath_ReturnsResult() { var result = CspUriSource.Parse("https://www.nwebsec.com:8000/some/Path"); Assert.Equal("https://www.nwebsec.com:8000/some/Path", result.ToString()); }
public void Parse_SchemeHostPathAndQueryWithNonAsciiChars_ReturnsEncodedPathResult() { var result = CspUriSource.Parse("https://www.nwebsec.com/André?a=b"); Assert.Equal("https://www.nwebsec.com/Andr%C3%A9?a=b", result.ToString()); }
public void Parse_SchemeHostAndPathWithSpecialChars_ReturnsEncodedPathResult() { var result = CspUriSource.Parse("https://www.nwebsec.com/hello;hello,"); Assert.Equal("https://www.nwebsec.com/hello%3Bhello%2C", result.ToString()); }
/// <summary> /// Sets custom sources for the CSP directive. /// </summary> /// <typeparam name="T">The type of the CSP directive configuration object.</typeparam> /// <param name="directive">The CSP directive configuration object.</param> /// <param name="sources">One or more custom sources.</param> /// <returns>The CSP directive configuration object.</returns> public static T CustomSources <T>(this T directive, params string[] sources) where T : class, ICspDirectiveBasicConfiguration { if (directive == null) { throw new ArgumentNullException(nameof(directive)); } if (sources.Length == 0) { throw new ArgumentException("You must supply at least one source.", nameof(sources)); } try { var type = typeof(T); var enableHashes = type == typeof(ICspDirectiveConfiguration) || type == typeof(ICspDirectiveUnsafeInlineConfiguration); directive.CustomSources = sources .Select(s => (enableHashes ? CspHashSource.Parse(s) : null) ?? CspUriSource.Parse(s).ToString()) .ToArray(); } catch (InvalidCspSourceException e) { throw new ArgumentException("Invalid source. Details: " + e.Message, nameof(sources), e); } return(directive); }