コード例 #1
0
        public void ToString_ReturnsFormattedString()
        {
            var reportDetails = new CspReportDetails
            {
                BlockedUri         = "blockeduri",
                ColumnNumber       = "columnnumber",
                DocumentUri        = "documenturi",
                EffectiveDirective = "effectivedirective",
                LineNumber         = "linenumber",
                OriginalPolicy     = "originalpolicy",
                Referrer           = "referrer",
                ScriptSample       = "scriptsample",
                SourceFile         = "sourcefile",
                StatusCode         = "statuscode",
                ViolatedDirective  = "violateddirective"
            };

            var violationReport = new CspViolationReport
            {
                Details   = reportDetails,
                UserAgent = "useragent"
            };

            const string expectedResult =
                @"DocumentUri=""documenturi""
EffectiveDirective=""effectivedirective""
ViolatedDirective=""violateddirective""
OriginalPolicy=""originalpolicy""
BlockedUri=""blockeduri""
UserAgent=""useragent""
Referrer=""referrer""
StatusCode=""statuscode""
SourceFile=""sourcefile""
LineNumber=""linenumber""
ColumnNumber=""columnnumber""
ScriptSample=""scriptsample""";

            var result = violationReport.ToString();

            Assert.Equal(expectedResult, result);
        }
コード例 #2
0
 /// <summary>
 /// Handles the Content Security Policy (CSP) violation errors. For more information see FilterConfig.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="CspViolationReportEventArgs"/> instance containing the event data.</param>
 protected void NWebsecHttpHeaderSecurityModule_CspViolationReported(object sender, CspViolationReportEventArgs e)
 {
     // Log the Content Security Policy (CSP) violation.
     CspViolationReport violationReport       = e.ViolationReport;
     CspReportDetails   reportDetails         = violationReport.Details;
     string             violationReportString = string.Format(
         "UserAgent:<{0}>\r\nBlockedUri:<{1}>\r\nColumnNumber:<{2}>\r\nDocumentUri:<{3}>\r\nEffectiveDirective:<{4}>\r\nLineNumber:<{5}>\r\nOriginalPolicy:<{6}>\r\nReferrer:<{7}>\r\nScriptSample:<{8}>\r\nSourceFile:<{9}>\r\nStatusCode:<{10}>\r\nViolatedDirective:<{11}>",
         violationReport.UserAgent,
         reportDetails.BlockedUri,
         reportDetails.ColumnNumber,
         reportDetails.DocumentUri,
         reportDetails.EffectiveDirective,
         reportDetails.LineNumber,
         reportDetails.OriginalPolicy,
         reportDetails.Referrer,
         reportDetails.ScriptSample,
         reportDetails.SourceFile,
         reportDetails.StatusCode,
         reportDetails.ViolatedDirective);
     CspViolationException exception = new CspViolationException(violationReportString);
     //DependencyResolver.Current.GetService<ILogService>().Log(exception);
 }