Merge branch 'master' into halter73/mega-merge
This commit is contained in:
commit
1e03d57deb
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
|
@ -272,7 +273,7 @@ namespace Microsoft.AspNetCore.Hosting
|
|||
{
|
||||
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");
|
||||
}
|
||||
|
||||
[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]
|
||||
public void ActivityTraceParentAndTraceStateFromHeaders()
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Identity
|
|||
public partial class 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 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 { } }
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Microsoft.AspNetCore.Identity
|
|||
public partial class 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 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 { } }
|
||||
|
|
|
|||
|
|
@ -25,9 +25,14 @@ namespace Microsoft.AspNetCore.Identity
|
|||
/// </summary>
|
||||
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>
|
||||
/// Gets or sets the ClaimType used for the security stamp claim. Defaults to "AspNet.Identity.SecurityStamp".
|
||||
/// </summary>
|
||||
public string SecurityStampClaimType { get; set; } = "AspNet.Identity.SecurityStamp";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,14 @@ namespace Microsoft.AspNetCore.Identity
|
|||
Options.ClaimsIdentity.RoleClaimType);
|
||||
id.AddClaim(new Claim(Options.ClaimsIdentity.UserIdClaimType, userId));
|
||||
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)
|
||||
{
|
||||
id.AddClaim(new Claim(Options.ClaimsIdentity.SecurityStampClaimType,
|
||||
|
|
@ -154,4 +162,4 @@ namespace Microsoft.AspNetCore.Identity
|
|||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,22 +30,33 @@ namespace Microsoft.AspNetCore.Identity.Test
|
|||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(false, false, false)]
|
||||
[InlineData(false, true, false)]
|
||||
[InlineData(true, false, false)]
|
||||
[InlineData(true, true, false)]
|
||||
[InlineData(true, false, true)]
|
||||
[InlineData(true, true, true)]
|
||||
public async Task EnsureClaimsIdentityHasExpectedClaims(bool supportRoles, bool supportClaims, bool supportRoleClaims)
|
||||
[InlineData(true, false, false, false)]
|
||||
[InlineData(true, true, false, false)]
|
||||
[InlineData(true, false, true, false)]
|
||||
[InlineData(true, true, true, false)]
|
||||
[InlineData(false, false, false, true)]
|
||||
[InlineData(false, true, false, true)]
|
||||
[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
|
||||
var userManager = MockHelpers.MockUserManager<PocoUser>();
|
||||
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.SupportsUserRole).Returns(supportRoles);
|
||||
userManager.Setup(m => m.SupportsUserEmail).Returns(supportsUserEmail);
|
||||
userManager.Setup(m => m.GetUserIdAsync(user)).ReturnsAsync(user.Id);
|
||||
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" };
|
||||
if (supportRoles)
|
||||
{
|
||||
|
|
@ -90,6 +101,7 @@ namespace Microsoft.AspNetCore.Identity.Test
|
|||
Assert.Contains(
|
||||
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.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 == "Local"));
|
||||
foreach (var cl in userClaims)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,15 @@ using Microsoft.AspNetCore.ResponseCaching;
|
|||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for adding the <see cref="ResponseCachingMiddleware"/> to an application.
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
if (app == null)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ using Microsoft.Net.Http.Headers;
|
|||
|
||||
namespace Microsoft.AspNetCore.ResponseCaching
|
||||
{
|
||||
/// <summary>
|
||||
/// Enable HTTP response caching.
|
||||
/// </summary>
|
||||
public class ResponseCachingMiddleware
|
||||
{
|
||||
private static readonly TimeSpan DefaultExpirationTimeSpan = TimeSpan.FromSeconds(10);
|
||||
|
|
@ -29,6 +32,13 @@ namespace Microsoft.AspNetCore.ResponseCaching
|
|||
private readonly IResponseCache _cache;
|
||||
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(
|
||||
RequestDelegate next,
|
||||
IOptions<ResponseCachingOptions> options,
|
||||
|
|
@ -88,6 +98,11 @@ namespace Microsoft.AspNetCore.ResponseCaching
|
|||
_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)
|
||||
{
|
||||
var context = new ResponseCachingContext(httpContext, _logger);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@
|
|||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory)..\, Directory.Build.props))\Directory.Build.props" />
|
||||
|
||||
<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>
|
||||
|
||||
<IsTestProject>true</IsTestProject>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.XPath;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
|
|
@ -122,7 +123,16 @@ namespace Microsoft.Extensions.SecretManager.Tools.Internal
|
|||
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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.Extensions.Configuration.UserSecrets.Tests;
|
||||
using Microsoft.Extensions.SecretManager.Tools.Internal;
|
||||
|
|
@ -90,6 +91,18 @@ namespace Microsoft.Extensions.SecretManager.Tools.Tests
|
|||
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]
|
||||
public void OverridesIdForProjectWithSecretId()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue