Skip to content

Commit 36ea4de

Browse files
[main] Source code updates from dotnet/aspnetcore (#4872)
[main] Source code updates from dotnet/aspnetcore
1 parent ebc8503 commit 36ea4de

17 files changed

Lines changed: 682 additions & 331 deletions

File tree

src/aspnetcore/.github/workflows/backport.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ permissions:
1414

1515
jobs:
1616
backport:
17-
uses: dotnet/arcade/.github/workflows/backport-base.yml@656bdecfc772fca7eba40c0c6983b58b21bbe4be # 2025-01-13
17+
uses: dotnet/arcade/.github/workflows/backport-base.yml@ab22aeec12730f321addeb11568f0213b23ac3f4 # 2025-01-13
1818
with:
1919
pr_description_template: |
2020
Backport of #%source_pr_number% to %target_branch%

src/aspnetcore/.github/workflows/inter-branch-merge-flow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ permissions:
1111

1212
jobs:
1313
Merge:
14-
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@656bdecfc772fca7eba40c0c6983b58b21bbe4be # 2024-06-24
14+
uses: dotnet/arcade/.github/workflows/inter-branch-merge-base.yml@ab22aeec12730f321addeb11568f0213b23ac3f4 # 2024-06-24

src/aspnetcore/docs/EventSourceAndCounters.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,34 @@ namespace Microsoft.AspNetCore.Authentication.Internal
169169

170170
## Automated Testing of EventSources
171171

172-
EventSources can be tested using the `EventSourceTestBase` base class in `Microsoft.AspNetCore.InternalTesting`. An example test is below:
172+
### Validating Event ID Consistency
173+
174+
All `EventSource` subclasses should have a test that validates the `[Event(N)]` attribute IDs match the `WriteEvent(N, ...)` call arguments. This catches drift caused by bad merge resolution or missed updates that would otherwise surface only as runtime errors.
175+
176+
Use the `EventSourceValidator` utility in `Microsoft.AspNetCore.InternalTesting.Tracing`:
177+
178+
```csharp
179+
using Microsoft.AspNetCore.InternalTesting.Tracing;
180+
181+
public class MyEventSourceTests
182+
{
183+
[Fact]
184+
public void EventIdsAreConsistent()
185+
{
186+
EventSourceValidator.ValidateEventSourceIds<MyEventSource>();
187+
}
188+
}
189+
```
190+
191+
The validator:
192+
* Uses `EventSource.GenerateManifest` with `EventManifestOptions.Strict` to perform IL-level validation that each `WriteEvent(id, ...)` call argument matches the `[Event(id)]` attribute — the same validation the .NET runtime uses internally
193+
* Checks for duplicate event IDs across methods
194+
195+
> **Important:** Every new `EventSource` class should include this one-line validation test.
196+
197+
### Functional Testing with EventSourceTestBase
198+
199+
EventSources can also be functionally tested using the `EventSourceTestBase` base class in `Microsoft.AspNetCore.InternalTesting`. An example test is below:
173200

174201
```csharp
175202
// The base class MUST be used for EventSource testing because EventSources are global and parallel tests can cause issues.

src/aspnetcore/eng/Version.Details.props

Lines changed: 92 additions & 92 deletions
Large diffs are not rendered by default.

src/aspnetcore/eng/Version.Details.xml

Lines changed: 185 additions & 185 deletions
Large diffs are not rendered by default.

src/aspnetcore/global.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
"jdk": "latest"
2323
},
2424
"msbuild-sdks": {
25-
"Microsoft.DotNet.Arcade.Sdk": "11.0.0-beta.26111.109",
26-
"Microsoft.DotNet.Helix.Sdk": "11.0.0-beta.26111.109",
27-
"Microsoft.DotNet.SharedFramework.Sdk": "11.0.0-beta.26111.109",
25+
"Microsoft.DotNet.Arcade.Sdk": "11.0.0-beta.26112.105",
26+
"Microsoft.DotNet.Helix.Sdk": "11.0.0-beta.26112.105",
27+
"Microsoft.DotNet.SharedFramework.Sdk": "11.0.0-beta.26112.105",
2828
"Microsoft.Build.NoTargets": "3.7.0",
2929
"Microsoft.Build.Traversal": "3.4.0",
3030
"Microsoft.WixToolset.Sdk": "5.0.2-dotnet.2811440"

src/aspnetcore/src/Hosting/Hosting/test/Internal/HostingEventSourceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
using Microsoft.AspNetCore.Http;
77
using Microsoft.AspNetCore.Internal;
88
using Microsoft.AspNetCore.InternalTesting;
9+
using Microsoft.AspNetCore.InternalTesting.Tracing;
910
using Microsoft.Extensions.Logging;
1011

1112
namespace Microsoft.AspNetCore.Hosting;
1213

1314
public class HostingEventSourceTests : LoggedTest
1415
{
16+
[Fact]
17+
public void EventIdsAreConsistent()
18+
{
19+
EventSourceValidator.ValidateEventSourceIds(typeof(HostingEventSource));
20+
}
21+
1522
[Fact]
1623
public void MatchesNameAndGuid()
1724
{

src/aspnetcore/src/Servers/HttpSys/src/NativeInterop/UrlGroup.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ internal sealed partial class UrlGroup : IDisposable
1818
Marshal.SizeOf<HTTP_QOS_SETTING_INFO>();
1919
private static readonly int RequestPropertyInfoSize =
2020
Marshal.SizeOf<HTTP_BINDING_INFO>();
21+
private static readonly int ChannelBindInfoSize =
22+
Marshal.SizeOf<HTTP_CHANNEL_BIND_INFO>();
2123

2224
private readonly ILogger _logger;
2325

@@ -42,6 +44,17 @@ internal unsafe UrlGroup(ServerSession serverSession, RequestQueue requestQueue,
4244

4345
Debug.Assert(urlGroupId != 0, "Invalid id returned by HttpCreateUrlGroup");
4446
Id = urlGroupId;
47+
48+
if (AppContext.TryGetSwitch("Microsoft.AspNetCore.Server.HttpSys.EnableCBTHardening", out var enabled) && enabled)
49+
{
50+
var channelBindingSettings = new HTTP_CHANNEL_BIND_INFO
51+
{
52+
Hardening = HTTP_AUTHENTICATION_HARDENING_LEVELS.HttpAuthenticationHardeningMedium,
53+
ServiceNames = (HTTP_SERVICE_BINDING_BASE**)IntPtr.Zero,
54+
NumberOfServiceNames = 0,
55+
};
56+
SetProperty(HTTP_SERVER_PROPERTY.HttpServerChannelBindProperty, new(&channelBindingSettings), (uint)ChannelBindInfoSize);
57+
}
4558
}
4659

4760
internal ulong Id { get; private set; }

src/aspnetcore/src/Servers/HttpSys/src/NativeMethods.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ HTTP_AUTH_EX_FLAG_*
99
HTTP_AUTH_STATUS
1010
HTTP_BINDING_INFO
1111
HTTP_CACHE_POLICY
12+
HTTP_CHANNEL_BIND_INFO
1213
HTTP_CONNECTION_LIMIT_INFO
1314
HTTP_COOKED_URL
1415
HTTP_CREATE_REQUEST_QUEUE_FLAG_*

src/aspnetcore/src/Servers/Kestrel/Core/test/KestrelEventSourceTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics.Tracing;
66
using System.Globalization;
77
using System.Reflection;
8+
using Microsoft.AspNetCore.InternalTesting.Tracing;
89
using Xunit;
910

1011
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests;
@@ -26,4 +27,16 @@ public void ExistsWithCorrectId()
2627
Assert.Equal(Guid.Parse("bdeb4676-a36e-5442-db99-4764e2326c7d", CultureInfo.InvariantCulture), EventSource.GetGuid(esType));
2728
Assert.NotEmpty(EventSource.GenerateManifest(esType, "assemblyPathToIncludeInManifest"));
2829
}
30+
31+
[Fact]
32+
public void EventIdsAreConsistent()
33+
{
34+
var esType = typeof(KestrelServer).Assembly.GetType(
35+
"Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelEventSource",
36+
throwOnError: true,
37+
ignoreCase: false
38+
);
39+
40+
EventSourceValidator.ValidateEventSourceIds(esType);
41+
}
2942
}

0 commit comments

Comments
 (0)