-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from 42-world/develop
🔥 Main Merge 🏃♀️🏃♂️🏃
- Loading branch information
Showing
45 changed files
with
1,008 additions
and
248 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: 'Auto Label' | ||
|
||
on: | ||
pull_request: | ||
types: [labeled, unlabeled, opened, synchronize, reopened] | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
auto-label: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: Yaminyam/auto-label-in-issue@1.1.0 |
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
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Response } from 'express'; | ||
import { mock, mockFn } from 'jest-mock-extended'; | ||
import { AuthController } from '../auth.controller'; | ||
import { AuthService } from '../auth.service'; | ||
import { GithubProfile } from '../types'; | ||
|
||
describe('AuthController', () => { | ||
const mockAuthService = mock<AuthService>({ | ||
login: mockFn().mockResolvedValue({ id: 1 }), | ||
getJwt: mockFn().mockReturnValue('jwt'), | ||
getCookieOption: mockFn().mockReturnValue({ cookie: 'test' }), | ||
}); | ||
const mockConfigService = mock<ConfigService>({ | ||
get: mockFn().mockReturnValue('access-token-key'), | ||
}); | ||
const authController = new AuthController(mockAuthService, mockConfigService); | ||
|
||
beforeEach(() => { | ||
jest.clearAllTimers(); | ||
}); | ||
|
||
describe('githubLogin', () => { | ||
test('정상 호출', async () => { | ||
const actual = () => authController.githubLogin(); | ||
|
||
expect(actual).not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('githubCallback', () => { | ||
test('로그인하면 쿠키를 세팅한다', async () => { | ||
const githubProfile: GithubProfile = { id: '1', username: 'test' }; | ||
const mockResponse = mock<Response>({ | ||
cookie: mockFn().mockReturnThis(), | ||
}); | ||
|
||
await authController.githubCallback(githubProfile, mockResponse); | ||
|
||
expect(mockResponse.cookie).toBeCalledTimes(1); | ||
expect(mockResponse.cookie).toBeCalledWith('access-token-key', 'jwt', { cookie: 'test' }); | ||
}); | ||
}); | ||
|
||
describe('signout', () => { | ||
test('로그아웃하면 쿠키를 비운다', async () => { | ||
const mockResponse = mock<Response>({ | ||
clearCookie: mockFn().mockReturnThis(), | ||
}); | ||
|
||
authController.signout(mockResponse); | ||
|
||
expect(mockResponse.clearCookie).toBeCalledTimes(1); | ||
expect(mockResponse.clearCookie).toBeCalledWith('access-token-key', { cookie: 'test' }); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { UserRole } from '@app/entity/user/interfaces/userrole.interface'; | ||
import { User } from '@app/entity/user/user.entity'; | ||
import { ExecutionContextHost } from '@nestjs/core/helpers/execution-context-host'; | ||
import 'reflect-metadata'; | ||
import { Auth, AuthUser, ReqGithubProfile } from '../auth.decorator'; | ||
import { REQUIRE_ROLES } from '../constant'; | ||
import { getParamDecorator } from './getParamDecoratorFactory'; | ||
|
||
describe('AuthDecorator', () => { | ||
describe('Auth', () => { | ||
test('Auth를 사용하지 않으면 권한이 설정이 되지 않는다.', async () => { | ||
class TestClass { | ||
testMethod() {} | ||
} | ||
|
||
const result = Reflect.getMetadata(REQUIRE_ROLES, new TestClass().testMethod); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
test(`Auth('allow', UserRole.GUEST, UserRole.ADMIN) 는 GUEST, ADMIN 둘다 허락한다`, async () => { | ||
class TestClass { | ||
@Auth('allow', UserRole.GUEST, UserRole.ADMIN) | ||
testMethod() {} | ||
} | ||
|
||
const result = Reflect.getMetadata(REQUIRE_ROLES, new TestClass().testMethod); | ||
|
||
expect(result).toStrictEqual(['allow', UserRole.GUEST, UserRole.ADMIN]); | ||
}); | ||
|
||
test(`Auth('allow') 는 아무권한도 허락하지 않는다.`, async () => { | ||
class TestClass { | ||
@Auth('allow') | ||
testMethod() {} | ||
} | ||
|
||
const result = Reflect.getMetadata(REQUIRE_ROLES, new TestClass().testMethod); | ||
|
||
expect(result).toStrictEqual(['allow']); | ||
}); | ||
|
||
test(`Auth('deny', UserRole.GUEST, UserRole.ADMIN) 는 GUEST, ADMIN 둘다 허락한다`, async () => { | ||
class TestClass { | ||
@Auth('deny', UserRole.GUEST, UserRole.ADMIN) | ||
testMethod() {} | ||
} | ||
|
||
const result = Reflect.getMetadata(REQUIRE_ROLES, new TestClass().testMethod); | ||
|
||
expect(result).toStrictEqual(['deny', UserRole.GUEST, UserRole.ADMIN]); | ||
}); | ||
|
||
test(`Auth('deny') 는 모든 권한을 허락한다.`, async () => { | ||
class TestClass { | ||
@Auth('deny') | ||
testMethod() {} | ||
} | ||
|
||
const result = Reflect.getMetadata(REQUIRE_ROLES, new TestClass().testMethod); | ||
|
||
expect(result).toStrictEqual(['deny']); | ||
}); | ||
|
||
test(`Auth('public') 은 모든 권한을 허락한다.`, async () => { | ||
class TestClass { | ||
@Auth('public') | ||
testMethod() {} | ||
} | ||
|
||
const result = Reflect.getMetadata(REQUIRE_ROLES, new TestClass().testMethod); | ||
|
||
expect(result).toStrictEqual(['deny']); | ||
}); | ||
|
||
test(`Auth() 은 GUEST를 제외한 권한을 허락한다.`, async () => { | ||
class TestClass { | ||
@Auth() | ||
testMethod() {} | ||
} | ||
|
||
const result = Reflect.getMetadata(REQUIRE_ROLES, new TestClass().testMethod); | ||
|
||
expect(result).toStrictEqual(['deny', UserRole.GUEST]); | ||
}); | ||
}); | ||
|
||
describe('AuthUser', () => { | ||
test('Request 에 담긴 user를 가져온다', async () => { | ||
const user = new User(); | ||
const context = new ExecutionContextHost([{ user }, {}]); | ||
|
||
const result = getParamDecorator(AuthUser)(null, context); | ||
|
||
expect(result).toStrictEqual(user); | ||
}); | ||
|
||
test('Request 에 담긴 user의 id를 가져온다', async () => { | ||
const user = new User(); | ||
user.id = 1; | ||
const context = new ExecutionContextHost([{ user }, {}]); | ||
|
||
const result = getParamDecorator(AuthUser)('id', context); | ||
|
||
expect(result).toStrictEqual(user.id); | ||
}); | ||
|
||
test('Request 에 담긴 user의 id가 없는경우', async () => { | ||
const user = new User(); | ||
const context = new ExecutionContextHost([{ user }, {}]); | ||
|
||
const result = getParamDecorator(AuthUser)('id', context); | ||
|
||
expect(result).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('ReqGithubProfile', () => { | ||
test('Request 에 담긴 githubprofile를 가져온다', async () => { | ||
const user = { id: 1, username: 'test' }; | ||
const context = new ExecutionContextHost([{ user }, {}]); | ||
|
||
const result = getParamDecorator(ReqGithubProfile)(null, context); | ||
|
||
expect(result).toStrictEqual(user); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { AuthModule } from '../auth.module'; | ||
|
||
describe('AuthModule', () => { | ||
test('모듈이 잘 컴파일된다.', async () => { | ||
// TODO: Test.createTestingModule 로 complie 할것 | ||
// const module = await Test.createTestingModule({ | ||
// imports: [AuthModule], | ||
// }).compile(); | ||
const module = new AuthModule(); | ||
|
||
expect(module).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.