From 6a6cc3a967468dd4b84d711fda2648dc3255e496 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 29 Aug 2026 16:23:58 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Validation=20de=20l=E2=80=99email?= =?UTF-8?q?=20d=E2=80=99inscription=20ajout=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vvalidation au point le plus sûr : le modèle de formulaire, avec un garde-fou côté contrôleur pour normaliser la valeur avant création du compte. * Ajout de [EmailAddress] dans RegisterModel.cs * Nettoyage de model.Email avec Trim() avant le ModelState.IsValid dans AccountController.cs * Ajout d’un test de régression dans EMailling.cs Additionnellement, le job de test est corrigé pour laisser vivre le test en plateforme Android, hors CI --- .forgejo/workflows/buildAndTest.yml | 6 ++++- .github/workflows/docker-publish-backend.yml | 2 +- .../PostIt.Tests/AndroidAppLaunchTests.cs | 5 ++-- .../Authentication/RegisterModel.cs | 4 ++-- .../NonRegression/EMailling.cs | 24 +++++++++++++++++++ .../Accounting/AccountController.cs | 2 ++ 6 files changed, 37 insertions(+), 6 deletions(-) diff --git a/.forgejo/workflows/buildAndTest.yml b/.forgejo/workflows/buildAndTest.yml index cb18656d..ea58d2fe 100644 --- a/.forgejo/workflows/buildAndTest.yml +++ b/.forgejo/workflows/buildAndTest.yml @@ -44,4 +44,8 @@ jobs: - name: Test run: | echo "🚀 Lancement des tests..." - cd /src/_src && dotnet test --verbosity normal && echo "✅ Success !" || echo "❌ Fail ($?)!" + cd /src/_src && dotnet test \ + --verbosity normal \ + --filter="Category!=Platform-Android" \ + --logger "xunit;LogFileName=test-results.xml" \ + && echo "✅ Success !" || echo "❌ Fail ($?)!" diff --git a/.github/workflows/docker-publish-backend.yml b/.github/workflows/docker-publish-backend.yml index 6c2431ae..d8466bdb 100644 --- a/.github/workflows/docker-publish-backend.yml +++ b/.github/workflows/docker-publish-backend.yml @@ -26,7 +26,7 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Test - run: dotnet test --no-build --verbosity normal + run: dotnet test --no-build --verbosity normal --filter="Category!=Platform-Android" # 4. Build et Push de l'image de production finale - name: Build and push production image uses: docker/build-push-action@v7 diff --git a/src/PostIt/PostIt.Tests/AndroidAppLaunchTests.cs b/src/PostIt/PostIt.Tests/AndroidAppLaunchTests.cs index d4980d26..25630c83 100644 --- a/src/PostIt/PostIt.Tests/AndroidAppLaunchTests.cs +++ b/src/PostIt/PostIt.Tests/AndroidAppLaunchTests.cs @@ -12,6 +12,7 @@ namespace PostIt.Tests; /// Skip conditions: the package is not installed on the connected device, /// or no device is connected via adb. /// +[Trait("Category", "Platform-Android")] public class AndroidAppLaunchTests { private const string PackageName = "fr.pschneider.postit"; @@ -23,8 +24,8 @@ public class AndroidAppLaunchTests _output = output; } - // https://twosixtech.com/blog/integrating-docker-and-adb/ - // FIXME ala hosted shared resource adb server - [Fact] + // TODO https://twosixtech.com/blog/integrating-docker-and-adb/ + [Fact] public void PostIt_starts_and_draws_a_first_frame_on_the_emulator() { if (!IsPackageInstalledOnAnyDevice()) diff --git a/src/Yavsc.Abstract/Authentication/RegisterModel.cs b/src/Yavsc.Abstract/Authentication/RegisterModel.cs index 2ebb3297..3bf9876b 100644 --- a/src/Yavsc.Abstract/Authentication/RegisterModel.cs +++ b/src/Yavsc.Abstract/Authentication/RegisterModel.cs @@ -12,8 +12,8 @@ namespace Yavsc.ViewModels.Account public string UserName { get; set; } [Required()] - [StringLength( maximumLength:102, MinimumLength = 5)] - // [EmailAddress] + [StringLength(maximumLength: 102, MinimumLength = 5)] + [EmailAddress(ErrorMessage = "L'adresse e-mail n'est pas valide.")] [Display(Name = "Email", Description = "E-Mail")] public string Email { get; set; } diff --git a/src/Yavsc.Org.Tests/NonRegression/EMailling.cs b/src/Yavsc.Org.Tests/NonRegression/EMailling.cs index 5b1b33e9..d5599842 100644 --- a/src/Yavsc.Org.Tests/NonRegression/EMailling.cs +++ b/src/Yavsc.Org.Tests/NonRegression/EMailling.cs @@ -1,8 +1,10 @@ +using System.ComponentModel.DataAnnotations; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Yavsc.Interface; using Yavsc.Interfaces; using Yavsc.Org.Tests.Fakes; +using Yavsc.ViewModels.Account; namespace Yavsc.Org.Tests { @@ -56,5 +58,27 @@ namespace Yavsc.Org.Tests Assert.Equal(_serverFixture.SiteSettings.Owner.EMail, client.LastSentMessage?.To.Mailboxes.First().Address); } + [Fact] + public void RegisterModel_rejects_invalid_email_format() + { + var model = new RegisterModel + { + UserName = "alice", + Email = "this is not an email", + Password = "Password123!", + ConfirmPassword = "Password123!" + }; + + var results = new List(); + var valid = Validator.TryValidateObject( + model, + new ValidationContext(model), + results, + validateAllProperties: true); + + Assert.False(valid); + Assert.Contains(results, r => r.MemberNames.Contains(nameof(RegisterModel.Email))); + } + } } diff --git a/src/Yavsc.Org/Controllers/Accounting/AccountController.cs b/src/Yavsc.Org/Controllers/Accounting/AccountController.cs index c562736d..05cb55b5 100644 --- a/src/Yavsc.Org/Controllers/Accounting/AccountController.cs +++ b/src/Yavsc.Org/Controllers/Accounting/AccountController.cs @@ -564,6 +564,8 @@ IHtmlLocalizerFactory htmlLocalizerFactory, [ValidateAntiForgeryToken] public async Task Register(RegisterModel model) { + model.Email = model.Email?.Trim(); + if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };