Heimdall Gitea / Build and tests (pull_request) Failing after 7m50s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
130 lines
4.9 KiB
C#
130 lines
4.9 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("Jeton d’accès");
|
||
cut.Markup.ShouldContain("Adresse d’expédition");
|
||
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);
|
||
});
|
||
}
|
||
|
||
[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>();
|
||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Tester l’envoi de courriel"));
|
||
|
||
cut.FindAll("button").Single(b => b.TextContent.Contains("Tester l’envoi de courriel")).Click();
|
||
|
||
cut.WaitForAssertion(() =>
|
||
{
|
||
Handler.Requests.ShouldContain(r =>
|
||
r.Method == HttpMethod.Post &&
|
||
r.RequestUri!.AbsolutePath.Contains("email/test", StringComparison.OrdinalIgnoreCase));
|
||
cut.Markup.ShouldContain("SMTP injoignable");
|
||
});
|
||
}
|
||
}
|