|
| 1 | +package org.gitanimals.core.auth |
| 2 | + |
| 3 | +import com.ninjasquad.springmockk.MockkBean |
| 4 | +import io.kotest.assertions.throwables.shouldThrow |
| 5 | +import io.kotest.core.annotation.DisplayName |
| 6 | +import io.kotest.core.spec.style.DescribeSpec |
| 7 | +import io.kotest.matchers.shouldBe |
| 8 | +import io.mockk.every |
| 9 | +import org.springframework.boot.test.context.SpringBootTest |
| 10 | +import org.springframework.boot.test.context.TestComponent |
| 11 | +import org.springframework.context.annotation.EnableAspectJAutoProxy |
| 12 | + |
| 13 | +@SpringBootTest( |
| 14 | + classes = [ |
| 15 | + RequiredUserEntryPointAspect::class, |
| 16 | + UserEntryPointValidationExtension::class, |
| 17 | + UserEntryPointValidationExtension.UserEntryPointValidationExtensionBeanInjector::class, |
| 18 | + TestService::class |
| 19 | + ] |
| 20 | +) |
| 21 | +@EnableAspectJAutoProxy(proxyTargetClass = true) |
| 22 | +@DisplayName("RequiredUserEntryPointAspect 클래스의") |
| 23 | +internal class RequiredUserEntryPointAspectTest( |
| 24 | + @MockkBean(relaxed = true) private val internalAuth: InternalAuth, |
| 25 | + private val testService: TestService, |
| 26 | +) : DescribeSpec({ |
| 27 | + |
| 28 | + |
| 29 | + describe("validate 메소드는") { |
| 30 | + |
| 31 | + context("expected가 GITHUB로 설정되어있을때, GITHUB유저가 인입되면") { |
| 32 | + it("메소드 호출을 성공한다") { |
| 33 | + every { internalAuth.getUserEntryPoint(any()) } returns "GITHUB" |
| 34 | + |
| 35 | + testService.githubOnly() shouldBe "github-ok" |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + context("expected가 GITHUB로 설정되어 있을때, APPLE유저가 인입되면") { |
| 40 | + it("IllegalArgumentException 을 던진다") { |
| 41 | + every { internalAuth.getUserEntryPoint(any()) } returns "APPLE" |
| 42 | + |
| 43 | + shouldThrow<IllegalArgumentException> { |
| 44 | + testService.githubOnly() |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + context("expected가 ANY로 설정되어 있을때, 어떤 유저가 인입되더라도 성공한다") { |
| 50 | + it("always invokes the method") { |
| 51 | + every { internalAuth.getUserEntryPoint(any()) } returns "GITHUB" |
| 52 | + testService.anyEntry() shouldBe "any-ok" |
| 53 | + |
| 54 | + every { internalAuth.getUserEntryPoint(any()) } returns "APPLE" |
| 55 | + testService.anyEntry() shouldBe "any-ok" |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | +}) |
| 60 | + |
| 61 | +@TestComponent |
| 62 | +class TestService { |
| 63 | + |
| 64 | + @RequiredUserEntryPoints(expected = [UserEntryPoint.GITHUB]) |
| 65 | + fun githubOnly(): String { |
| 66 | + return "github-ok" |
| 67 | + } |
| 68 | + |
| 69 | + @RequiredUserEntryPoints(expected = [UserEntryPoint.ANY]) |
| 70 | + fun anyEntry(): String { |
| 71 | + return "any-ok" |
| 72 | + } |
| 73 | +} |
0 commit comments