Compare commits
No commits in common. "51dc24de34702ca83837920d0f2de2e253d3dc65" and "0bfe61cbb80bc2f8dac096f8880accef9adf1852" have entirely different histories.
51dc24de34
...
0bfe61cbb8
7 changed files with 7 additions and 122 deletions
|
|
@ -44,8 +44,4 @@ jobs:
|
||||||
- name: Test
|
- name: Test
|
||||||
run: |
|
run: |
|
||||||
echo "🚀 Lancement des tests..."
|
echo "🚀 Lancement des tests..."
|
||||||
cd /src/_src && dotnet test \
|
cd /src/_src && dotnet test --verbosity normal && echo "✅ Success !" || echo "❌ Fail ($?)!"
|
||||||
--verbosity normal \
|
|
||||||
--filter="Category!=Platform-Android" \
|
|
||||||
--logger "xunit;LogFileName=test-results.xml" \
|
|
||||||
&& echo "✅ Success !" || echo "❌ Fail ($?)!"
|
|
||||||
|
|
|
||||||
2
.github/workflows/docker-publish-backend.yml
vendored
2
.github/workflows/docker-publish-backend.yml
vendored
|
|
@ -26,7 +26,7 @@ jobs:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
- name: Test
|
- name: Test
|
||||||
run: dotnet test --no-build --verbosity normal --filter="Category!=Platform-Android"
|
run: dotnet test --no-build --verbosity normal
|
||||||
# 4. Build et Push de l'image de production finale
|
# 4. Build et Push de l'image de production finale
|
||||||
- name: Build and push production image
|
- name: Build and push production image
|
||||||
uses: docker/build-push-action@v7
|
uses: docker/build-push-action@v7
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ namespace PostIt.Tests;
|
||||||
/// Skip conditions: the package is not installed on the connected device,
|
/// Skip conditions: the package is not installed on the connected device,
|
||||||
/// or no device is connected via adb.
|
/// or no device is connected via adb.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Trait("Category", "Platform-Android")]
|
|
||||||
public class AndroidAppLaunchTests
|
public class AndroidAppLaunchTests
|
||||||
{
|
{
|
||||||
private const string PackageName = "fr.pschneider.postit";
|
private const string PackageName = "fr.pschneider.postit";
|
||||||
|
|
@ -24,8 +23,8 @@ public class AndroidAppLaunchTests
|
||||||
_output = output;
|
_output = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO https://twosixtech.com/blog/integrating-docker-and-adb/
|
// https://twosixtech.com/blog/integrating-docker-and-adb/
|
||||||
[Fact]
|
// FIXME ala hosted shared resource adb server - [Fact]
|
||||||
public void PostIt_starts_and_draws_a_first_frame_on_the_emulator()
|
public void PostIt_starts_and_draws_a_first_frame_on_the_emulator()
|
||||||
{
|
{
|
||||||
if (!IsPackageInstalledOnAnyDevice())
|
if (!IsPackageInstalledOnAnyDevice())
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ namespace Yavsc.ViewModels.Account
|
||||||
public string UserName { get; set; }
|
public string UserName { get; set; }
|
||||||
|
|
||||||
[Required()]
|
[Required()]
|
||||||
[StringLength(maximumLength: 102, MinimumLength = 5)]
|
[StringLength( maximumLength:102, MinimumLength = 5)]
|
||||||
[EmailAddress(ErrorMessage = "L'adresse e-mail n'est pas valide.")]
|
// [EmailAddress]
|
||||||
[Display(Name = "Email", Description = "E-Mail")]
|
[Display(Name = "Email", Description = "E-Mail")]
|
||||||
public string Email { get; set; }
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,8 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Globalization;
|
|
||||||
using MailKit.Net.Smtp;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Localization;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
using MimeKit;
|
|
||||||
using Yavsc.Interface;
|
using Yavsc.Interface;
|
||||||
using Yavsc.Interfaces;
|
using Yavsc.Interfaces;
|
||||||
using Yavsc.Models.Relationship;
|
|
||||||
using Yavsc.Org.Tests.Fakes;
|
using Yavsc.Org.Tests.Fakes;
|
||||||
using Yavsc.Services;
|
|
||||||
using Yavsc.Settings;
|
|
||||||
using Yavsc.ViewModels.Account;
|
|
||||||
|
|
||||||
namespace Yavsc.Org.Tests
|
namespace Yavsc.Org.Tests
|
||||||
{
|
{
|
||||||
|
|
@ -67,96 +56,5 @@ namespace Yavsc.Org.Tests
|
||||||
Assert.Equal(_serverFixture.SiteSettings.Owner.EMail, client.LastSentMessage?.To.Mailboxes.First().Address);
|
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<ValidationResult>();
|
|
||||||
var valid = Validator.TryValidateObject(
|
|
||||||
model,
|
|
||||||
new ValidationContext(model),
|
|
||||||
results,
|
|
||||||
validateAllProperties: true);
|
|
||||||
|
|
||||||
Assert.False(valid);
|
|
||||||
Assert.Contains(results, r => r.MemberNames.Contains(nameof(RegisterModel.Email)));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task SendEmailAsync_ignores_smtp_recipient_rejection()
|
|
||||||
{
|
|
||||||
var sender = new MailSender(
|
|
||||||
Options.Create(new SiteSettings
|
|
||||||
{
|
|
||||||
Title = "Test",
|
|
||||||
Authority = "example.com",
|
|
||||||
Owner = new StaticContact { Name = "Test Owner", EMail = "owner@example.com" }
|
|
||||||
}),
|
|
||||||
Options.Create(new SmtpSettings
|
|
||||||
{
|
|
||||||
Host = "smtp.test.local",
|
|
||||||
Port = 465,
|
|
||||||
UserName = "test-user",
|
|
||||||
Password = "secret"
|
|
||||||
}),
|
|
||||||
NullLoggerFactory.Instance,
|
|
||||||
new TestStringLocalizer(),
|
|
||||||
new RejectingSmtpClientFactory());
|
|
||||||
|
|
||||||
var result = await sender.SendEmailAsync(
|
|
||||||
"Alice",
|
|
||||||
"contact@pschneider.fr",
|
|
||||||
"Welcome",
|
|
||||||
"hello");
|
|
||||||
|
|
||||||
Assert.Equal(string.Empty, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class RejectingSmtpClientFactory : ISmtpClientFactory
|
|
||||||
{
|
|
||||||
public Yavsc.Interfaces.ISmtpClient CreateClient() => new RejectingSmtpClient();
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class RejectingSmtpClient : Yavsc.Interfaces.ISmtpClient
|
|
||||||
{
|
|
||||||
public int Timeout { get; set; }
|
|
||||||
public void Connect(string host, int port, MailKit.Security.SecureSocketOptions options) { }
|
|
||||||
public void Authenticate(string userName, string password) { }
|
|
||||||
public Task SendAsync(MimeMessage message, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
throw new SmtpCommandException(
|
|
||||||
SmtpErrorCode.RecipientNotAccepted,
|
|
||||||
SmtpStatusCode.MailboxUnavailable,
|
|
||||||
"Recipient address rejected: User unknown in local recipient table");
|
|
||||||
}
|
|
||||||
public void Disconnect(bool quit) { }
|
|
||||||
public void Dispose() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
private sealed class TestStringLocalizer : IStringLocalizer<MailSender>
|
|
||||||
{
|
|
||||||
public LocalizedString this[string name] => new(name, name);
|
|
||||||
public LocalizedString this[string name, params object[] arguments] => new(name, string.Format(CultureInfo.InvariantCulture, name, arguments));
|
|
||||||
|
|
||||||
public IEnumerable<LocalizedString> GetAllStrings(bool includeParentCultures)
|
|
||||||
=> Enumerable.Empty<LocalizedString>();
|
|
||||||
|
|
||||||
public LocalizedString GetString(string name)
|
|
||||||
=> new(name, name);
|
|
||||||
|
|
||||||
public LocalizedString GetString(string name, params object[] arguments)
|
|
||||||
=> new(name, string.Format(CultureInfo.InvariantCulture, name, arguments));
|
|
||||||
|
|
||||||
public IStringLocalizer WithCulture(CultureInfo culture)
|
|
||||||
=> this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -564,8 +564,6 @@ IHtmlLocalizerFactory htmlLocalizerFactory,
|
||||||
[ValidateAntiForgeryToken]
|
[ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Register(RegisterModel model)
|
public async Task<IActionResult> Register(RegisterModel model)
|
||||||
{
|
{
|
||||||
model.Email = model.Email?.Trim();
|
|
||||||
|
|
||||||
if (ModelState.IsValid)
|
if (ModelState.IsValid)
|
||||||
{
|
{
|
||||||
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
|
var user = new ApplicationUser { UserName = model.UserName, Email = model.Email };
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
using MailKit.Net.Smtp;
|
|
||||||
using MailKit.Security;
|
using MailKit.Security;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
@ -115,7 +114,7 @@ namespace Yavsc.Services
|
||||||
msg.MessageId = MimeKit.Utils.MimeUtils.GenerateMessageId(
|
msg.MessageId = MimeKit.Utils.MimeUtils.GenerateMessageId(
|
||||||
siteSettings.Authority
|
siteSettings.Authority
|
||||||
);
|
);
|
||||||
using Yavsc.Interfaces.ISmtpClient sc = _smtpClientFactory.CreateClient();
|
using ISmtpClient sc = _smtpClientFactory.CreateClient();
|
||||||
{
|
{
|
||||||
sc.Timeout = 30000;
|
sc.Timeout = 30000;
|
||||||
sc.Connect(
|
sc.Connect(
|
||||||
|
|
@ -140,11 +139,6 @@ namespace Yavsc.Services
|
||||||
logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings.Owner.EMail);
|
logger.LogError(ex, "Refusing to send email because the recipient or sender address is malformed. To={To}, From={From}", email, siteSettings.Owner.EMail);
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
catch (SmtpCommandException ex)
|
|
||||||
{
|
|
||||||
logger.LogError(ex, "SMTP rejected the recipient or sender address. To={To}, Subject={Subject}, Status={Status}, Error={Error}", email, subject, ex.StatusCode, ex.Message);
|
|
||||||
return string.Empty;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError(ex, "Failed to send email. To={To}, Subject={Subject}", email, subject);
|
logger.LogError(ex, "Failed to send email. To={To}, Subject={Subject}", email, subject);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue