22// The .NET Foundation licenses this file to you under the MIT license.
33
44using Microsoft . AspNetCore . Builder ;
5+ using Microsoft . AspNetCore . DataProtection . Infrastructure ;
56using Microsoft . AspNetCore . DataProtection . KeyManagement . Internal ;
67using Microsoft . AspNetCore . Hosting ;
78using Microsoft . AspNetCore . Hosting . Server ;
@@ -16,6 +17,28 @@ namespace Microsoft.AspNetCore.DataProtection.Test;
1617
1718public class HostingTests
1819{
20+ [ Fact ]
21+ public void DefaultApplicationDiscriminatorTrimsTrailingSlash ( )
22+ {
23+ var builder = new WebHostBuilder ( )
24+ . UseStartup < TestStartup > ( )
25+ . ConfigureServices ( s => s . AddDataProtection ( ) ) ;
26+
27+ using ( var host = builder . Build ( ) )
28+ {
29+ var contentRootPath = host . Services . GetRequiredService < IWebHostEnvironment > ( ) . ContentRootPath ;
30+ Assert . True ( contentRootPath . EndsWith ( Path . DirectorySeparatorChar ) , "expected contentRootPath to end with a slash" ) ;
31+
32+ var appDisc = host . Services . GetRequiredService < IApplicationDiscriminator > ( ) . Discriminator ;
33+ Assert . False ( appDisc . EndsWith ( Path . DirectorySeparatorChar ) , "expected appDiscriminator to have slash trimmed" ) ;
34+ Assert . False ( appDisc . EndsWith ( Path . AltDirectorySeparatorChar ) , "expected appDiscriminator to have slash trimmed" ) ;
35+
36+ var appId = host . Services . GetApplicationUniqueIdentifier ( ) ;
37+ Assert . False ( appId . EndsWith ( Path . DirectorySeparatorChar ) , "expected appId to have slash trimmed" ) ;
38+ Assert . False ( appId . EndsWith ( Path . AltDirectorySeparatorChar ) , "expected appId to have slash trimmed" ) ;
39+ }
40+ }
41+
1942 [ Fact ]
2043 public async Task WebhostLoadsKeyRingBeforeServerStarts ( )
2144 {
0 commit comments