-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add ClaimData for AuthenticationStateData and fix overtrimming #56878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Security.Claims; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.Authorization; | ||
|
|
||
| /// <summary> | ||
| /// This is a serializable representation of a <see cref="Claim"/> object that only consists of the type and value. | ||
| /// </summary> | ||
| public readonly struct ClaimData | ||
| { | ||
| /// <summary> | ||
| /// Constructs a new instance of <see cref="ClaimData"/> from a type and value. | ||
| /// </summary> | ||
| /// <param name="type">The claim type.</param> | ||
| /// <param name="value">The claim value</param> | ||
| [JsonConstructor] | ||
| public ClaimData(string type, string value) | ||
| { | ||
| Type = type; | ||
| Value = value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Constructs a new instance of <see cref="ClaimData"/> from a <see cref="Claim"/> copying only the | ||
| /// <see cref="Claim.Type"/> and <see cref="Claim.Value"/> into their corresponding properties. | ||
| /// </summary> | ||
| /// <param name="claim">The <see cref="Claim"/> to copy from.</param> | ||
| public ClaimData(Claim claim) | ||
| : this(claim.Type, claim.Value) | ||
| { | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the claim type of the claim. <seealso cref="ClaimTypes"/>. | ||
| /// </summary> | ||
| public string Type { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the value of the claim. | ||
| /// </summary> | ||
| public string Value { get; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,15 @@ | ||
| #nullable enable | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.AuthenticationStateData() -> void | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.Claims.get -> System.Collections.Generic.IList<System.Collections.Generic.KeyValuePair<string!, string!>>! | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.Claims.get -> System.Collections.Generic.IList<Microsoft.AspNetCore.Components.Authorization.ClaimData>! | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.Claims.set -> void | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.NameClaimType.get -> string! | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.NameClaimType.set -> void | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.RoleClaimType.get -> string! | ||
| Microsoft.AspNetCore.Components.Authorization.AuthenticationStateData.RoleClaimType.set -> void | ||
| Microsoft.AspNetCore.Components.Authorization.ClaimData | ||
| Microsoft.AspNetCore.Components.Authorization.ClaimData.ClaimData() -> void | ||
| Microsoft.AspNetCore.Components.Authorization.ClaimData.ClaimData(string! type, string! value) -> void | ||
| Microsoft.AspNetCore.Components.Authorization.ClaimData.ClaimData(System.Security.Claims.Claim! claim) -> void | ||
| Microsoft.AspNetCore.Components.Authorization.ClaimData.Type.get -> string! | ||
| Microsoft.AspNetCore.Components.Authorization.ClaimData.Value.get -> string! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Reflection; | ||
| using Microsoft.AspNetCore.Hosting; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Logging.Testing; | ||
|
|
||
| namespace Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; | ||
|
|
||
| // REVIEW: Should this be merged into BasicTestAppServerSiteFixture? Is there any case where we wouldn't | ||
| // want to trim BasicTestAppServerSiteFixture tests when TestTrimmedOrMultithreadingApps is true? | ||
|
||
| public class TrimmingServerFixture<TStartup> : BasicTestAppServerSiteFixture<TStartup> where TStartup : class | ||
| { | ||
| public readonly bool TestTrimmedApps = typeof(ToggleExecutionModeServerFixture<>).Assembly | ||
| .GetCustomAttributes<AssemblyMetadataAttribute>() | ||
| .First(m => m.Key == "Microsoft.AspNetCore.E2ETesting.TestTrimmedOrMultithreadingApps") | ||
| .Value == "true"; | ||
|
|
||
| public TrimmingServerFixture() | ||
| { | ||
| if (TestTrimmedApps) | ||
| { | ||
| BuildWebHostMethod = BuildPublishedWebHost; | ||
| GetContentRootMethod = GetPublishedContentRoot; | ||
| } | ||
| } | ||
|
|
||
| private static IHost BuildPublishedWebHost(string[] args) => | ||
| Extensions.Hosting.Host.CreateDefaultBuilder(args) | ||
| .ConfigureLogging((ctx, lb) => | ||
| { | ||
| var sink = new TestSink(); | ||
| lb.AddProvider(new TestLoggerProvider(sink)); | ||
| lb.Services.AddSingleton(sink); | ||
| }) | ||
| .ConfigureWebHostDefaults(webHostBuilder => | ||
| { | ||
| webHostBuilder.UseStartup<TStartup>(); | ||
| // Avoid UseStaticAssets or we won't use the trimmed published output. | ||
| }) | ||
| .Build(); | ||
|
|
||
| private static string GetPublishedContentRoot(Assembly assembly) | ||
| { | ||
| var contentRoot = Path.Combine(AppContext.BaseDirectory, "trimmed-or-threading", assembly.GetName().Name); | ||
|
|
||
| if (!Directory.Exists(contentRoot)) | ||
| { | ||
| throw new DirectoryNotFoundException($"Test is configured to use trimmed outputs, but trimmed outputs were not found in {contentRoot}."); | ||
| } | ||
|
|
||
| return contentRoot; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.