Nota importante.
");
StringAssert.Contains(html, "
<script>alert(1)</script>
");
StringAssert.Contains(html, "
");
}
[TestMethod]
public void Markdown_LinksAndImages_AreSafe()
{
var html = WikiMarkdown.ToHtml(
"Vedi [Anagrafiche](Anagrafiche), [clienti](Anagrafiche#clienti), [sito](https://example.com), [qui](#come-si-usa), "
+ "[male](javascript:alert) e
non HTML.   ",
Links);
StringAssert.Contains(html, "
Anagrafiche");
StringAssert.Contains(html, "
clienti");
StringAssert.Contains(html, "
sito");
StringAssert.Contains(html, "
qui");
Assert.DoesNotContain("javascript:", html);
StringAssert.Contains(html, "male e <b>non HTML</b>");
StringAssert.Contains(html, "

");
StringAssert.Contains(html, "

();
foreach (var name in Wiki.PageNames)
{
foreach (Match link in PageLink().Matches(Wiki.Get(name)!.Html))
{
if (!Wiki.Exists(link.Groups[1].Value))
{
broken.Add(name + " -> " + link.Groups[1].Value);
}
}
}
Assert.IsEmpty(broken, string.Join(", ", broken));
}
[TestMethod]
public void EveryPage_AndEveryMenuEntry_HasAHelpPageThatExists()
{
var routes = typeof(HelpLinks).Assembly.GetTypes()
.Where(t => typeof(IComponent).IsAssignableFrom(t))
.SelectMany(t => t.GetCustomAttributes
())
.Select(r => "/" + r.Template.Split('{')[0].Trim('/'))
.Concat(MenuCatalog.All.Select(i => i.Href))
.Distinct()
.ToList();
Assert.IsGreaterThan(20, routes.Count);
var missing = routes.Where(r => !Wiki.Exists(HelpLinks.PageFor(r))).Select(r => r + " -> " + HelpLinks.PageFor(r)).ToList();
Assert.IsEmpty(missing, string.Join(", ", missing));
Assert.AreEqual("aiuto/Dashboard", HelpLinks.LocalFor("/"));
Assert.AreEqual("aiuto/Anagrafiche", HelpLinks.LocalFor("/anagrafiche/clienti?x=1"));
}
[TestMethod]
public async Task Search_FindsPageTitles_ThenTheirSections()
{
var provider = new HelpSearchProvider(Wiki);
var root = new Khaemhat.Application.Security.Actor("root", Khaemhat.Core.Security.UserLevel.SuperUser, 1, null, null);
var hits = await provider.SearchAsync(root, Khaemhat.Application.Search.SearchQuery.Parse("scorciatoie"), CancellationToken.None);
Assert.AreEqual("aiuto/Interfaccia-e-scorciatoie", hits[0].Href);
Assert.IsTrue(hits.All(h => h.Href.StartsWith("aiuto/", StringComparison.Ordinal)));
Assert.IsTrue(hits.Where(h => h.Detail is not null).All(h => h.Href.Contains('#', StringComparison.Ordinal)));
Assert.IsLessThanOrEqualTo(Khaemhat.Application.Search.GlobalSearchService.PerProvider, hits.Count);
}
[TestMethod]
public void OnlineWiki_AndProblemReports_FollowTheConfiguredAddress()
{
Assert.AreEqual(HelpLinks.DefaultBaseUrl, HelpLinks.BaseUrl(null));
Assert.AreEqual("https://git.example.com/acme/khaemhat/wiki/", HelpLinks.BaseUrl("https://git.example.com/acme/khaemhat/wiki"));
Assert.AreEqual("https://git.example.com/acme/khaemhat/issues/new", HelpLinks.IssuesUrl("https://git.example.com/acme/khaemhat/wiki/"));
Assert.IsNull(HelpLinks.IssuesUrl("https://docs.example.com/"));
}
[GeneratedRegex("href=\"aiuto/([^\"#]+)")]
private static partial Regex PageLink();
}