- SettingsPage refondue : plus de création/édition clé/valeur arbitraire, chaque domaine a sa section dédiée (pattern StorageSettingsSection) - NotificationSettingsSection : ntfy (baseUrl, token) + email SMTP (from, host, port, user, password, SSL) — secrets masqués, redaction API respectée - AiSettingsSection : URLs CodeProject.AI/Ollama + toggle détection IA - AgentDefaultsSection : niveau de log global (select), rétention logs, intervalle heartbeat, DSN Sentry - Seed #80 étendu : ai.detection.enabled, log.level, log.retentionDays, heartbeat.interval.seconds, sentry.dsn (idempotent, catégories cohérentes) - Tests bUnit : 12 tests (4 page + 8 sections) — rendu, PUT par clé, secrets redactés invisibles ; 221 tests Web verts
86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
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>
|
|
{
|
|
Setting("ntfy.baseUrl", "https://ntfy.sh"),
|
|
Setting("ntfy.token", "tok123"),
|
|
Setting("email.fromAddress", "alertes@heimdall.local"),
|
|
Setting("email.smtpHost", "smtp.gmail.com"),
|
|
Setting("email.useSsl", "true"),
|
|
});
|
|
LoginAs();
|
|
|
|
var cut = Render<NotificationSettingsSection>();
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
cut.Markup.ShouldContain("Serveur ntfy");
|
|
cut.Markup.ShouldContain("Token d'accès");
|
|
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()
|
|
{
|
|
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);
|
|
LoginAs();
|
|
|
|
var cut = Render<NotificationSettingsSection>();
|
|
cut.WaitForAssertion(() => cut.Markup.ShouldContain("https://ntfy.sh"));
|
|
|
|
// Inputs texte : [0]=ntfy.baseUrl (les 8 champs texte viennent avant le switch)
|
|
cut.FindAll("input")[0].Change("https://ntfy.tordais.cc");
|
|
|
|
cut.WaitForAssertion(() =>
|
|
{
|
|
Handler.Requests.ShouldContain(r =>
|
|
r.Method == HttpMethod.Put &&
|
|
r.RequestUri!.AbsolutePath.Contains("ntfy.baseUrl", StringComparison.OrdinalIgnoreCase));
|
|
});
|
|
}
|
|
|
|
[Fact]
|
|
public void NotificationSection_SecretRedacte_ChampVideAvecPlaceholder()
|
|
{
|
|
Handler.OnGet("api/settings", new List<AppSettingItem>
|
|
{
|
|
Setting("ntfy.baseUrl", "https://ntfy.sh"),
|
|
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);
|
|
});
|
|
}
|
|
}
|