2026-08-12 10:46:09 +02:00
|
|
|
|
using Bunit;
|
|
|
|
|
|
using Heimdall.Web.Components.Settings;
|
|
|
|
|
|
using Heimdall.Web.Services;
|
|
|
|
|
|
using Heimdall.Web.Tests.Components.Pages;
|
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
using MudBlazor;
|
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Web.Tests.Components.Settings;
|
|
|
|
|
|
|
|
|
|
|
|
public class NotificationSettingsSectionTests : PageTestBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private static AppSettingItem Setting(string key, string value) =>
|
|
|
|
|
|
new(Guid.NewGuid(), key, value, key, "integrations", "string", null, DateTime.UtcNow.AddDays(-1));
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void NotificationSection_AfficheChampsNtfyEtEmail()
|
|
|
|
|
|
{
|
|
|
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>
|
|
|
|
|
|
{
|
2026-08-12 11:12:28 +02:00
|
|
|
|
Setting("ntfy.baseurl", "https://ntfy.sh"),
|
2026-08-12 10:46:09 +02:00
|
|
|
|
Setting("ntfy.token", "tok123"),
|
2026-08-12 11:12:28 +02:00
|
|
|
|
Setting("email.fromaddress", "alertes@heimdall.local"),
|
|
|
|
|
|
Setting("email.smtphost", "smtp.gmail.com"),
|
|
|
|
|
|
Setting("email.usessl", "true"),
|
2026-08-12 10:46:09 +02:00
|
|
|
|
});
|
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
|
|
var cut = Render<NotificationSettingsSection>();
|
|
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
cut.Markup.ShouldContain("Serveur ntfy");
|
2026-10-25 06:30:33 +01:00
|
|
|
|
cut.Markup.ShouldContain("Jeton d’accès");
|
2026-08-12 10:46:09 +02:00
|
|
|
|
cut.Markup.ShouldContain("Adresse expéditrice");
|
|
|
|
|
|
cut.Markup.ShouldContain("Serveur SMTP");
|
|
|
|
|
|
cut.Markup.ShouldContain("https://ntfy.sh");
|
|
|
|
|
|
cut.Markup.ShouldContain("smtp.gmail.com");
|
|
|
|
|
|
cut.Markup.ShouldContain("Utiliser SSL/TLS");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public async Task NotificationSection_ModifieBaseUrl_AppellePutAvecBonneCle()
|
|
|
|
|
|
{
|
2026-08-12 11:12:28 +02:00
|
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ntfy.baseurl", "https://ntfy.sh") });
|
|
|
|
|
|
Handler.On(HttpMethod.Put, "api/settings/ntfy.baseurl", System.Net.HttpStatusCode.OK);
|
2026-08-12 10:46:09 +02:00
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
|
|
var cut = Render<NotificationSettingsSection>();
|
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("https://ntfy.sh"));
|
|
|
|
|
|
|
2026-08-12 11:12:28 +02:00
|
|
|
|
// Inputs texte : [0]=ntfy.baseurl (les 8 champs texte viennent avant le switch)
|
2026-08-12 10:46:09 +02:00
|
|
|
|
cut.FindAll("input")[0].Change("https://ntfy.tordais.cc");
|
|
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Handler.Requests.ShouldContain(r =>
|
|
|
|
|
|
r.Method == HttpMethod.Put &&
|
2026-08-12 11:12:28 +02:00
|
|
|
|
r.RequestUri!.AbsolutePath.Contains("ntfy.baseurl", StringComparison.OrdinalIgnoreCase));
|
2026-08-12 10:46:09 +02:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void NotificationSection_SecretRedacte_ChampVideAvecPlaceholder()
|
|
|
|
|
|
{
|
|
|
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>
|
|
|
|
|
|
{
|
2026-08-12 11:12:28 +02:00
|
|
|
|
Setting("ntfy.baseurl", "https://ntfy.sh"),
|
2026-08-12 10:46:09 +02:00
|
|
|
|
Setting("ntfy.token", "***REDACTED***"),
|
|
|
|
|
|
Setting("email.password", "***REDACTED***"),
|
|
|
|
|
|
});
|
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
|
|
var cut = Render<NotificationSettingsSection>();
|
|
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// Le champ token ne doit PAS exposer la valeur redactée
|
|
|
|
|
|
cut.FindAll("input")[1].GetAttribute("value").ShouldBe(string.Empty);
|
|
|
|
|
|
// Le champ mot de passe SMTP non plus (7e champ texte)
|
|
|
|
|
|
cut.FindAll("input")[7].GetAttribute("value").ShouldBe(string.Empty);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-08-12 11:50:47 +02:00
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void NotificationSection_TestNtfy_AppelleEndpointEtAfficheSucces()
|
|
|
|
|
|
{
|
|
|
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("ntfy.baseurl", "https://ntfy.sh") });
|
|
|
|
|
|
Handler.On(HttpMethod.Post, "api/settings/ntfy/test",
|
|
|
|
|
|
new { success = true, message = "Notification test envoyée sur le topic « heimdall-test »" });
|
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
|
|
var cut = Render<NotificationSettingsSection>();
|
|
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tester ntfy"));
|
|
|
|
|
|
|
|
|
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Tester ntfy")).Click();
|
|
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Handler.Requests.ShouldContain(r =>
|
|
|
|
|
|
r.Method == HttpMethod.Post &&
|
|
|
|
|
|
r.RequestUri!.AbsolutePath.Contains("ntfy/test", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
cut.Markup.ShouldContain("Notification test envoyée");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void NotificationSection_TestEmail_AppelleEndpointEtAfficheErreur()
|
|
|
|
|
|
{
|
|
|
|
|
|
Handler.OnGet("api/settings", new List<AppSettingItem> { Setting("email.fromaddress", "a@b.c") });
|
|
|
|
|
|
Handler.On(HttpMethod.Post, "api/settings/email/test",
|
|
|
|
|
|
new { success = false, message = "Échec de l'envoi : SMTP injoignable" });
|
|
|
|
|
|
LoginAs();
|
|
|
|
|
|
|
|
|
|
|
|
var cut = Render<NotificationSettingsSection>();
|
2026-10-25 06:30:33 +01:00
|
|
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tester l’envoi de courriel"));
|
2026-08-12 11:50:47 +02:00
|
|
|
|
|
2026-10-25 06:30:33 +01:00
|
|
|
|
cut.FindAll("button").Single(b => b.TextContent.Contains("Tester l’envoi de courriel")).Click();
|
2026-08-12 11:50:47 +02:00
|
|
|
|
|
|
|
|
|
|
cut.WaitForAssertion(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Handler.Requests.ShouldContain(r =>
|
|
|
|
|
|
r.Method == HttpMethod.Post &&
|
|
|
|
|
|
r.RequestUri!.AbsolutePath.Contains("email/test", StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
cut.Markup.ShouldContain("SMTP injoignable");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2026-08-12 10:46:09 +02:00
|
|
|
|
}
|