Move ProtectedBrowserStorage to the shared fx (#25557)
* Move ProtectedBrowserStorage to the shared fx * Fixups * Fixup
This commit is contained in:
parent
9f5276d17a
commit
646925127b
|
|
@ -1487,12 +1487,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Diagno
|
|||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.JSInterop.Tests", "src\JSInterop\Microsoft.JSInterop\test\Microsoft.JSInterop.Tests.csproj", "{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ProtectedBrowserStorage", "ProtectedBrowserStorage", "{1B06FD32-3A1D-46A4-B2AF-99159FAD8127}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.ProtectedBrowserStorage", "src\Components\ProtectedBrowserStorage\src\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj", "{9059AC97-7547-4CC1-A076-680CBCCC1F33}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests", "src\Components\ProtectedBrowserStorage\test\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests.csproj", "{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Configuration.KeyPerFile", "src\Configuration.KeyPerFile\src\Microsoft.Extensions.Configuration.KeyPerFile.csproj", "{498A4F54-F11A-46C5-A58D-09DE56C6A034}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configuration.KeyPerFile", "Configuration.KeyPerFile", "{AEB1933E-9369-4305-B20E-F186F888158F}"
|
||||
|
|
@ -7127,30 +7121,6 @@ Global
|
|||
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}.Release|x64.Build.0 = Release|Any CPU
|
||||
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E}.Release|x86.Build.0 = Release|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x64.Build.0 = Release|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33}.Release|x86.Build.0 = Release|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x64.Build.0 = Release|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5}.Release|x86.Build.0 = Release|Any CPU
|
||||
{498A4F54-F11A-46C5-A58D-09DE56C6A034}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{498A4F54-F11A-46C5-A58D-09DE56C6A034}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{498A4F54-F11A-46C5-A58D-09DE56C6A034}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
|
|
@ -8053,9 +8023,6 @@ Global
|
|||
{55CACC1F-FE96-47C8-8073-91F4CAA55C75} = {2A91479A-4ABE-4BB7-9A5E-CA3B9CCFC69E}
|
||||
{7509AA1E-3093-4BEE-984F-E11579E98A11} = {7CB09412-C9B0-47E8-A8C3-311AA4CFDE04}
|
||||
{DAAB6B35-CBD2-4573-B633-CDD42F583A0E} = {16898702-3E33-41C1-B8D8-4CE3F1D46BD9}
|
||||
{1B06FD32-3A1D-46A4-B2AF-99159FAD8127} = {60D51C98-2CC0-40DF-B338-44154EFEE2FF}
|
||||
{9059AC97-7547-4CC1-A076-680CBCCC1F33} = {1B06FD32-3A1D-46A4-B2AF-99159FAD8127}
|
||||
{943FD3EC-D330-4277-B3F3-3DFABB57D3B5} = {1B06FD32-3A1D-46A4-B2AF-99159FAD8127}
|
||||
{498A4F54-F11A-46C5-A58D-09DE56C6A034} = {AEB1933E-9369-4305-B20E-F186F888158F}
|
||||
{AEB1933E-9369-4305-B20E-F186F888158F} = {017429CC-C5FB-48B4-9C46-034E29EE2F06}
|
||||
{B9D37BCF-80D1-489D-9FC6-55191FDBB033} = {AEB1933E-9369-4305-B20E-F186F888158F}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,6 @@
|
|||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components" ProjectPath="$(RepoRoot)src\Components\Components\src\Microsoft.AspNetCore.Components.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.Forms" ProjectPath="$(RepoRoot)src\Components\Forms\src\Microsoft.AspNetCore.Components.Forms.csproj" />
|
||||
<ProjectReferenceProvider Include="Ignitor" ProjectPath="$(RepoRoot)src\Components\Ignitor\src\Ignitor.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.ProtectedBrowserStorage" ProjectPath="$(RepoRoot)src\Components\ProtectedBrowserStorage\src\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.Server" ProjectPath="$(RepoRoot)src\Components\Server\src\Microsoft.AspNetCore.Components.Server.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Components.Web.Extensions" ProjectPath="$(RepoRoot)src\Components\Web.Extensions\src\Microsoft.AspNetCore.Components.Web.Extensions.csproj" />
|
||||
<ProjectReferenceProvider Include="Microsoft.Authentication.WebAssembly.Msal" ProjectPath="$(RepoRoot)src\Components\WebAssembly\Authentication.Msal\src\Microsoft.Authentication.WebAssembly.Msal.csproj" />
|
||||
|
|
|
|||
|
|
@ -111,9 +111,7 @@
|
|||
"src\\Components\\WebAssembly\\Sdk\\src\\Microsoft.NET.Sdk.BlazorWebAssembly.csproj",
|
||||
"src\\Components\\WebAssembly\\Sdk\\test\\Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj",
|
||||
"src\\Components\\WebAssembly\\Sdk\\integrationtests\\Microsoft.NET.Sdk.BlazorWebAssembly.IntegrationTests.csproj",
|
||||
"src\\JSInterop\\Microsoft.JSInterop\\src\\Microsoft.JSInterop.csproj",
|
||||
"src\\Components\\ProtectedBrowserStorage\\src\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj",
|
||||
"src\\Components\\ProtectedBrowserStorage\\test\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests.csproj"
|
||||
"src\\JSInterop\\Microsoft.JSInterop\\src\\Microsoft.JSInterop.csproj"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,9 +45,7 @@
|
|||
"src\\Components\\test\\testassets\\BasicTestApp\\BasicTestApp.csproj",
|
||||
"src\\Components\\test\\testassets\\ComponentsApp.Server\\ComponentsApp.Server.csproj",
|
||||
"src\\Components\\test\\testassets\\TestContentPackage\\TestContentPackage.csproj",
|
||||
"src\\Components\\test\\testassets\\TestServer\\Components.TestServer.csproj",
|
||||
"src\\Components\\ProtectedBrowserStorage\\src\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.csproj",
|
||||
"src\\Components\\ProtectedBrowserStorage\\test\\Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests.csproj"
|
||||
"src\\Components\\test\\testassets\\TestServer\\Components.TestServer.csproj"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
|
||||
<Description>Provides functionality for storing protected data using the browser's localStorage and sessionStorage APIs.</Description>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.Components" />
|
||||
<Reference Include="Microsoft.AspNetCore.DataProtection" />
|
||||
<Reference Include="Microsoft.JSInterop" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\Shared\src\JsonSerializerOptionsProvider.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Versioning;
|
||||
|
||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Components.ProtectedBrowserStorage.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNetCore.Components.ProtectedBrowserStorage;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for registering Protected Browser Storage services.
|
||||
/// </summary>
|
||||
public static class ProtectedBrowserStorageServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds services for protected browser storage to the specified <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
|
||||
public static void AddProtectedBrowserStorage(this IServiceCollection services)
|
||||
{
|
||||
services.AddDataProtection();
|
||||
services.AddScoped<ProtectedLocalStorage>();
|
||||
services.AddScoped<ProtectedSessionStorage>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.Components" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.ProtectedBrowserStorage" />
|
||||
<Reference Include="Microsoft.AspNetCore.WebUtilities" />
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="$(ComponentsSharedSourceRoot)test\**\*.cs" LinkBase="Helpers" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Components.Routing;
|
|||
using Microsoft.AspNetCore.Components.Server;
|
||||
using Microsoft.AspNetCore.Components.Server.BlazorPack;
|
||||
using Microsoft.AspNetCore.Components.Server.Circuits;
|
||||
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;
|
||||
using Microsoft.AspNetCore.SignalR.Protocol;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
|
@ -33,6 +34,9 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
|
||||
services.AddDataProtection();
|
||||
|
||||
services.TryAddScoped<ProtectedLocalStorage>();
|
||||
services.TryAddScoped<ProtectedSessionStorage>();
|
||||
|
||||
// This call INTENTIONALLY uses the AddHubOptions on the SignalR builder, because it will merge
|
||||
// the global HubOptions before running the configure callback. We want to ensure that happens
|
||||
// once. Our AddHubOptions method doesn't do this.
|
||||
|
|
|
|||
|
|
@ -4,19 +4,17 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
||||
namespace Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Provides mechanisms for storing and retrieving data in the browser storage.
|
||||
/// </summary>
|
||||
[UnsupportedOSPlatform("browser")]
|
||||
public abstract class ProtectedBrowserStorage
|
||||
{
|
||||
private readonly string _storeName;
|
||||
|
|
@ -31,7 +29,7 @@ namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
|||
/// <param name="storeName">The name of the store in which the data should be stored.</param>
|
||||
/// <param name="jsRuntime">The <see cref="IJSRuntime"/>.</param>
|
||||
/// <param name="dataProtectionProvider">The <see cref="IDataProtectionProvider"/>.</param>
|
||||
protected ProtectedBrowserStorage(string storeName, IJSRuntime jsRuntime, IDataProtectionProvider dataProtectionProvider)
|
||||
private protected ProtectedBrowserStorage(string storeName, IJSRuntime jsRuntime, IDataProtectionProvider dataProtectionProvider)
|
||||
{
|
||||
// Performing data protection on the client would give users a false sense of security, so we'll prevent this.
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
|
||||
|
|
@ -155,8 +153,8 @@ namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
|||
private ValueTask SetProtectedJsonAsync(string key, string protectedJson)
|
||||
=> _jsRuntime.InvokeVoidAsync($"{_storeName}.setItem", key, protectedJson);
|
||||
|
||||
private ValueTask<string> GetProtectedJsonAsync(string key)
|
||||
=> _jsRuntime.InvokeAsync<string>($"{_storeName}.getItem", key);
|
||||
private ValueTask<string?> GetProtectedJsonAsync(string key)
|
||||
=> _jsRuntime.InvokeAsync<string?>($"{_storeName}.getItem", key);
|
||||
|
||||
// IDataProtect isn't disposable, so we're fine holding these indefinitely.
|
||||
// Only a bounded number of them will be created, as the 'key' values should
|
||||
|
|
@ -1,14 +1,12 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
||||
namespace Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains the result of a protected browser storage operation.
|
||||
/// </summary>
|
||||
public readonly struct ProtectedBrowserStorageResult<T>
|
||||
public readonly struct ProtectedBrowserStorageResult<TValue>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether the operation succeeded.
|
||||
|
|
@ -18,11 +16,9 @@ namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
|||
/// <summary>
|
||||
/// Gets the result value of the operation.
|
||||
/// </summary>
|
||||
[MaybeNull]
|
||||
[AllowNull]
|
||||
public T Value { get; }
|
||||
public TValue? Value { get; }
|
||||
|
||||
internal ProtectedBrowserStorageResult(bool success, [AllowNull] T value)
|
||||
internal ProtectedBrowserStorageResult(bool success, TValue? value)
|
||||
{
|
||||
Success = success;
|
||||
Value = value;
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Runtime.Versioning;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
||||
namespace Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides mechanisms for storing and retrieving data in the browser's
|
||||
|
|
@ -16,8 +15,7 @@ namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
|||
///
|
||||
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
|
||||
/// </summary>
|
||||
[UnsupportedOSPlatform("browser")]
|
||||
public class ProtectedLocalStorage : ProtectedBrowserStorage
|
||||
public sealed class ProtectedLocalStorage : ProtectedBrowserStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs an instance of <see cref="ProtectedLocalStorage"/>.
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Runtime.Versioning;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
||||
namespace Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides mechanisms for storing and retrieving data in the browser's
|
||||
|
|
@ -16,8 +15,7 @@ namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
|||
///
|
||||
/// See: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
|
||||
/// </summary>
|
||||
[UnsupportedOSPlatform("browser")]
|
||||
public class ProtectedSessionStorage : ProtectedBrowserStorage
|
||||
public sealed class ProtectedSessionStorage : ProtectedBrowserStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs an instance of <see cref="ProtectedSessionStorage"/>.
|
||||
|
|
@ -14,7 +14,7 @@ using Microsoft.AspNetCore.WebUtilities;
|
|||
using Microsoft.JSInterop;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
||||
namespace Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
{
|
||||
public class ProtectedBrowserStorageTest
|
||||
{
|
||||
|
|
@ -8,7 +8,10 @@ namespace Microsoft.AspNetCore.Components.E2ETest
|
|||
{
|
||||
public static IWebElement MountTestComponent<TComponent>(this IWebDriver browser) where TComponent : IComponent
|
||||
{
|
||||
var componentTypeName = typeof(TComponent).FullName;
|
||||
var componentType = typeof(TComponent);
|
||||
var componentTypeName = componentType.Assembly == typeof(BasicTestApp.Program).Assembly ?
|
||||
componentType.FullName :
|
||||
componentType.AssemblyQualifiedName;
|
||||
var testSelector = browser.WaitUntilTestSelectorReady();
|
||||
testSelector.SelectByValue("none");
|
||||
testSelector.SelectByValue(componentTypeName);
|
||||
|
|
|
|||
|
|
@ -5,25 +5,24 @@ using System;
|
|||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using BasicTestApp;
|
||||
using Components.TestServer;
|
||||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
|
||||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
|
||||
using Microsoft.AspNetCore.E2ETesting;
|
||||
using OpenQA.Selenium;
|
||||
using OpenQA.Selenium.Interactions;
|
||||
using TestServer;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
|
||||
{
|
||||
public class ProtectedBrowserStorageUsageTest : ServerTestBase<BasicTestAppServerSiteFixture<ServerStartup>>
|
||||
public class ProtectedBrowserStorageUsageTest : ServerTestBase<ToggleExecutionModeServerFixture<BasicTestApp.Program>>
|
||||
{
|
||||
public ProtectedBrowserStorageUsageTest(
|
||||
BrowserFixture browserFixture,
|
||||
BasicTestAppServerSiteFixture<ServerStartup> serverFixture,
|
||||
ToggleExecutionModeServerFixture<BasicTestApp.Program> serverFixture,
|
||||
ITestOutputHelper output)
|
||||
: base(browserFixture, serverFixture, output)
|
||||
: base(browserFixture, serverFixture.WithServerExecution(), output)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using BasicTestApp;
|
||||
using Components.TestServer;
|
||||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure;
|
||||
using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures;
|
||||
using Microsoft.AspNetCore.E2ETesting;
|
||||
|
|
@ -10,7 +11,7 @@ using OpenQA.Selenium;
|
|||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNetCore.Components.E2ETest.Tests
|
||||
namespace Microsoft.AspNetCore.Components.E2ETest.ServerExecutionTests
|
||||
{
|
||||
public class ProtectedBrowserStorageInjectionTest : ServerTestBase<ToggleExecutionModeServerFixture<Program>>
|
||||
{
|
||||
|
|
@ -18,7 +19,7 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
|
|||
BrowserFixture browserFixture,
|
||||
ToggleExecutionModeServerFixture<Program> serverFixture,
|
||||
ITestOutputHelper output)
|
||||
: base(browserFixture, serverFixture, output)
|
||||
: base(browserFixture, serverFixture.WithServerExecution(), output)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@
|
|||
<Reference Include="System.Net.Http.Json" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.Authorization" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.ProtectedBrowserStorage" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.Web.Extensions" />
|
||||
<Reference Include="Microsoft.Extensions.Logging.Configuration" />
|
||||
<Reference Include="Newtonsoft.Json" />
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@
|
|||
<option value="BasicTestApp.NavigationFailureComponent">Navigation failure</option>
|
||||
<option value="BasicTestApp.ParentChildComponent">Parent component with child</option>
|
||||
<option value="BasicTestApp.PropertiesChangedHandlerParent">Parent component that changes parameters on child</option>
|
||||
<option value="BasicTestApp.ProtectedBrowserStorageUsageComponent">Protected browser storage usage</option>
|
||||
<option value="BasicTestApp.ProtectedBrowserStorageInjectionComponent">Protected browser storage injection</option>
|
||||
<option value="@GetTestServerProjectComponent("Components.TestServer.ProtectedBrowserStorageUsageComponent")">Protected browser storage usage</option>
|
||||
<option value="@GetTestServerProjectComponent("Components.TestServer.ProtectedBrowserStorageInjectionComponent")">Protected browser storage injection</option>
|
||||
<option value="BasicTestApp.RazorTemplates">Razor Templates</option>
|
||||
<option value="BasicTestApp.Reconnection.ReconnectionComponent">Reconnection server-side blazor</option>
|
||||
<option value="BasicTestApp.RedTextComponent">Red text</option>
|
||||
|
|
@ -108,7 +108,7 @@
|
|||
string SelectedComponentTypeName { get; set; } = "none";
|
||||
|
||||
Type SelectedComponentType
|
||||
=> SelectedComponentTypeName == "none" ? null : Type.GetType(SelectedComponentTypeName);
|
||||
=> SelectedComponentTypeName == "none" ? null : Type.GetType(SelectedComponentTypeName, throwOnError: true);
|
||||
|
||||
void RenderSelectedComponent(RenderTreeBuilder builder)
|
||||
{
|
||||
|
|
@ -118,4 +118,13 @@
|
|||
builder.CloseComponent();
|
||||
}
|
||||
}
|
||||
|
||||
static string GetTestServerProjectComponent(string componentName)
|
||||
{
|
||||
var serverAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(f => f.GetName().Name == "Components.TestServer");
|
||||
// If the server project isn't loaded return the component name as-is. Calculating the SelectedComponentType property will result in an error.
|
||||
return serverAssembly is null ?
|
||||
componentName :
|
||||
serverAssembly.GetType(componentName, throwOnError: true).AssemblyQualifiedName;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ using Microsoft.Extensions.Configuration;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Configuration;
|
||||
using Microsoft.JSInterop;
|
||||
using Microsoft.AspNetCore.Components.ProtectedBrowserStorage;
|
||||
|
||||
namespace BasicTestApp
|
||||
{
|
||||
|
|
@ -40,11 +39,6 @@ namespace BasicTestApp
|
|||
policy.RequireAssertion(ctx => ctx.User.Identity.Name?.StartsWith("B") ?? false));
|
||||
});
|
||||
|
||||
builder.Services.AddDataProtection();
|
||||
|
||||
builder.Services.AddTransient<ProtectedLocalStorage>();
|
||||
builder.Services.AddTransient<ProtectedSessionStorage>();
|
||||
|
||||
builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
|
||||
|
||||
builder.Logging.Services.AddSingleton<ILoggerProvider, PrependMessageLoggerProvider>(s =>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
<title>Basic test app</title>
|
||||
<base href="/subdir/" />
|
||||
<link href="style.css" rel="stylesheet" />
|
||||
<link rel="icon" href="data:,">
|
||||
|
||||
<!-- Used by ExternalContentPackage -->
|
||||
<link href="_content/TestContentPackage/styles.css" rel="stylesheet" />
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore" />
|
||||
<Reference Include="Microsoft.AspNetCore.Authentication.Cookies" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.Web.Extensions" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
|
||||
<Reference Include="Microsoft.AspNetCore.Components.Server" />
|
||||
<Reference Include="Microsoft.AspNetCore.Cors" />
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
<title>Basic test app</title>
|
||||
<base href="~/" />
|
||||
<link href="style.css" rel="stylesheet" />
|
||||
<link rel="icon" href="data:,">
|
||||
|
||||
<!-- Used by ExternalContentPackage -->
|
||||
<link href="_content/TestContentPackage/styles.css" rel="stylesheet" />
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace TestServer
|
|||
services.AddMvc();
|
||||
services.AddServerSideBlazor();
|
||||
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie();
|
||||
services.AddSingleton<LazyAssemblyLoader>();
|
||||
services.AddScoped<LazyAssemblyLoader>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
@using Microsoft.Extensions.DependencyInjection
|
||||
@using Microsoft.AspNetCore.Components.Web.Extensions
|
||||
@using Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
@inject IServiceProvider ServiceProvider
|
||||
|
||||
<button id="inject-local" @onclick="Inject<ProtectedLocalStorage>">Inject @(nameof(ProtectedLocalStorage))</button>
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
@using Microsoft.AspNetCore.Components.Web.Extensions
|
||||
@using Microsoft.AspNetCore.Components.ProtectedBrowserStorage
|
||||
@using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage
|
||||
@inject ProtectedLocalStorage ProtectedLocalStore
|
||||
@inject ProtectedSessionStorage ProtectedSessionStore
|
||||
|
||||
|
|
@ -19,8 +19,7 @@ namespace TestServer
|
|||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc();
|
||||
services.AddServerSideBlazor();
|
||||
services.AddProtectedBrowserStorage();
|
||||
services.AddServerSideBlazor(options => options.DetailedErrors = true);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
Loading…
Reference in New Issue