From 9e33f2d21c6739c4b8b292c73f46d2c23afa9ad4 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 9 Nov 2023 18:03:45 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=B8=8D=E8=A6=81=E3=81=AA=E4=BE=9D?= =?UTF-8?q?=E5=AD=98=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 3 -- .../api/note/NoteApControllerImplTest.kt | 42 ++++++++----------- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index fe039be1..aff08d05 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -163,9 +163,7 @@ dependencies { compileOnly("io.swagger.core.v3:swagger-annotations:2.2.6") implementation("io.swagger.core.v3:swagger-models:2.2.6") implementation("org.jetbrains.exposed:exposed-java-time:$exposed_version") - testImplementation("org.springframework.boot:spring-boot-test-autoconfigure") testImplementation("org.springframework.boot:spring-boot-starter-test") - testImplementation("org.springframework.security:spring-security-test") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.springframework.security:spring-security-oauth2-jose") @@ -193,7 +191,6 @@ dependencies { implementation("io.ktor:ktor-client-content-negotiation:$ktor_version") testImplementation("io.ktor:ktor-client-mock:$ktor_version") - testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") testImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0") testImplementation("org.mockito:mockito-inline:5.2.0") testImplementation("nl.jqno.equalsverifier:equalsverifier:3.15.3") diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt index 9537be64..c337e770 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/note/NoteApControllerImplTest.kt @@ -16,17 +16,10 @@ import org.mockito.Mock import org.mockito.junit.jupiter.MockitoExtension import org.mockito.kotlin.* import org.springframework.security.core.context.SecurityContextHolder -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.anonymous -import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication -import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity -import org.springframework.security.web.DefaultSecurityFilterChain -import org.springframework.security.web.FilterChainProxy import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken -import org.springframework.security.web.util.matcher.AnyRequestMatcher import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.get import org.springframework.test.web.servlet.setup.MockMvcBuilders -import org.springframework.test.web.servlet.setup.StandaloneMockMvcBuilder import java.net.URL @ExtendWith(MockitoExtension::class) @@ -44,21 +37,21 @@ class NoteApControllerImplTest { fun setUp() { mockMvc = MockMvcBuilders.standaloneSetup(noteApControllerImpl) - .apply( - springSecurity( - FilterChainProxy( - DefaultSecurityFilterChain( - AnyRequestMatcher.INSTANCE - ) - ) - ) - ) +// .apply( +// springSecurity( +// FilterChainProxy( +// DefaultSecurityFilterChain( +// AnyRequestMatcher.INSTANCE +// ) +// ) +// ) +// ) .build() } @Test fun `postAP 匿名で取得できる`() = runTest { - + SecurityContextHolder.clearContext() val note = Note( name = "Note", id = "https://example.com/users/hoge/posts/1234", @@ -74,7 +67,7 @@ class NoteApControllerImplTest { mockMvc .get("/users/hoge/posts/1234") { - with(anonymous()) +// with(anonymous()) } .asyncDispatch() .andExpect { status { isOk() } } @@ -83,11 +76,12 @@ class NoteApControllerImplTest { @Test fun `postAP 存在しない場合は404`() = runTest { + SecurityContextHolder.clearContext() whenever(noteApApiService.getNote(eq(123), isNull())).doReturn(null) mockMvc .get("/users/hoge/posts/123") { - with(anonymous()) +// with(anonymous()) } .asyncDispatch() .andExpect { status { isNotFound() } } @@ -117,11 +111,11 @@ class NoteApControllerImplTest { SecurityContextHolder.getContext().authentication = preAuthenticatedAuthenticationToken mockMvc.get("/users/hoge/posts/1234") { - with( - authentication( - preAuthenticatedAuthenticationToken - ) - ) +// with( +// authentication( +// preAuthenticatedAuthenticationToken +// ) +// ) }.asyncDispatch() .andExpect { status { isOk() } } .andExpect { content { json(objectMapper.writeValueAsString(note)) } }