Skip to content

Commit

Permalink
Fix: 1034 mailinator no longer working for automated tests (and other…
Browse files Browse the repository at this point in the history
… bugs) (#1225)

* Fix gram. info. not rendered on first load

* Fix invite link should be relative

* Fix out of date Playwright texts

* Adapt to new GQL error handling: no 500s
See: https://chillicream.com/blog/2024/08/30/hot-chocolate-14/#transport

* Refactor email Playwright tests to use maildev API and e2e-mailbox

* refactor how we make the login redirect link so we validate that the return to is not an absolute Uri

---------

Co-authored-by: Kevin Hahn <[email protected]>
  • Loading branch information
myieye and hahn-kev authored Nov 12, 2024
1 parent f6db408 commit faba095
Show file tree
Hide file tree
Showing 25 changed files with 503 additions and 250 deletions.
31 changes: 19 additions & 12 deletions backend/LexBoxApi/Services/EmailService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public async Task SendForgotPasswordEmail(string emailAddress)
var httpContext = httpContextAccessor.HttpContext;
ArgumentNullException.ThrowIfNull(httpContext);
// returnTo is a svelte app url
var forgotLink = _linkGenerator.GetUriByAction(httpContext,
"LoginRedirect",
"Login",
new { jwt, returnTo = "/resetPassword" });
ArgumentException.ThrowIfNullOrEmpty(forgotLink);
var forgotLink = MakeLoginRedirectUrl(jwt, "/resetPassword");
await RenderEmail(email, new ForgotPasswordEmail(user.Name, forgotLink, lifetime), user.LocalizationCode);
await SendEmailWithRetriesAsync(email, retryCount: 5, retryWaitSeconds: 30);
}
Expand Down Expand Up @@ -166,15 +162,11 @@ private async Task SendInvitationEmail(
var httpContext = httpContextAccessor.HttpContext;
ArgumentNullException.ThrowIfNull(httpContext);

var returnTo = _linkGenerator.GetUriByAction(httpContext,
nameof(LexBoxApi.Controllers.UserController.HandleInviteLink),
var returnTo = _linkGenerator.GetPathByAction(httpContext,
nameof(Controllers.UserController.HandleInviteLink),
"User");
var registerLink = _linkGenerator.GetUriByAction(httpContext,
"LoginRedirect",
"Login",
new { jwt, returnTo });
var registerLink = MakeLoginRedirectUrl(jwt, returnTo);

ArgumentException.ThrowIfNullOrEmpty(registerLink);
if (isProjectInvitation)
{
await RenderEmail(email, new ProjectInviteEmail(emailAddress, managerName, resourceName ?? "", registerLink, lifetime), language);
Expand Down Expand Up @@ -296,4 +288,19 @@ private static MimeMessage StartUserEmail(string name, string email)
message.To.Add(new MailboxAddress(name, email));
return message;
}

private string MakeLoginRedirectUrl(string jwt, string? returnTo)
{
ArgumentException.ThrowIfNullOrEmpty(jwt);
ArgumentException.ThrowIfNullOrEmpty(returnTo);
if (new Uri(returnTo).IsAbsoluteUri) throw new ArgumentException($"returnTo must be relative, was: {returnTo}", nameof(returnTo));
var httpContext = httpContextAccessor.HttpContext;
ArgumentNullException.ThrowIfNull(httpContext);
var loginRedirect = _linkGenerator.GetUriByAction(httpContext,
"LoginRedirect",
"Login",
new { jwt, returnTo });
ArgumentException.ThrowIfNullOrEmpty(loginRedirect);
return loginRedirect;
}
}
2 changes: 1 addition & 1 deletion backend/LexBoxApi/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"CloudFlare": {
// always passes key, more info here: https://developers.cloudflare.com/turnstile/frequently-asked-questions/#are-there-sitekeys-and-secret-keys-that-can-be-used-for-testing
"TurnstileKey": "1x0000000000000000000000000000000AA",
"AllowDomain": "mailinator.com"
"AllowDomain": "maildev.com"
},
"HgConfig": {
"RepoPath": "../../hgweb/repos",
Expand Down
2 changes: 1 addition & 1 deletion deployment/develop/lexbox-deployment.patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
- name: lexbox-api
env:
- name: CloudFlare__AllowDomain
value: "mailinator.com"
value: "developermail.com"
- name: ASPNETCORE_ENVIRONMENT
value: "Staging" #we don't want to act like dev as that's for local development
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion deployment/local-dev/lexbox-deployment.patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
value: "1x0000000000000000000000000000000AA"
valueFrom:
- name: CloudFlare__AllowDomain
value: "mailinator.com"
value: "maildev.com"
- name: HealthChecksConfig__RequireFwHeadlessContainerVersionMatch
value: "false"
- name: HealthChecksConfig__RequireHealthyFwHeadlessContainer
Expand Down
2 changes: 1 addition & 1 deletion deployment/staging/lexbox-deployment.patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:

env:
- name: CloudFlare__AllowDomain
value: "mailinator.com"
value: "developermail.com"
- name: Email__SmtpHost
value: email-smtp.us-east-1.amazonaws.com
- name: Email__SmtpPort
Expand Down
1 change: 1 addition & 0 deletions frontend/.npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
engine-strict=true
include-workspace-root=true
ignore-workspace-root-check=true # we commonly add packages to the root package.json (aka frontend/package.json)
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"@types/set-cookie-parser": "^2.4.7",
"@vitejs/plugin-basic-ssl": "^1.1.0",
"css-tree": "^2.3.1",
"e2e-mailbox": "1.1.5",
"js-cookie": "^3.0.5",
"just-order-by": "^1.0.0",
"mjml": "^4.15.3",
Expand Down
Loading

0 comments on commit faba095

Please sign in to comment.