Merge branch 'master' into halter73/mega-merge
This commit is contained in:
commit
1e03d57deb
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Web;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
|
@ -272,7 +273,7 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
if (NameValueHeaderValue.TryParse(item, out var baggageItem))
|
if (NameValueHeaderValue.TryParse(item, out var baggageItem))
|
||||||
{
|
{
|
||||||
activity.AddBaggage(baggageItem.Name.ToString(), baggageItem.Value.ToString());
|
activity.AddBaggage(baggageItem.Name.ToString(), HttpUtility.UrlDecode(baggageItem.Value.ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -345,6 +345,35 @@ namespace Microsoft.AspNetCore.Hosting.Tests
|
||||||
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key2" && pair.Value == "value2");
|
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key2" && pair.Value == "value2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ActivityBaggageValuesAreUrlDecodedFromHeaders()
|
||||||
|
{
|
||||||
|
var diagnosticListener = new DiagnosticListener("DummySource");
|
||||||
|
var hostingApplication = CreateApplication(out var features, diagnosticListener: diagnosticListener);
|
||||||
|
|
||||||
|
diagnosticListener.Subscribe(new CallbackDiagnosticListener(pair => { }),
|
||||||
|
s =>
|
||||||
|
{
|
||||||
|
if (s.StartsWith("Microsoft.AspNetCore.Hosting.HttpRequestIn"))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
features.Set<IHttpRequestFeature>(new HttpRequestFeature()
|
||||||
|
{
|
||||||
|
Headers = new HeaderDictionary()
|
||||||
|
{
|
||||||
|
{"Request-Id", "ParentId1"},
|
||||||
|
{"Correlation-Context", "Key1=value1%2F1"}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
hostingApplication.CreateContext(features);
|
||||||
|
Assert.Equal("Microsoft.AspNetCore.Hosting.HttpRequestIn", Activity.Current.OperationName);
|
||||||
|
Assert.Contains(Activity.Current.Baggage, pair => pair.Key == "Key1" && pair.Value == "value1/1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ActivityTraceParentAndTraceStateFromHeaders()
|
public void ActivityTraceParentAndTraceStateFromHeaders()
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Identity
|
||||||
public partial class ClaimsIdentityOptions
|
public partial class ClaimsIdentityOptions
|
||||||
{
|
{
|
||||||
public ClaimsIdentityOptions() { }
|
public ClaimsIdentityOptions() { }
|
||||||
|
public string EmailClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
public string RoleClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
public string RoleClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
public string SecurityStampClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
public string SecurityStampClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
public string UserIdClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
public string UserIdClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Identity
|
||||||
public partial class ClaimsIdentityOptions
|
public partial class ClaimsIdentityOptions
|
||||||
{
|
{
|
||||||
public ClaimsIdentityOptions() { }
|
public ClaimsIdentityOptions() { }
|
||||||
|
public string EmailClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
public string RoleClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
public string RoleClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
public string SecurityStampClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
public string SecurityStampClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
public string UserIdClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
public string UserIdClaimType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,11 @@ namespace Microsoft.AspNetCore.Identity
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string UserIdClaimType { get; set; } = ClaimTypes.NameIdentifier;
|
public string UserIdClaimType { get; set; } = ClaimTypes.NameIdentifier;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the ClaimType used for the user email claim. Defaults to <see cref="ClaimTypes.Email"/>.
|
||||||
|
/// </summary>
|
||||||
|
public string EmailClaimType { get; set; } = ClaimTypes.Email;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the ClaimType used for the security stamp claim. Defaults to "AspNet.Identity.SecurityStamp".
|
/// Gets or sets the ClaimType used for the security stamp claim. Defaults to "AspNet.Identity.SecurityStamp".
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,14 @@ namespace Microsoft.AspNetCore.Identity
|
||||||
Options.ClaimsIdentity.RoleClaimType);
|
Options.ClaimsIdentity.RoleClaimType);
|
||||||
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
|
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
|
||||||
id.AddClaim(new Claim(Options.ClaimsIdentity.UserNameClaimType, userName));
|
id.AddClaim(new Claim(Options.ClaimsIdentity.UserNameClaimType, userName));
|
||||||
|
if (UserManager.SupportsUserEmail)
|
||||||
|
{
|
||||||
|
var email = await UserManager.GetEmailAsync(user);
|
||||||
|
if (!string.IsNullOrEmpty(email))
|
||||||
|
{
|
||||||
|
id.AddClaim(new Claim(Options.ClaimsIdentity.EmailClaimType, email));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (UserManager.SupportsUserSecurityStamp)
|
if (UserManager.SupportsUserSecurityStamp)
|
||||||
{
|
{
|
||||||
id.AddClaim(new Claim(Options.ClaimsIdentity.SecurityStampClaimType,
|
id.AddClaim(new Claim(Options.ClaimsIdentity.SecurityStampClaimType,
|
||||||
|
|
|
||||||
|
|
@ -30,22 +30,33 @@ namespace Microsoft.AspNetCore.Identity.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(false, false, false)]
|
[InlineData(true, false, false, false)]
|
||||||
[InlineData(false, true, false)]
|
[InlineData(true, true, false, false)]
|
||||||
[InlineData(true, false, false)]
|
[InlineData(true, false, true, false)]
|
||||||
[InlineData(true, true, false)]
|
[InlineData(true, true, true, false)]
|
||||||
[InlineData(true, false, true)]
|
[InlineData(false, false, false, true)]
|
||||||
[InlineData(true, true, true)]
|
[InlineData(false, true, false, true)]
|
||||||
public async Task EnsureClaimsIdentityHasExpectedClaims(bool supportRoles, bool supportClaims, bool supportRoleClaims)
|
[InlineData(false, false, false, false)]
|
||||||
|
[InlineData(false, true, false, false)]
|
||||||
|
[InlineData(true, false, false, true)]
|
||||||
|
[InlineData(true, true, false, true)]
|
||||||
|
[InlineData(true, false, true, true)]
|
||||||
|
[InlineData(true, true, true, true)]
|
||||||
|
public async Task EnsureClaimsIdentityHasExpectedClaims(bool supportRoles, bool supportClaims, bool supportRoleClaims, bool supportsUserEmail)
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
var userManager = MockHelpers.MockUserManager<PocoUser>();
|
var userManager = MockHelpers.MockUserManager<PocoUser>();
|
||||||
var roleManager = MockHelpers.MockRoleManager<PocoRole>();
|
var roleManager = MockHelpers.MockRoleManager<PocoRole>();
|
||||||
var user = new PocoUser { UserName = "Foo" };
|
var user = new PocoUser { UserName = "Foo", Email = "foo@bar.com" };
|
||||||
userManager.Setup(m => m.SupportsUserClaim).Returns(supportClaims);
|
userManager.Setup(m => m.SupportsUserClaim).Returns(supportClaims);
|
||||||
userManager.Setup(m => m.SupportsUserRole).Returns(supportRoles);
|
userManager.Setup(m => m.SupportsUserRole).Returns(supportRoles);
|
||||||
|
userManager.Setup(m => m.SupportsUserEmail).Returns(supportsUserEmail);
|
||||||
userManager.Setup(m => m.GetUserIdAsync(user)).ReturnsAsync(user.Id);
|
userManager.Setup(m => m.GetUserIdAsync(user)).ReturnsAsync(user.Id);
|
||||||
userManager.Setup(m => m.GetUserNameAsync(user)).ReturnsAsync(user.UserName);
|
userManager.Setup(m => m.GetUserNameAsync(user)).ReturnsAsync(user.UserName);
|
||||||
|
if (supportsUserEmail)
|
||||||
|
{
|
||||||
|
userManager.Setup(m => m.GetEmailAsync(user)).ReturnsAsync(user.Email);
|
||||||
|
}
|
||||||
var roleClaims = new[] { "Admin", "Local" };
|
var roleClaims = new[] { "Admin", "Local" };
|
||||||
if (supportRoles)
|
if (supportRoles)
|
||||||
{
|
{
|
||||||
|
|
@ -90,6 +101,7 @@ namespace Microsoft.AspNetCore.Identity.Test
|
||||||
Assert.Contains(
|
Assert.Contains(
|
||||||
claims, c => c.Type == manager.Options.ClaimsIdentity.UserNameClaimType && c.Value == user.UserName);
|
claims, c => c.Type == manager.Options.ClaimsIdentity.UserNameClaimType && c.Value == user.UserName);
|
||||||
Assert.Contains(claims, c => c.Type == manager.Options.ClaimsIdentity.UserIdClaimType && c.Value == user.Id);
|
Assert.Contains(claims, c => c.Type == manager.Options.ClaimsIdentity.UserIdClaimType && c.Value == user.Id);
|
||||||
|
Assert.Equal(supportsUserEmail, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.EmailClaimType && c.Value == user.Email));
|
||||||
Assert.Equal(supportRoles, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.RoleClaimType && c.Value == "Admin"));
|
Assert.Equal(supportRoles, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.RoleClaimType && c.Value == "Admin"));
|
||||||
Assert.Equal(supportRoles, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.RoleClaimType && c.Value == "Local"));
|
Assert.Equal(supportRoles, claims.Any(c => c.Type == manager.Options.ClaimsIdentity.RoleClaimType && c.Value == "Local"));
|
||||||
foreach (var cl in userClaims)
|
foreach (var cl in userClaims)
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,15 @@ using Microsoft.AspNetCore.ResponseCaching;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Builder
|
namespace Microsoft.AspNetCore.Builder
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for adding the <see cref="ResponseCachingMiddleware"/> to an application.
|
||||||
|
/// </summary>
|
||||||
public static class ResponseCachingExtensions
|
public static class ResponseCachingExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the <see cref="ResponseCachingMiddleware"/> for caching HTTP responses.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
|
||||||
public static IApplicationBuilder UseResponseCaching(this IApplicationBuilder app)
|
public static IApplicationBuilder UseResponseCaching(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
if (app == null)
|
if (app == null)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.ResponseCaching
|
namespace Microsoft.AspNetCore.ResponseCaching
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Enable HTTP response caching.
|
||||||
|
/// </summary>
|
||||||
public class ResponseCachingMiddleware
|
public class ResponseCachingMiddleware
|
||||||
{
|
{
|
||||||
private static readonly TimeSpan DefaultExpirationTimeSpan = TimeSpan.FromSeconds(10);
|
private static readonly TimeSpan DefaultExpirationTimeSpan = TimeSpan.FromSeconds(10);
|
||||||
|
|
@ -29,6 +32,13 @@ namespace Microsoft.AspNetCore.ResponseCaching
|
||||||
private readonly IResponseCache _cache;
|
private readonly IResponseCache _cache;
|
||||||
private readonly IResponseCachingKeyProvider _keyProvider;
|
private readonly IResponseCachingKeyProvider _keyProvider;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="ResponseCachingMiddleware"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
|
||||||
|
/// <param name="options">The options for this middleware.</param>
|
||||||
|
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used for logging.</param>
|
||||||
|
/// <param name="poolProvider">The <see cref="ObjectPoolProvider"/> used for creating <see cref="ObjectPool"/> instances.</param>
|
||||||
public ResponseCachingMiddleware(
|
public ResponseCachingMiddleware(
|
||||||
RequestDelegate next,
|
RequestDelegate next,
|
||||||
IOptions<ResponseCachingOptions> options,
|
IOptions<ResponseCachingOptions> options,
|
||||||
|
|
@ -88,6 +98,11 @@ namespace Microsoft.AspNetCore.ResponseCaching
|
||||||
_keyProvider = keyProvider;
|
_keyProvider = keyProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the logic of the middleware.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="httpContext">The <see cref="HttpContext"/>.</param>
|
||||||
|
/// <returns>A <see cref="Task"/> that completes when the middleware has completed processing.</returns>
|
||||||
public async Task Invoke(HttpContext httpContext)
|
public async Task Invoke(HttpContext httpContext)
|
||||||
{
|
{
|
||||||
var context = new ResponseCachingContext(httpContext, _logger);
|
var context = new ResponseCachingContext(httpContext, _logger);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />
|
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<IsPackable>true</IsPackable>
|
|
||||||
|
<!-- This package ID is only ever used along with eng/PatchConfig.props to determine when to patch the Java client. -->
|
||||||
|
<PackageId>java:signalr</PackageId>
|
||||||
|
|
||||||
|
<!-- In servicing builds, this will be set to value if the Java client is not configured to be released in the currently building patch. -->
|
||||||
<IsPackable>true</IsPackable>
|
<IsPackable>true</IsPackable>
|
||||||
|
|
||||||
<IsTestProject>true</IsTestProject>
|
<IsTestProject>true</IsTestProject>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using System.Xml.XPath;
|
using System.Xml.XPath;
|
||||||
using Microsoft.Extensions.CommandLineUtils;
|
using Microsoft.Extensions.CommandLineUtils;
|
||||||
|
|
@ -122,7 +123,16 @@ namespace Microsoft.Extensions.SecretManager.Tools.Internal
|
||||||
propertyGroup.Add(new XElement("UserSecretsId", newSecretsId));
|
propertyGroup.Add(new XElement("UserSecretsId", newSecretsId));
|
||||||
}
|
}
|
||||||
|
|
||||||
projectDocument.Save(projectPath);
|
var settings = new XmlWriterSettings
|
||||||
|
{
|
||||||
|
Indent = true,
|
||||||
|
OmitXmlDeclaration = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
using (var xw = XmlWriter.Create(projectPath, settings))
|
||||||
|
{
|
||||||
|
projectDocument.Save(xw);
|
||||||
|
}
|
||||||
|
|
||||||
context.Reporter.Output(Resources.FormatMessage_SetUserSecretsIdForProject(newSecretsId, projectPath));
|
context.Reporter.Output(Resources.FormatMessage_SetUserSecretsIdForProject(newSecretsId, projectPath));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Xml.Linq;
|
||||||
using Microsoft.AspNetCore.Testing;
|
using Microsoft.AspNetCore.Testing;
|
||||||
using Microsoft.Extensions.Configuration.UserSecrets.Tests;
|
using Microsoft.Extensions.Configuration.UserSecrets.Tests;
|
||||||
using Microsoft.Extensions.SecretManager.Tools.Internal;
|
using Microsoft.Extensions.SecretManager.Tools.Internal;
|
||||||
|
|
@ -90,6 +91,18 @@ namespace Microsoft.Extensions.SecretManager.Tools.Tests
|
||||||
Assert.Equal(SecretId, idResolver.Resolve(null, null));
|
Assert.Equal(SecretId, idResolver.Resolve(null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DoesNotAddXmlDeclarationToProject()
|
||||||
|
{
|
||||||
|
var projectDir = _fixture.CreateProject(null);
|
||||||
|
var projectFile = Path.Combine(projectDir, "TestProject.csproj");
|
||||||
|
|
||||||
|
new InitCommand(null, null).Execute(MakeCommandContext(), projectDir);
|
||||||
|
|
||||||
|
var projectDocument = XDocument.Load(projectFile);
|
||||||
|
Assert.Null(projectDocument.Declaration);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void OverridesIdForProjectWithSecretId()
|
public void OverridesIdForProjectWithSecretId()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue