using System.Security.Claims; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using PlotLine.Services; internal static class HelpVisibilityTests { public static void Run() { void Check(bool value,string message){if(!value)throw new Exception(message);} var environment=NativeWorkflowTests.Proxy((name,args)=>name=="get_ContentRootPath"?Path.GetFullPath("PlotLine"):null); var config=new ConfigurationBuilder().AddInMemoryCollection(new Dictionary { ["Admin:AllowedEmails:0"]="approved-admin@example.invalid" }).Build(); var context=new HttpContextAccessor {HttpContext=new DefaultHttpContext()}; var help=new HelpService(environment,config,context);var all=help.GetSourceArticles(); Check(all.Count==409 && all.Count(a=>a.Visibility=="administrator")==42 && all.Count(a=>a.Visibility=="public")==367,"Complete explicit visibility audit"); Check(all.All(a=>a.Visibility is "public" or "administrator" or "internal"),"Missing visibility fails publication"); var restricted=all.Where(a=>a.Visibility=="administrator").ToArray(); foreach(var principal in new[]{new ClaimsPrincipal(),new ClaimsPrincipal(new ClaimsIdentity(new[]{new Claim(ClaimTypes.Email,"ordinary@example.invalid"),new Claim(ClaimTypes.Role,"Admin")},"Fixture"))}) { context.HttpContext.User=principal; Check(help.GetAllArticles().Count==367 && !help.GetCategories().Contains("Story Intelligence Admin"),"Anonymous/nonadmin navigation excludes restricted category"); foreach(var a in restricted) { Check(help.GetByContextKey(a.ContextKey) is null && help.GetBySlugs(a.CategorySlug,a.Slug) is null && help.GetByRelativePath(a.RelativePath) is null,"All direct lookup forms deny restricted help"); Check(help.Search(a.Title).All(x=>x.Visibility=="public"),"Search cannot return admin help"); } Check(help.GetRelatedArticles(help.GetAllArticles()[0],500).All(a=>a.Visibility=="public"),"Related recommendations respect access"); } context.HttpContext.User=new ClaimsPrincipal(new ClaimsIdentity(new[]{new Claim(ClaimTypes.Email,"approved-admin@example.invalid")},"Fixture")); Check(AdministratorAccess.IsAllowed(context.HttpContext.User,config) && help.GetAllArticles().Count==409,"Existing AdminOnly rule retains full administrator documentation"); foreach(var a in restricted)Check(help.GetByContextKey(a.ContextKey)?.Visibility=="administrator","Administrators retain every restricted context identifier"); context.HttpContext.User=new ClaimsPrincipal();Check(help.GetAllArticles().Count==367,"Singleton cache does not leak prior administrator view"); Console.WriteLine("PASS help visibility: 409 classified articles, 42 restricted; anonymous/user/admin lookups, search, navigation, related links and cache isolation"); } }