Skip to content

Commit

Permalink
Change response for unknown user case
Browse files Browse the repository at this point in the history
  • Loading branch information
zysim committed Aug 16, 2023
1 parent 839e80f commit 526eb18
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task ResendConfirmation_Unauthorised()
}

[Test]
public async Task ResendConfirmation_NotFound_ShouldGet500()
public async Task ResendConfirmation_NotFound_ShouldGet401()
{
string token = _authService.GenerateJSONWebToken(new()
{
Expand All @@ -55,7 +55,7 @@ public async Task ResendConfirmation_NotFound_ShouldGet500()
Client.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse($"Bearer {token}");
HttpResponseMessage res = await Client.PostAsync(RESEND_CONFIRMATION_URI, null);

res.Should().HaveStatusCode(HttpStatusCode.InternalServerError);
res.Should().HaveStatusCode(HttpStatusCode.Unauthorized);
}

[Test]
Expand Down
17 changes: 4 additions & 13 deletions LeaderboardBackend/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,14 @@ public async Task<ActionResult<LoginResponse>> Login([FromBody] LoginRequest req
/// The request doesn't contain a valid session token.
/// </response>
/// <response code="409">
/// A `User` with the specified username or email already exists.<br/><br/>
/// Validation error codes by property:
/// - **Username**:
/// - **UsernameTaken**: the username is already in use
/// - **Email**:
/// - **EmailAlreadyUsed**: the email is already in use
/// </response>
/// <response code="500">
/// Internal server error.
/// The `User`'s account has already been confirmed.
/// </response>
[HttpPost("confirm")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
[ProducesResponseType(StatusCodes.Status429TooManyRequests)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> ResendConfirmation(
[FromServices] IAuthService authService,
[FromServices] IAccountConfirmationService confirmationService,
Expand All @@ -165,10 +156,10 @@ [FromServices] IEmailSender emailSender
return Ok();
}

return errors.Match(
return errors.Match<ActionResult>(
badCredentials => Unauthorized(),
// Shouldn't be possible; throw 500
notFound => StatusCode(StatusCodes.Status500InternalServerError),
// Shouldn't be possible; throw 401
notFound => Unauthorized(),
badRole => Conflict()
);
}
Expand Down
5 changes: 1 addition & 4 deletions LeaderboardBackend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
}
},
"409": {
"description": "A `User` with the specified username or email already exists.<br /><br />\r\nValidation error codes by property:\r\n- **Username**:\r\n - **UsernameTaken**: the username is already in use\r\n- **Email**:\r\n - **EmailAlreadyUsed**: the email is already in use",
"description": "The `User`'s account has already been confirmed.",
"content": {
"application/json": {
"schema": {
Expand Down Expand Up @@ -236,9 +236,6 @@
}
}
}
},
"500": {
"description": "Internal server error."
}
}
}
Expand Down

0 comments on commit 526eb18

Please sign in to comment.