Skip to content

Commit 1e03d57

Browse files
Merge branch 'master' into halter73/mega-merge
2 parents 2d066dc + b669875 commit 1e03d57

File tree

12 files changed

+119
-13
lines changed

12 files changed

+119
-13
lines changed

src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Diagnostics;
66
using System.Runtime.CompilerServices;
7+
using System.Web;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.Extensions.Logging;
910
using Microsoft.Extensions.Primitives;
@@ -272,7 +273,7 @@ private Activity StartActivity(HttpContext httpContext, out bool hasDiagnosticLi
272273
{
273274
if (NameValueHeaderValue.TryParse(item, out var baggageItem))
274275
{
275-
activity.AddBaggage(baggageItem.Name.ToString(), baggageItem.Value.ToString());
276+
activity.AddBaggage(baggageItem.Name.ToString(), HttpUtility.UrlDecode(baggageItem.Value.ToString()));
276277
}
277278
}
278279
}

src/Hosting/Hosting/test/HostingApplicationDiagnosticsTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,35 @@ public void ActivityParentIdAndBaggeReadFromHeaders()
345345
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key2" && pair.Value == "value2");
346346
}
347347

348+
[Fact]
349+
public void ActivityBaggageValuesAreUrlDecodedFromHeaders()
350+
{
351+
var diagnosticListener = new DiagnosticListener("DummySource");
352+
var hostingApplication = CreateApplication(out var features, diagnosticListener: diagnosticListener);
353+
354+
diagnosticListener.Subscribe(new CallbackDiagnosticListener(pair => { }),
355+
s =>
356+
{
357+
if (s.StartsWith("Microsoft.AspNetCore.Hosting.HttpRequestIn"))
358+
{
359+
return true;
360+
}
361+
return false;
362+
});
363+
364+
features.Set<IHttpRequestFeature>(new HttpRequestFeature()
365+
{
366+
Headers = new HeaderDictionary()
367+
{
368+
{"Request-Id", "ParentId1"},
369+
{"Correlation-Context", "Key1=value1%2F1"}
370+
}
371+
});
372+
hostingApplication.CreateContext(features);
373+
Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", Activity.Current.OperationName);
374+
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key1" && pair.Value == "value1/1");
375+
}
376+
348377

349378
[Fact]
350379
public void ActivityTraceParentAndTraceStateFromHeaders()

src/Identity/Extensions.Core/ref/Microsoft.Extensions.Identity.Core.netcoreapp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public AuthenticatorTokenProvider() { }
1515
public partial class ClaimsIdentityOptions
1616
{
1717
public ClaimsIdentityOptions() { }
18+
public string EmailClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
1819
public string RoleClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
1920
public string SecurityStampClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
2021
public string UserIdClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }

src/Identity/Extensions.Core/ref/Microsoft.Extensions.Identity.Core.netstandard2.0.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public AuthenticatorTokenProvider() { }
1515
public partial class ClaimsIdentityOptions
1616
{
1717
public ClaimsIdentityOptions() { }
18+
public string EmailClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
1819
public string RoleClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
1920
public string SecurityStampClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
2021
public string UserIdClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }

src/Identity/Extensions.Core/src/ClaimsIdentityOptions.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ public class ClaimsIdentityOptions
2525
/// </summary>
2626
public string UserIdClaimType { get; set; } = ClaimTypes.NameIdentifier;
2727

28+
/// <summary>
29+
/// Gets or sets the ClaimType used for the user email claim. Defaults to <see cref="ClaimTypes.Email"/>.
30+
/// </summary>
31+
public string EmailClaimType { get; set; } = ClaimTypes.Email;
32+
2833
/// <summary>
2934
/// Gets or sets the ClaimType used for the security stamp claim. Defaults to "AspNet.Identity.SecurityStamp".
3035
/// </summary>
3136
public string SecurityStampClaimType { get; set; } = "AspNet.Identity.SecurityStamp";
3237
}
33-
}
38+
}

src/Identity/Extensions.Core/src/UserClaimsPrincipalFactory.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ protected virtual async Task<ClaimsIdentity> GenerateClaimsAsync(TUser user)
8181
Options.ClaimsIdentity.RoleClaimType);
8282
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
8383
id.AddClaim(new Claim(Options.ClaimsIdentity.UserNameClaimType, userName));
84+
if (UserManager.SupportsUserEmail)
85+
{
86+
var email = await UserManager.GetEmailAsync(user);
87+
if (!string.IsNullOrEmpty(email))
88+
{
89+
id.AddClaim(new Claim(Options.ClaimsIdentity.EmailClaimType, email));
90+
}
91+
}
8492
if (UserManager.SupportsUserSecurityStamp)
8593
{
8694
id.AddClaim(new Claim(Options.ClaimsIdentity.SecurityStampClaimType,
@@ -154,4 +162,4 @@ protected override async Task<ClaimsIdentity> GenerateClaimsAsync(TUser user)
154162
return id;
155163
}
156164
}
157-
}
165+
}

src/Identity/test/Identity.Test/UserClaimsPrincipalFactoryTest.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,33 @@ await Assert.ThrowsAsync<ArgumentNullException>("user",
3030
}
3131

3232
[Theory]
33-
[InlineData(false, false, false)]
34-
[InlineData(false, true, false)]
35-
[InlineData(true, false, false)]
36-
[InlineData(true, true, false)]
37-
[InlineData(true, false, true)]
38-
[InlineData(true, true, true)]
39-
public async Task EnsureClaimsIdentityHasExpectedClaims(bool supportRoles, bool supportClaims, bool supportRoleClaims)
33+
[InlineData(true, false, false, false)]
34+
[InlineData(true, true, false, false)]
35+
[InlineData(true, false, true, false)]
36+
[InlineData(true, true, true, false)]
37+
[InlineData(false, false, false, true)]
38+
[InlineData(false, true, false, true)]
39+
[InlineData(false, false, false, false)]
40+
[InlineData(false, true, false, false)]
41+
[InlineData(true, false, false, true)]
42+
[InlineData(true, true, false, true)]
43+
[InlineData(true, false, true, true)]
44+
[InlineData(true, true, true, true)]
45+
public async Task EnsureClaimsIdentityHasExpectedClaims(bool supportRoles, bool supportClaims, bool supportRoleClaims, bool supportsUserEmail)
4046
{
4147
// Setup
4248
var userManager = MockHelpers.MockUserManager<PocoUser>();
4349
var roleManager = MockHelpers.MockRoleManager<PocoRole>();
44-
var user = new PocoUser { UserName = "Foo" };
50+
var user = new PocoUser { UserName = "Foo", Email = "[email protected]" };
4551
userManager.Setup(m => m.SupportsUserClaim).Returns(supportClaims);
4652
userManager.Setup(m => m.SupportsUserRole).Returns(supportRoles);
53+
userManager.Setup(m => m.SupportsUserEmail).Returns(supportsUserEmail);
4754
userManager.Setup(m => m.GetUserIdAsync(user)).ReturnsAsync(user.Id);
4855
userManager.Setup(m => m.GetUserNameAsync(user)).ReturnsAsync(user.UserName);
56+
if (supportsUserEmail)
57+
{
58+
userManager.Setup(m => m.GetEmailAsync(user)).ReturnsAsync(user.Email);
59+
}
4960
var roleClaims = new[] { "Admin", "Local" };
5061
if (supportRoles)
5162
{
@@ -90,6 +101,7 @@ public async Task EnsureClaimsIdentityHasExpectedClaims(bool supportRoles, bool
90101
Assert.Contains(
91102
claims, c => c.Type == manager.Options.ClaimsIdentity.UserNameClaimType && c.Value == user.UserName);
92103
Assert.Contains(claims, c => c.Type == manager.Options.ClaimsIdentity.UserIdClaimType && c.Value == user.Id);
104+
Assert.Equal(supportsUserEmail, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.EmailClaimType && c.Value == user.Email));
93105
Assert.Equal(supportRoles, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.RoleClaimType && c.Value == "Admin"));
94106
Assert.Equal(supportRoles, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.RoleClaimType && c.Value == "Local"));
95107
foreach (var cl in userClaims)

src/Middleware/ResponseCaching/src/ResponseCachingExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
namespace Microsoft.AspNetCore.Builder
88
{
9+
/// <summary>
10+
/// Extension methods for adding the <see cref="ResponseCachingMiddleware"/> to an application.
11+
/// </summary>
912
public static class ResponseCachingExtensions
1013
{
14+
/// <summary>
15+
/// Adds the <see cref="ResponseCachingMiddleware"/> for caching HTTP responses.
16+
/// </summary>
17+
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
1118
public static IApplicationBuilder UseResponseCaching(this IApplicationBuilder app)
1219
{
1320
if (app == null)

src/Middleware/ResponseCaching/src/ResponseCachingMiddleware.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
namespace Microsoft.AspNetCore.ResponseCaching
1616
{
17+
/// <summary>
18+
/// Enable HTTP response caching.
19+
/// </summary>
1720
public class ResponseCachingMiddleware
1821
{
1922
private static readonly TimeSpan DefaultExpirationTimeSpan = TimeSpan.FromSeconds(10);
@@ -29,6 +32,13 @@ public class ResponseCachingMiddleware
2932
private readonly IResponseCache _cache;
3033
private readonly IResponseCachingKeyProvider _keyProvider;
3134

35+
/// <summary>
36+
/// Creates a new <see cref="ResponseCachingMiddleware"/>.
37+
/// </summary>
38+
/// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
39+
/// <param name="options">The options for this middleware.</param>
40+
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used for logging.</param>
41+
/// <param name="poolProvider">The <see cref="ObjectPoolProvider"/> used for creating <see cref="ObjectPool"/> instances.</param>
3242
public ResponseCachingMiddleware(
3343
RequestDelegate next,
3444
IOptions<ResponseCachingOptions> options,
@@ -88,6 +98,11 @@ internal ResponseCachingMiddleware(
8898
_keyProvider = keyProvider;
8999
}
90100

101+
/// <summary>
102+
/// Invokes the logic of the middleware.
103+
/// </summary>
104+
/// <param name="httpContext">The <see cref="HttpContext"/>.</param>
105+
/// <returns>A <see cref="Task"/> that completes when the middleware has completed processing.</returns>
91106
public async Task Invoke(HttpContext httpContext)
92107
{
93108
var context = new ResponseCachingContext(httpContext, _logger);

src/SignalR/clients/java/signalr/signalr.client.java.Tests.javaproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />
33

44
<PropertyGroup>
5-
<IsPackable>true</IsPackable>
5+
6+
<!-- This package ID is only ever used along with eng/PatchConfig.props to determine when to patch the Java client. -->
7+
<PackageId>java:signalr</PackageId>
8+
9+
<!-- In servicing builds, this will be set to value if the Java client is not configured to be released in the currently building patch. -->
610
<IsPackable>true</IsPackable>
711

812
<IsTestProject>true</IsTestProject>

0 commit comments

Comments
 (0)