초기커밋
This commit is contained in:
45
BrokerApiTest/Jwt/JwtBasicTests.cs
Normal file
45
BrokerApiTest/Jwt/JwtBasicTests.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
|
||||
//=============================================================================================
|
||||
// Jwt 토큰 생성 및 파싱 기본 라이브러리 사용 테스트
|
||||
//=============================================================================================
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
using BrokerCore.Common;
|
||||
using BrokerCore.Services;
|
||||
|
||||
namespace BrokerTest.Jwt;
|
||||
|
||||
public class JwtBasicTests
|
||||
{
|
||||
private readonly ITestOutputHelper m_test_output_helper;
|
||||
|
||||
public JwtBasicTests(ITestOutputHelper testOutputHelper)
|
||||
{
|
||||
m_test_output_helper = testOutputHelper;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void jwtServiceTest()
|
||||
{
|
||||
var jwt_option = new JwtOption
|
||||
{
|
||||
Secret = "zgoRtipbFcgQp0VGP8VZW8QhW4ll1swfvASqwr78",
|
||||
TokenValidityInMinutes = 1,
|
||||
};
|
||||
var jwt_service = new JwtGenerator(jwt_option);
|
||||
var token = jwt_service.generateAccessToken("new_earth", "caliverse");
|
||||
m_test_output_helper.WriteLine(token);
|
||||
Assert.NotNull(token);
|
||||
|
||||
var jwt_parser = new JwtParser(jwt_option);
|
||||
var token_parsed = jwt_parser.parseToken(token);
|
||||
Assert.NotNull(token_parsed);
|
||||
var sid = token_parsed.FindFirstValue(JwtRegisteredClaimNames.Sid);
|
||||
Assert.NotNull(sid);
|
||||
var typ = token_parsed.FindFirstValue(JwtRegisteredClaimNames.Typ);
|
||||
Assert.NotNull(typ);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user