-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix bug where tokens generated from LexAuthService would cont…
…ain 2 audiences and then be unable to deserialize into a LexAuthUser" This reverts commit 319af51.
- Loading branch information
Showing
2 changed files
with
5 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,27 +7,23 @@ | |
using LexCore.Entities; | ||
using Microsoft.AspNetCore.Authentication; | ||
using Microsoft.AspNetCore.Authentication.JwtBearer; | ||
using Microsoft.Extensions.Options; | ||
using Microsoft.IdentityModel.Tokens; | ||
using Shouldly; | ||
|
||
namespace Testing.LexCore; | ||
|
||
public class LexAuthUserTests | ||
{ | ||
private readonly LexAuthService _lexAuthService = new LexAuthService( | ||
new OptionsWrapper<JwtOptions>(JwtOptions.TestingOptions), | ||
null, | ||
null, | ||
null); | ||
|
||
private readonly LexAuthUser _user = new() | ||
{ | ||
Id = Guid.NewGuid(), | ||
Email = "[email protected]", | ||
Role = UserRole.user, | ||
Name = "test", | ||
Projects = new[] { new AuthUserProject("test-flex", ProjectRole.Manager, Guid.NewGuid()) } | ||
Projects = new[] | ||
{ | ||
new AuthUserProject("test-flex", ProjectRole.Manager, Guid.NewGuid()) | ||
} | ||
}; | ||
|
||
[Fact] | ||
|
@@ -86,15 +82,4 @@ public void CanRoundTripClaimsWhenUsingSecurityTokenDescriptor() | |
var newUser = JsonSerializer.Deserialize<LexAuthUser>(Base64UrlEncoder.Decode(token.RawPayload)); | ||
_user.ShouldBeEquivalentTo(newUser); | ||
} | ||
|
||
[Fact] | ||
public void CanRoundTripJwtFromUserThroughLexAuthService() | ||
{ | ||
var (jwt, _) = _lexAuthService.GenerateJwt(_user); | ||
var tokenHandler = new JwtSecurityTokenHandler(); | ||
var outputJwt = tokenHandler.ReadJwtToken(jwt); | ||
var principal = new ClaimsPrincipal(new ClaimsIdentity(outputJwt.Claims, "Testing")); | ||
var newUser = LexAuthUser.FromClaimsPrincipal(principal); | ||
_user.ShouldBeEquivalentTo(newUser); | ||
} | ||
} |