Skip to content

Commit

Permalink
Fix for Nullreference exception when public api authenticate endpoint…
Browse files Browse the repository at this point in the history
… called with invalid username. (dotnet-architecture#482)
  • Loading branch information
onurbiyik authored Nov 14, 2020
1 parent c2fe05d commit 2502e01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/PublicApi/AuthEndpoints/Authenticate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public override async Task<ActionResult<AuthenticateResponse>> HandleAsync(Authe
response.IsNotAllowed = result.IsNotAllowed;
response.RequiresTwoFactor = result.RequiresTwoFactor;
response.Username = request.Username;
response.Token = await _tokenClaimsService.GetTokenAsync(request.Username);

if (result.Succeeded)
{
response.Token = await _tokenClaimsService.GetTokenAsync(request.Username);
}

return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public AuthenticateEndpoint(ApiTestFixture factory)
[Theory]
[InlineData("demouser@microsoft.com", AuthorizationConstants.DEFAULT_PASSWORD, true)]
[InlineData("demouser@microsoft.com", "badpassword", false)]
[InlineData("baduser@microsoft.com", "badpassword", false)]
public async Task ReturnsExpectedResultGivenCredentials(string testUsername, string testPassword, bool expectedResult)
{
var request = new AuthenticateRequest()
Expand All @@ -38,6 +39,6 @@ public async Task ReturnsExpectedResultGivenCredentials(string testUsername, str
var model = stringResponse.FromJson<AuthenticateResponse>();

Assert.Equal(expectedResult, model.Result);
}
}
}
}

0 comments on commit 2502e01

Please sign in to comment.