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();
+}
diff --git a/tests/Khaemhat.Web.Tests/Shell/NotificationInboxTests.cs b/tests/Khaemhat.Web.Tests/Shell/NotificationInboxTests.cs
new file mode 100644
index 0000000..741fd57
--- /dev/null
+++ b/tests/Khaemhat.Web.Tests/Shell/NotificationInboxTests.cs
@@ -0,0 +1,70 @@
+using Khaemhat.Application.Modules;
+using Khaemhat.Application.Notifications;
+using Khaemhat.Application.Security;
+using Khaemhat.Core.Instance;
+using Khaemhat.Core.Security;
+using Khaemhat.Web.Tests.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Khaemhat.Web.Tests.Shell;
+
+/// The notification panel of mockup 010 (issue #32): what each user reads is kept per user.
+[TestClass]
+public sealed class NotificationInboxTests
+{
+ private const string Category = "test";
+
+ [TestMethod]
+ public async Task ANotificationForEveryone_IsReadByEachUserSeparately()
+ {
+ var (app, _, company) = await TestInstance.StartAsync(CancellationToken.None);
+ await using (app)
+ {
+ var notifications = app.Services.GetRequiredService();
+ var users = app.Services.GetRequiredService();
+ var root = new Actor(TestInstance.SuperUser, UserLevel.SuperUser, 1, null, null);
+ var (anna, _) = await users.CreateAsync(root, company, new NewCompanyUser("anna", "Anna Verdi", null, UserKind.Human, [PredefinedRoles.ReadOnly], new UserFlags(false, false, false, false)));
+ var (luca, _) = await users.CreateAsync(root, company, new NewCompanyUser("luca", "Luca Neri", null, UserKind.Human, [PredefinedRoles.ReadOnly], new UserFlags(false, false, false, false)));
+ var annaActor = new Actor("anna", UserLevel.Standard, null, anna.Id, company);
+ var lucaActor = new Actor("luca", UserLevel.Standard, null, luca.Id, company);
+
+ await notifications.NotifyCompanyAsync(company, new NotificationMessage(Category, NotificationSeverity.Info, "Per tutti"));
+ await notifications.NotifyCompanyAsync(company, new NotificationMessage(Category, NotificationSeverity.Warning, "Solo per Anna", "Dettaglio", "/profilo"), anna.Id);
+
+ var annaInbox = await Inbox(annaActor);
+ CollectionAssert.AreEqual(new[] { "Solo per Anna", "Per tutti" }, annaInbox.Select(n => n.Title).ToList(), "Newest first.");
+ Assert.IsTrue(annaInbox[0].Personal);
+ Assert.AreEqual("/profilo", annaInbox[0].Link);
+ Assert.IsTrue(annaInbox.All(n => !n.Read));
+ CollectionAssert.AreEqual(new[] { "Per tutti" }, (await Inbox(lucaActor)).Select(n => n.Title).ToList(), "Personal notifications stay personal.");
+
+ // Anna reads the one for everyone: it stays unread for Luca; reading it again changes nothing.
+ var everyone = annaInbox[1].Id;
+ await notifications.MarkReadAsync(annaActor, everyone);
+ await notifications.MarkReadAsync(annaActor, everyone);
+ Assert.IsTrue((await Inbox(annaActor)).Single(n => n.Id == everyone).Read);
+ Assert.IsFalse((await Inbox(lucaActor)).Single(n => n.Id == everyone).Read);
+
+ // Nobody marks someone else's notification.
+ await notifications.MarkReadAsync(lucaActor, annaInbox[0].Id);
+ Assert.IsFalse((await Inbox(annaActor)).Single(n => n.Id == annaInbox[0].Id).Read);
+
+ // "Segna tutte come lette" is for the user only.
+ await notifications.MarkAllReadAsync(annaActor);
+ Assert.IsEmpty(await Inbox(annaActor, unreadOnly: true));
+ Assert.HasCount(1, await Inbox(lucaActor, unreadOnly: true));
+
+ // Instance accounts read the notifications of the system.
+ await notifications.NotifyInstanceAsync(new NotificationMessage(Category, NotificationSeverity.Error, "Backup non riuscito"));
+ var system = await Inbox(root, unreadOnly: true);
+ Assert.AreEqual("Backup non riuscito", system.Single().Title);
+ Assert.IsFalse((await Inbox(annaActor)).Any(n => n.Title == "Backup non riuscito"));
+ await notifications.MarkAllReadAsync(root);
+ Assert.IsEmpty(await Inbox(root, unreadOnly: true));
+ await app.StopAsync();
+
+ async Task> Inbox(Actor actor, bool unreadOnly = false) =>
+ [.. (await notifications.InboxAsync(actor, unreadOnly)).Where(n => n.Category == Category)];
+ }
+ }
+}