Repository: dotnet/aspnetcore
File: src/Components/test/E2ETest/ServerExecutionTests/WebSocketCompressionTests.cs (C#)

Code before:
                    "script-src 'self' 'unsafe-inline'"
                ],
                response.Headers.GetValues("Content-Security-Policy"));
        }
    }
}

public abstract partial class BlockedWebSocketCompressionTests(
    BrowserFixture browserFixture,
    BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
    ITestOutputHelper output)
    : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>>(browserFixture, serverFixture, output)
{
    [Fact]
    public void EmbeddingServerAppInsideIframe_WithCompressionEnabled_Fails()
    {
        Navigate("/subdir/iframe");

        var logs = Browser.GetBrowserLogs(LogLevel.Severe);

        Assert.True(logs.Count > 0);

        Assert.True(
            ParseErrorMessageRegexOld.IsMatch(logs[0].Message) ||
            ParseErrorMessageRegexNew.IsMatch(logs[0].Message),
            $"Expected log message to match one of the CSP error patterns. Actual: {logs[0].Message}");
    }

    [GeneratedRegex(@"security - Refused to frame 'http://\d+\.\d+\.\d+\.\d+:\d+/' because an ancestor violates the following Content Security Policy directive: ""frame-ancestors 'none'"".")]
    private static partial Regex ParseErrorMessageRegexOld { get; }

    [GeneratedRegex(@"security - Framing 'http://\d+\.\d+\.\d+\.\d+:\d+/' violates the following Content Security Policy directive: ""frame-ancestors 'none'"".")]
    private static partial Regex ParseErrorMessageRegexNew { get; }
}

public partial class DefaultConfigurationWebSocketCompressionTests : AllowedWebSocketCompressionTests
{
    public DefaultConfigurationWebSocketCompressionTests(
        BrowserFixture browserFixture,
        BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
        ITestOutputHelper output) : base(browserFixture, serverFixture, output)
    {
        ExpectedPolicy = "'self'";
    }
}

public partial class CustomConfigurationCallbackWebSocketCompressionTests : AllowedWebSocketCompressionTests
{
    public CustomConfigurationCallbackWebSocketCompressionTests(
        BrowserFixture browserFixture,
        BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,

Review comment (suggestion):
```suggestion
            $"Expected log message to match one of the CSP error patterns: {ParseErrorMessageRegexOld} or {ParseErrorMessageRegexNew}. Actual: {logs[0].Message}");
```

Code after:
                    "script-src 'self' 'unsafe-inline'"
                ],
                response.Headers.GetValues("Content-Security-Policy"));
        }
    }
}

public abstract partial class BlockedWebSocketCompressionTests(
    BrowserFixture browserFixture,
    BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
    ITestOutputHelper output)
    : ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>>(browserFixture, serverFixture, output)
{
    [Fact]
    public void EmbeddingServerAppInsideIframe_WithCompressionEnabled_Fails()
    {
        Navigate("/subdir/iframe");

        var logs = Browser.GetBrowserLogs(LogLevel.Severe);

        Assert.True(logs.Count > 0);

        Assert.True(
            ParseErrorMessageRegexOld.IsMatch(logs[0].Message) ||
            ParseErrorMessageRegexNew.IsMatch(logs[0].Message),
            $"Expected log message to match one of the CSP error patterns: {ParseErrorMessageRegexOld} or {ParseErrorMessageRegexNew}. Actual: {logs[0].Message}");
    }

    [GeneratedRegex(@"security - Refused to frame 'http://\d+\.\d+\.\d+\.\d+:\d+/' because an ancestor violates the following Content Security Policy directive: ""frame-ancestors 'none'"".")]
    private static partial Regex ParseErrorMessageRegexOld { get; }

    [GeneratedRegex(@"security - Framing 'http://\d+\.\d+\.\d+\.\d+:\d+/' violates the following Content Security Policy directive: ""frame-ancestors 'none'"".")]
    private static partial Regex ParseErrorMessageRegexNew { get; }
}

public partial class DefaultConfigurationWebSocketCompressionTests : AllowedWebSocketCompressionTests
{
    public DefaultConfigurationWebSocketCompressionTests(
        BrowserFixture browserFixture,
        BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,
        ITestOutputHelper output) : base(browserFixture, serverFixture, output)
    {
        ExpectedPolicy = "'self'";
    }
}

public partial class CustomConfigurationCallbackWebSocketCompressionTests : AllowedWebSocketCompressionTests
{
    public CustomConfigurationCallbackWebSocketCompressionTests(
        BrowserFixture browserFixture,
        BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture,