Skip to content

Commit 271ebe0

Browse files
Merge pull request #16580 from dotnet-maestro-bot/merge/release/3.1-to-master
[automated] Merge branch 'release/3.1' => 'master'
2 parents d967ef8 + 38eebb5 commit 271ebe0

File tree

86 files changed

+11756
-7728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+11756
-7728
lines changed

.azure/pipelines/ci.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ variables:
6565
valule: test
6666
- name: _PublishArgs
6767
value: ''
68-
68+
# used for post-build phases, internal builds only
69+
- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
70+
- group: DotNet-AspNet-SDLValidation-Params
71+
6972
stages:
7073
- stage: build
7174
displayName: Build
@@ -654,3 +657,17 @@ stages:
654657
enableSymbolValidation: false
655658
enableSigningValidation: false
656659
publishInstallersAndChecksums: true
660+
# This is to enable SDL runs part of Post-Build Validation Stage
661+
SDLValidationParameters:
662+
enable: true
663+
continueOnError: false
664+
params: ' -SourceToolsList @("policheck","credscan")
665+
-TsaInstanceURL $(_TsaInstanceURL)
666+
-TsaProjectName $(_TsaProjectName)
667+
-TsaNotificationEmail $(_TsaNotificationEmail)
668+
-TsaCodebaseAdmin $(_TsaCodebaseAdmin)
669+
-TsaBugAreaPath $(_TsaBugAreaPath)
670+
-TsaIterationPath $(_TsaIterationPath)
671+
-TsaRepositoryName "AspNetCore"
672+
-TsaCodebaseName "AspNetCore"
673+
-TsaPublish $True'

eng/Version.Details.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
-->
1010
<Dependencies>
1111
<ProductDependencies>
12-
<Dependency Name="Microsoft.AspNetCore.Blazor.Mono" Version="5.0.0-alpha1.19528.2">
12+
<Dependency Name="Microsoft.AspNetCore.Blazor.Mono" Version="5.0.0-alpha1.19531.2">
1313
<Uri>https://github.com/aspnet/Blazor</Uri>
14-
<Sha>109766852cdedfd07babca70c56b18a508228e1d</Sha>
14+
<Sha>67c011629f56585c6a561dc4bdca70efc43579dd</Sha>
1515
</Dependency>
1616
<Dependency Name="Microsoft.AspNetCore.Razor.Language" Version="5.0.0-alpha1.19531.8">
1717
<Uri>https://github.com/aspnet/AspNetCore-Tooling</Uri>

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
<!-- Only listed explicitly to workaround https://github.com/dotnet/cli/issues/10528 -->
9595
<MicrosoftNETCorePlatformsPackageVersion>5.0.0-alpha1.19520.7</MicrosoftNETCorePlatformsPackageVersion>
9696
<!-- Packages from aspnet/Blazor -->
97-
<MicrosoftAspNetCoreBlazorMonoPackageVersion>5.0.0-alpha1.19528.2</MicrosoftAspNetCoreBlazorMonoPackageVersion>
97+
<MicrosoftAspNetCoreBlazorMonoPackageVersion>5.0.0-alpha1.19531.2</MicrosoftAspNetCoreBlazorMonoPackageVersion>
9898
<!-- Packages from aspnet/Extensions -->
9999
<InternalAspNetCoreAnalyzersPackageVersion>5.0.0-alpha1.19530.2</InternalAspNetCoreAnalyzersPackageVersion>
100100
<MicrosoftAspNetCoreAnalyzerTestingPackageVersion>5.0.0-alpha1.19530.2</MicrosoftAspNetCoreAnalyzerTestingPackageVersion>

src/Analyzers/Analyzers/src/UseAuthorizationAnalyzer.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Diagnostics;
5+
using System.Linq;
56
using Microsoft.CodeAnalysis;
67
using Microsoft.CodeAnalysis.Diagnostics;
78

@@ -27,6 +28,7 @@ public void AnalyzeSymbol(SymbolAnalysisContext context)
2728
{
2829
MiddlewareItem? useAuthorizationItem = default;
2930
MiddlewareItem? useRoutingItem = default;
31+
MiddlewareItem? useEndpoint = default;
3032

3133
var length = middlewareAnalysis.Middleware.Length;
3234
for (var i = length - 1; i >= 0; i-- )
@@ -70,9 +72,24 @@ public void AnalyzeSymbol(SymbolAnalysisContext context)
7072
useAuthorizationItem.Operation.Syntax.GetLocation(),
7173
middlewareItem.UseMethod.Name));
7274
}
75+
76+
useEndpoint = middlewareItem;
7377
}
7478
else if (middleware == "UseRouting")
7579
{
80+
if (useEndpoint is null)
81+
{
82+
// We're likely here because the middleware uses an expression chain e.g.
83+
// app.UseRouting()
84+
// .UseAuthorization()
85+
// .UseEndpoints(..));
86+
// This analyzer expects MiddlewareItem instances to appear in the order in which they appear in source
87+
// which unfortunately isn't true for chained calls (the operations appear in reverse order).
88+
// We'll avoid doing any analysis in this event and rely on the runtime guardrails.
89+
// We'll use https://github.com/aspnet/AspNetCore/issues/16648 to track addressing this in a future milestone
90+
return;
91+
}
92+
7693
useRoutingItem = middlewareItem;
7794
}
7895
}

src/Analyzers/Analyzers/test/StartupAnalyzerTest.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,22 @@ public async Task StartupAnalyzer_UseAuthorizationConfiguredCorrectly_ReportsNoD
244244
Assert.Empty(diagnostics);
245245
}
246246

247+
[Fact]
248+
public async Task StartupAnalyzer_UseAuthorizationConfiguredAsAChain_ReportsNoDiagnostics()
249+
{
250+
// Regression test for https://github.com/aspnet/AspNetCore/issues/15203
251+
// Arrange
252+
var source = Read(nameof(TestFiles.StartupAnalyzerTest.UseAuthConfiguredCorrectlyChained));
253+
254+
// Act
255+
var diagnostics = await Runner.GetDiagnosticsAsync(source.Source);
256+
257+
// Assert
258+
var middlewareAnalysis = Assert.Single(Analyses.OfType<MiddlewareAnalysis>());
259+
Assert.NotEmpty(middlewareAnalysis.Middleware);
260+
Assert.Empty(diagnostics);
261+
}
262+
247263
[Fact]
248264
public async Task StartupAnalyzer_UseAuthorizationInvokedMultipleTimesInEndpointRoutingBlock_ReportsNoDiagnostics()
249265
{
@@ -279,6 +295,23 @@ public async Task StartupAnalyzer_UseAuthorizationConfiguredBeforeUseRouting_Rep
279295
});
280296
}
281297

298+
[Fact]
299+
public async Task StartupAnalyzer_UseAuthorizationConfiguredBeforeUseRoutingChained_ReportsDiagnostics()
300+
{
301+
// This one asserts a false negative for https://github.com/aspnet/AspNetCore/issues/15203.
302+
// We don't correctly identify chained calls, this test verifies the behavior.
303+
// Arrange
304+
var source = Read(nameof(TestFiles.StartupAnalyzerTest.UseAuthBeforeUseRoutingChained));
305+
306+
// Act
307+
var diagnostics = await Runner.GetDiagnosticsAsync(source.Source);
308+
309+
// Assert
310+
var middlewareAnalysis = Assert.Single(Analyses.OfType<MiddlewareAnalysis>());
311+
Assert.NotEmpty(middlewareAnalysis.Middleware);
312+
Assert.Empty(diagnostics);
313+
}
314+
282315
[Fact]
283316
public async Task StartupAnalyzer_UseAuthorizationConfiguredAfterUseEndpoints_ReportsDiagnostics()
284317
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Builder;
5+
6+
namespace Microsoft.AspNetCore.Analyzers.TestFiles.StartupAnalyzerTest {
7+
public class UseAuthBeforeUseRoutingChained
8+
{
9+
public void Configure(IApplicationBuilder app)
10+
{
11+
app.UseFileServer()
12+
.UseAuthorization()
13+
.UseRouting()
14+
.UseEndpoints(r => { });
15+
}
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Builder;
5+
6+
namespace Microsoft.AspNetCore.Analyzers.TestFiles.StartupAnalyzerTest {
7+
public class UseAuthConfiguredCorrectlyChained
8+
{
9+
public void Configure(IApplicationBuilder app)
10+
{
11+
app.UseRouting()
12+
.UseAuthorization()
13+
.UseEndpoints(r => { });
14+
}
15+
}
16+
}

src/Components/Blazor/Blazor/ref/Microsoft.AspNetCore.Blazor.netstandard2.0.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ public enum FetchCredentialsOption
5454
SameOrigin = 1,
5555
Include = 2,
5656
}
57-
public partial class WebAssemblyHttpMessageHandler : System.Net.Http.HttpMessageHandler
57+
public static partial class WebAssemblyHttpMessageHandlerOptions
5858
{
59-
public const string FetchArgs = "WebAssemblyHttpMessageHandler.FetchArgs";
60-
public WebAssemblyHttpMessageHandler() { }
61-
public static Microsoft.AspNetCore.Blazor.Http.FetchCredentialsOption DefaultCredentials { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
62-
[System.Diagnostics.DebuggerStepThroughAttribute]
63-
protected override System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { throw null; }
59+
public static Microsoft.AspNetCore.Blazor.Http.FetchCredentialsOption DefaultCredentials { get { throw null; } set { } }
6460
}
6561
}
6662
namespace Microsoft.AspNetCore.Blazor.Rendering

src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHost.cs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Net.Http;
6-
using System.Reflection;
75
using System.Threading;
86
using System.Threading.Tasks;
9-
using Microsoft.AspNetCore.Blazor.Http;
107
using Microsoft.AspNetCore.Blazor.Rendering;
118
using Microsoft.Extensions.DependencyInjection;
129
using Microsoft.JSInterop;
@@ -30,16 +27,6 @@ public WebAssemblyHost(IServiceProvider services, IJSRuntime runtime)
3027

3128
public Task StartAsync(CancellationToken cancellationToken = default)
3229
{
33-
// We need to do this as early as possible, it eliminates a bunch of problems. Note that what we do
34-
// is a bit fragile. If you see things breaking because JSRuntime.Current isn't set, then it's likely
35-
// that something on the startup path went wrong.
36-
//
37-
// We want to the JSRuntime created here to be the 'ambient' runtime when JS calls back into .NET. When
38-
// this happens in the browser it will be a direct call from Mono. We effectively needs to set the
39-
// JSRuntime in the 'root' execution context which implies that we want to do as part of a direct
40-
// call from Program.Main, and before any 'awaits'.
41-
SetBrowserHttpMessageHandlerAsDefault();
42-
4330
return StartAsyncAwaited();
4431
}
4532

@@ -102,35 +89,5 @@ public void Dispose()
10289
{
10390
(Services as IDisposable)?.Dispose();
10491
}
105-
106-
private static void SetBrowserHttpMessageHandlerAsDefault()
107-
{
108-
// Within the Mono WebAssembly BCL, this is a special private static field
109-
// that can be assigned to override the default handler
110-
const string getHttpMessageHandlerFieldName = "GetHttpMessageHandler";
111-
var getHttpMessageHandlerField = typeof(HttpClient).GetField(
112-
getHttpMessageHandlerFieldName,
113-
BindingFlags.Static | BindingFlags.NonPublic);
114-
115-
// getHttpMessageHandlerField will be null in tests, but nonnull when actually
116-
// running under Mono WebAssembly
117-
if (getHttpMessageHandlerField != null)
118-
{
119-
// Just in case you're not actually using HttpClient, defer the construction
120-
// of the WebAssemblyHttpMessageHandler
121-
var handlerSingleton = new Lazy<HttpMessageHandler>(
122-
() => new WebAssemblyHttpMessageHandler());
123-
Func<HttpMessageHandler> handlerFactory = () => handlerSingleton.Value;
124-
getHttpMessageHandlerField.SetValue(null, handlerFactory);
125-
}
126-
else
127-
{
128-
// We log a warning in case this ever happens at runtime (even though there's
129-
// no obvious way it could be possible), but don't actually throw because that
130-
// would break unit tests
131-
Console.WriteLine("WARNING: Could not set default HttpMessageHandler because " +
132-
$"'{getHttpMessageHandlerFieldName}' was not found on '{typeof(HttpClient).FullName}'.");
133-
}
134-
}
13592
}
13693
}

0 commit comments

Comments
 (0)