Skip to content

Commit

Permalink
Small fixup and fix unit test conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
FeTetra committed Feb 18, 2025
1 parent f77e5ee commit 3fb1441
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<IActionResult> Announce()

UserEntity? user = await this.database.UserFromGameToken(token);

StringBuilder announceText = new(ServerConfiguration.Instance.AnnounceText + "\n\n");
StringBuilder announceText = new(ServerConfiguration.Instance.AnnounceText);

announceText.Replace("%user", user.Username);

Check warning on line 62 in ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs

View workflow job for this annotation

GitHub Actions / Build & Test (Linux, ubuntu-latest, true, true)

Dereference of a possibly null reference.

Check warning on line 62 in ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs

View workflow job for this annotation

GitHub Actions / Build & Test (Linux, ubuntu-latest, true, true)

Dereference of a possibly null reference.

Check warning on line 62 in ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Dereference of a possibly null reference.

Dereference of a possibly null reference
announceText.Replace("%id", token.UserId.ToString());
Expand All @@ -69,7 +69,7 @@ public async Task<IActionResult> Announce()

if (EmailEnforcementConfiguration.Instance.EnableEmailEnforcement)
{
announceText.Append(BaseLayoutStrings.EmailEnforcementWarnMain.Translate(LocalizationManager.DefaultLang) + "\n\n");
announceText.Append("\n\n" + BaseLayoutStrings.EmailEnforcementWarnMain.Translate(LocalizationManager.DefaultLang) + "\n\n");

if (user.EmailAddress == null)
{
Expand Down Expand Up @@ -148,7 +148,7 @@ public async Task<IActionResult> Filter(IMailService mailService)
if (!SMTPHelper.IsValidEmail(this.database, email)) return this.BadRequest();

UserEntity? user = await this.database.UserFromGameToken(token);
if (user == null || user.EmailAddressVerified) return this.Ok();
if (user == null || user.EmailAddressVerified) return this.BadRequest();

user.EmailAddress = email;
await SMTPHelper.SendVerificationEmail(this.database, mailService, user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public EmailEnforcementMiddleware(RequestDelegate next) : base(next)

public override async Task InvokeAsync(HttpContext context, DatabaseContext database)
{
// Split path into segments
string[] pathSegments = context.Request.Path.ToString().Split("/", StringSplitOptions.RemoveEmptyEntries);
if (EmailEnforcementConfiguration.Instance.EnableEmailEnforcement)
{
// Split path into segments
string[] pathSegments = context.Request.Path.ToString().Split("/", StringSplitOptions.RemoveEmptyEntries);

if (pathSegments[0] == "LITTLEBIGPLANETPS3_XML")
{
if (EmailEnforcementConfiguration.Instance.EnableEmailEnforcement)
if (pathSegments[0] == "LITTLEBIGPLANETPS3_XML")
{
// Get user via GameToken
GameTokenEntity? token = await database.GameTokenFromRequest(context.Request);
Expand All @@ -35,7 +35,7 @@ public override async Task InvokeAsync(HttpContext context, DatabaseContext data
if (user == null)
{
// Send bad request status
context.Response.StatusCode = StatusCodes.Status400BadRequest;
context.Response.StatusCode = StatusCodes.Status403Forbidden;
await context.Response.WriteAsync("Not a valid user");

// Don't go to next in pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public async Task Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailTaken()

IActionResult result = await messageController.Filter(mailMock.Object);

Assert.IsType<OkResult>(result);
Assert.IsType<BadRequestResult>(result);
mailMock.Verify(x => x.SendEmailAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}

Expand All @@ -249,7 +249,7 @@ public async Task Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailAlreadyVerif

IActionResult result = await messageController.Filter(mailMock.Object);

Assert.IsType<OkResult>(result);
Assert.IsType<BadRequestResult>(result);
mailMock.Verify(x => x.SendEmailAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}

Expand All @@ -271,7 +271,7 @@ public async Task Filter_ShouldNotSendEmail_WhenMailEnabled_AndEmailFormatInvali

IActionResult result = await messageController.Filter(mailMock.Object);

Assert.IsType<OkResult>(result);
Assert.IsType<BadRequestResult>(result);
mailMock.Verify(x => x.SendEmailAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
}
}

0 comments on commit 3fb1441

Please sign in to comment.