-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
163 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/Components/test/E2ETest/ServerExecutionTests/WebSocketCompressionTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text.RegularExpressions; | ||
using Components.TestServer.RazorComponents; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; | ||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
using Microsoft.AspNetCore.E2ETesting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.VisualStudio.TestPlatform.Utilities; | ||
using OpenQA.Selenium; | ||
using TestServer; | ||
using Xunit.Abstractions; | ||
|
||
namespace Microsoft.AspNetCore.Components.E2ETests.ServerExecutionTests; | ||
|
||
public abstract partial class AllowedWebSocketCompressionTests( | ||
BrowserFixture browserFixture, | ||
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture, | ||
ITestOutputHelper output) | ||
: ServerTestBase<BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>>>(browserFixture, serverFixture, output) | ||
{ | ||
[Fact] | ||
public void EmbeddingServerAppInsideIframe_Works() | ||
{ | ||
Navigate("/subdir/iframe"); | ||
|
||
var logs = Browser.GetBrowserLogs(LogLevel.Severe); | ||
|
||
Assert.Empty(logs); | ||
|
||
// Get the iframe element from the page, and inspect its contents for a p element with id inside-iframe | ||
var iframe = Browser.FindElement(By.TagName("iframe")); | ||
Browser.SwitchTo().Frame(iframe); | ||
Browser.Exists(By.Id("inside-iframe")); | ||
} | ||
} | ||
|
||
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.Matches(ParseErrorMessage(), 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 ParseErrorMessage(); | ||
} | ||
|
||
public partial class DefaultConfigurationWebSocketCompressionTests( | ||
BrowserFixture browserFixture, | ||
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture, | ||
ITestOutputHelper output) | ||
: BlockedWebSocketCompressionTests(browserFixture, serverFixture, output) | ||
{ | ||
} | ||
|
||
public partial class CustomConfigurationCallbackWebSocketCompressionTests : BlockedWebSocketCompressionTests | ||
{ | ||
public CustomConfigurationCallbackWebSocketCompressionTests( | ||
BrowserFixture browserFixture, | ||
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture, | ||
ITestOutputHelper output) : base(browserFixture, serverFixture, output) | ||
{ | ||
serverFixture.UpdateHostServices = services => | ||
{ | ||
var configuration = services.GetService<WebSocketCompressionConfiguration>(); | ||
configuration.ConnectionDispatcherOptions = options => | ||
options.WebSockets.WebSocketAcceptContextFactory = context => | ||
new Http.WebSocketAcceptContext { DangerousEnableCompression = true }; | ||
}; | ||
} | ||
} | ||
|
||
public partial class CompressionDisabledWebSocketCompressionTests : AllowedWebSocketCompressionTests | ||
{ | ||
public CompressionDisabledWebSocketCompressionTests( | ||
BrowserFixture browserFixture, | ||
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture, | ||
ITestOutputHelper output) : base( | ||
browserFixture, serverFixture, output) | ||
{ | ||
serverFixture.UpdateHostServices = services => | ||
{ | ||
var configuration = services.GetService<WebSocketCompressionConfiguration>(); | ||
configuration.IsCompressionEnabled = false; | ||
}; | ||
} | ||
} | ||
|
||
public partial class SelfFrameAncestorWebSocketCompressionTests : AllowedWebSocketCompressionTests | ||
{ | ||
public SelfFrameAncestorWebSocketCompressionTests( | ||
BrowserFixture browserFixture, | ||
BasicTestAppServerSiteFixture<RazorComponentEndpointsStartup<App>> serverFixture, | ||
ITestOutputHelper output) | ||
: base(browserFixture, serverFixture, output) | ||
{ | ||
serverFixture.UpdateHostServices = services => | ||
{ | ||
var configuration = services.GetService<WebSocketCompressionConfiguration>(); | ||
configuration.CspPolicy = "'self'"; | ||
}; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...nts.TestServer/RazorComponents/Pages/CanNotEmbedAppInsideIFrameWhenUsingCompression.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@page "/iframe" | ||
|
||
<iframe src="embedded"></iframe> |
4 changes: 4 additions & 0 deletions
4
...ts/test/testassets/Components.TestServer/RazorComponents/Pages/EmbeddedInsideIFrame.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@page "/embedded" | ||
@rendermode Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer | ||
|
||
<p id="inside-iframe">This is some content embedded inside an iframe</p> |
15 changes: 15 additions & 0 deletions
15
src/Components/test/testassets/Components.TestServer/WebSocketCompressionConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Http.Connections; | ||
|
||
namespace TestServer; | ||
|
||
public class WebSocketCompressionConfiguration | ||
{ | ||
public bool IsCompressionEnabled { get; set; } = true; | ||
|
||
public string CspPolicy { get; set; } = "'none'"; | ||
|
||
public Action<HttpConnectionDispatcherOptions> ConnectionDispatcherOptions { get; set; } | ||
} |