From 8bf1fe06a8a8ca1de7f511d83c00457fa22c7179 Mon Sep 17 00:00:00 2001 From: usbharu Date: Fri, 14 Feb 2025 18:25:58 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hideout/hideout-activitypub/build.gradle.kts | 13 ++++- .../interface/api/APActorController.kt | 2 +- .../kotlin/activity/APActorControllerTest.kt | 49 +++++++++++++++++++ .../src/test/resources/application.yml | 14 ++++++ .../src/test/resources/sql/actors.sql | 35 +++++++++++++ 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 hideout/hideout-activitypub/src/test/kotlin/activity/APActorControllerTest.kt create mode 100644 hideout/hideout-activitypub/src/test/resources/application.yml create mode 100644 hideout/hideout-activitypub/src/test/resources/sql/actors.sql diff --git a/hideout/hideout-activitypub/build.gradle.kts b/hideout/hideout-activitypub/build.gradle.kts index 511d32b7..0e426117 100644 --- a/hideout/hideout-activitypub/build.gradle.kts +++ b/hideout/hideout-activitypub/build.gradle.kts @@ -32,7 +32,6 @@ repositories { } dependencies { - testImplementation(kotlin("test")) detektPlugins(libs.detekt.formatting) implementation(project(":hideout-core")) implementation("org.springframework.boot:spring-boot-starter-web") @@ -44,6 +43,14 @@ dependencies { implementation(libs.activity.streams.serialization) implementation(libs.jsonld) implementation(libs.coroutines.core) + implementation(libs.bundles.exposed) + testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.security:spring-security-test") + testImplementation(libs.bundles.spring.boot.oauth2) + testImplementation(libs.kotlin.junit) + testImplementation(libs.coroutines.test) + testImplementation(libs.h2db) + testImplementation(libs.flyway.core) } tasks.test { @@ -141,3 +148,7 @@ kover { } } + +springBoot{ + buildInfo { } +} \ No newline at end of file diff --git a/hideout/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/interface/api/APActorController.kt b/hideout/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/interface/api/APActorController.kt index 444f3a94..22619f32 100644 --- a/hideout/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/interface/api/APActorController.kt +++ b/hideout/hideout-activitypub/src/main/kotlin/dev/usbharu/hideout/activitypub/interface/api/APActorController.kt @@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.PathVariable class APActorController(private val getActorApplicationService: GetActorApplicationService) { @GetMapping( "/users/{username}", - consumes = ["application/activity+json"], +// consumes = ["application/activity+json"], produces = ["application/activity+json"] ) suspend fun user(@PathVariable username: String): ResponseEntity { diff --git a/hideout/hideout-activitypub/src/test/kotlin/activity/APActorControllerTest.kt b/hideout/hideout-activitypub/src/test/kotlin/activity/APActorControllerTest.kt new file mode 100644 index 00000000..6286033b --- /dev/null +++ b/hideout/hideout-activitypub/src/test/kotlin/activity/APActorControllerTest.kt @@ -0,0 +1,49 @@ +package activity + +import dev.usbharu.hideout.SpringApplication +import dev.usbharu.hideout.activitypub.`interface`.api.APActorController +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.MediaType +import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity +import org.springframework.test.context.jdbc.Sql +import org.springframework.test.web.servlet.MockMvc +import org.springframework.test.web.servlet.get +import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder +import org.springframework.test.web.servlet.setup.MockMvcBuilders +import org.springframework.transaction.annotation.Transactional +import org.springframework.web.context.WebApplicationContext + +@SpringBootTest(classes = [SpringApplication::class, APActorController::class]) +@AutoConfigureMockMvc +@Transactional +@Sql("/sql/actors.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS) +class APActorControllerTest { + + @Autowired + private lateinit var context: WebApplicationContext + + private lateinit var mockMvc: MockMvc + + @BeforeEach + fun setUp() { + mockMvc = MockMvcBuilders.webAppContextSetup(context) + .apply(springSecurity()) + .build() + } + + @Test + fun user() { + mockMvc + .get("/users/test") { + accept(MediaType("application", "activity+json")) + } + .asyncDispatch() + .andDo { print() } + .andExpect { status { isOk() } } + + } +} \ No newline at end of file diff --git a/hideout/hideout-activitypub/src/test/resources/application.yml b/hideout/hideout-activitypub/src/test/resources/application.yml new file mode 100644 index 00000000..c8d7673c --- /dev/null +++ b/hideout/hideout-activitypub/src/test/resources/application.yml @@ -0,0 +1,14 @@ +spring: + datasource: + url: "jdbc:h2:mem:test;MODE=POSTGRESQL;DB_CLOSE_DELAY=-1;CASE_INSENSITIVE_IDENTIFIERS=true;TRACE_LEVEL_FILE=4;" + driver-class-name: org.h2.Driver + flyway: + clean-disabled: false +hideout: + url: "https://example.com" + security: + jwt: + generate: true + key-id: a + private-key: "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC7VJTUt9Us8cKjMzEfYyjiWA4R4/M2bS1GB4t7NXp98C3SC6dVMvDuictGeurT8jNbvJZHtCSuYEvuNMoSfm76oqFvAp8Gy0iz5sxjZmSnXyCdPEovGhLa0VzMaQ8s+CLOyS56YyCFGeJZqgtzJ6GR3eqoYSW9b9UMvkBpZODSctWSNGj3P7jRFDO5VoTwCQAWbFnOjDfH5Ulgp2PKSQnSJP3AJLQNFNe7br1XbrhV//eO+t51mIpGSDCUv3E0DDFcWDTH9cXDTTlRZVEiR2BwpZOOkE/Z0/BVnhZYL71oZV34bKfWjQIt6V/isSMahdsAASACp4ZTGtwiVuNd9tybAgMBAAECggEBAKTmjaS6tkK8BlPXClTQ2vpz/N6uxDeS35mXpqasqskVlaAidgg/sWqpjXDbXr93otIMLlWsM+X0CqMDgSXKejLS2jx4GDjI1ZTXg++0AMJ8sJ74pWzVDOfmCEQ/7wXs3+cbnXhKriO8Z036q92Qc1+N87SI38nkGa0ABH9CN83Hm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BAQEFAAOCAQ8AMIIBCgKCAQEAu1SU1LfVLPHCozMxH2Mo4lgOEePzNm0tRgeLezV6ffAt0gunVTLw7onLRnrq0/IzW7yWR7QkrmBL7jTKEn5u+qKhbwKfBstIs+bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyehkd3qqGElvW/VDL5AaWTg0nLVkjRo9z+40RQzuVaE8AkAFmxZzow3x+VJYKdjykkJ0iT9wCS0DRTXu269V264Vf/3jvredZiKRkgwlL9xNAwxXFg0x/XFw005UWVRIkdgcKWTjpBP2dPwVZ4WWC+9aGVd+Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbcmwIDAQAB" diff --git a/hideout/hideout-activitypub/src/test/resources/sql/actors.sql b/hideout/hideout-activitypub/src/test/resources/sql/actors.sql new file mode 100644 index 00000000..cf62085d --- /dev/null +++ b/hideout/hideout-activitypub/src/test/resources/sql/actors.sql @@ -0,0 +1,35 @@ +insert into instance(id, name, description, url, icon_url, shared_inbox, software, version, is_blocked, is_muted, + moderation_note, created_at) +VALUES (1, 'instance', 'description', 'https://example.com', 'https://example.com', 'https://example.com', 'software', + 'version', false, false, 'note', current_timestamp) + , (2, 'instance', 'description', 'https://remote.example.com', 'https://example.com', 'https://remote.example.com', + 'software', + 'version', false, false, 'note', current_timestamp) + , (3, 'instance', 'description', 'https://remote2.example.com', 'https://example.com', + 'https://remote2.example.com', 'software', + 'version', false, false, 'note', current_timestamp); + +insert into actors(id, name, domain, screen_name, description, inbox, outbox, url, public_key, private_key, created_at, + key_id, following, followers, instance, locked, following_count, followers_count, posts_count, + last_post_at, last_update_at, suspend, move_to, icon, banner) +VALUES (1, 'test', 'example.com', 'test-actor', 'actor_description', 'https://example.com/test/inbox', + 'https://example.com/outbox', 'https://example.com/test', '---BEGIN PUBLIC KEY---', '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://example.com/test#main-key', 'https://example.com/test/following', + 'https://example.com/test/followers', 1, false, 1, 0, 0, null, current_timestamp, false, null, null, null), + (2, 'test', 'remote.example.com', 'test-actor', 'actor_description', 'https://remote.example.com/test/inbox', + 'https://remote.example.com/outbox', 'https://remote.example.com', '---BEGIN PUBLIC KEY---', + '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://remote.example.com/test#main-key', 'https://remote.example.com/test/following', + 'https://remote.example.com/test/followers', 2, false, 1, 0, 0, null, current_timestamp, false, null, null, + null), + (3, 'test', 'remote2.example.com', 'test-actor', 'actor_description', 'https://remote2.example.com/test/inbox', + 'https://remote2.example.com/test/outbox', 'https://remote2.example.com/test', '---BEGIN PUBLIC KEY---', + '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://remote2.example.com/test#main-key', 'https://remote2.example.com/test/following', + 'https://example.com/followers', 3, false, 1, 0, 0, null, current_timestamp, false, null, null, null), + (4, 'test2', 'remote2.example.com', 'test-actor', 'actor_description', 'https://example.com/inbox', + 'https://remote2.example.com/test2/outbox', 'https://remote2.example.com/test2', '---BEGIN PUBLIC KEY---', + '---BEGIN PRIVATE KEY---', + current_timestamp, 'https://remote2.example.com/test2#main-key', 'https://remote2.example.com/test2/following', + 'https://remote2.example.com/test2/followers', 3, false, 1, 0, 0, null, current_timestamp, false, null, null, + null); \ No newline at end of file