Skip to content

Commit

Permalink
refresh token을 검증하는 validateToken 메서드를 추가하라
Browse files Browse the repository at this point in the history
올바른 토큰인지 아닌지 검증하는 validateToken 메서드를 추가했습니다
  • Loading branch information
jihwooon committed Sep 18, 2023
1 parent ee972ee commit 20fdcae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/src/auth/token/application/token.issuer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('TokenIssuer class', () => {
let connect: Connection
let tokenIssuer: TokenIssuer
let memberRepository: MemberRepository
let jwtProvider: JwtProvider

const REFRESH_TOKEN =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXlsb2FkIjoxLCJpYXQiOjE2OTQ1MjI0NzUsImV4cCI6MTY5NTczMjA3NSwic3ViIjoiUkVGUkVTSCJ9.A2PfZdj91q6MIapXrvTB6bUd7blhqrrDY2yh0eYdGPY'
Expand All @@ -33,12 +34,14 @@ describe('TokenIssuer class', () => {

tokenIssuer = module.get<TokenIssuer>(TokenIssuer)
memberRepository = module.get<MemberRepository>(MemberRepository)
jwtProvider = module.get<JwtProvider>(JwtProvider)
})

describe('createAccessTokenByRefreshToken method', () => {
context('refreshToken이 주어지면', () => {
beforeEach(() => {
memberRepository.findMemberByRefreshToken = jest.fn().mockResolvedValue(MEMBER)
jwtProvider.validateToken = jest.fn().mockResolvedValue('[email protected]')
})
it('accessToken과 accessTokenExpireTime을 갱신해야 한다', async () => {
const member = await tokenIssuer.createAccessTokenByRefreshToken(REFRESH_TOKEN, NOW)
Expand All @@ -54,6 +57,7 @@ describe('TokenIssuer class', () => {
context('refreshToken이 찾을 수 없거나 올바르지 않으면', () => {
beforeEach(() => {
memberRepository.findMemberByRefreshToken = jest.fn().mockResolvedValue(undefined)
jwtProvider.validateToken = jest.fn().mockResolvedValue('[email protected]')
})
it('MemberNotFoundException를 던져야 한다', async () => {
expect(tokenIssuer.createAccessTokenByRefreshToken(REFRESH_TOKEN, NOW)).rejects.toThrow(
Expand All @@ -65,6 +69,7 @@ describe('TokenIssuer class', () => {
context('refreshToken의 유효기간이 만료 되면', () => {
beforeEach(() => {
memberRepository.findMemberByRefreshToken = jest.fn().mockResolvedValue(MEMBER)
jwtProvider.validateToken = jest.fn().mockResolvedValue('[email protected]')
})
it('TokenExpiredException를 던져야 한다', async () => {
expect(tokenIssuer.createAccessTokenByRefreshToken(REFRESH_TOKEN, EXPIRED_TIME)).rejects.toThrow(
Expand Down
1 change: 1 addition & 0 deletions server/src/auth/token/application/token.issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class TokenIssuer {
constructor(private readonly memberRepository: MemberRepository, private readonly jwtProvider: JwtProvider) {}

async createAccessTokenByRefreshToken(refreshToken: string, now: Date): Promise<AccessTokenDto> {
this.jwtProvider.validateToken(refreshToken)
const member = await this.memberRepository.findMemberByRefreshToken(refreshToken)

if (!member) {
Expand Down

0 comments on commit 20fdcae

Please sign in to comment.