From fd0a90ee51de9a8f27cdb6f1ba7c3048103a07b6 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 12 May 2024 16:44:31 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20Exposed=E3=81=AE=E5=A4=89=E6=9B=B4?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/activitypub/domain/model/Block.kt | 59 ------------ .../model/objects/ObjectDeserializer.kt | 2 +- .../activity/block/APSendBlockService.kt | 53 ----------- .../block/BlockActivityPubProcessor.kt | 51 ---------- .../activity/undo/APSendUndoService.kt | 1 - .../activity/undo/APSendUndoServiceImpl.kt | 19 ---- .../service/activity/undo/APUndoProcessor.kt | 15 --- .../relationship/RelationshipServiceImpl.kt | 16 +--- .../activitypub/domain/model/BlockTest.kt | 94 ------------------- .../RelationshipServiceImplTest.kt | 16 ---- 10 files changed, 2 insertions(+), 324 deletions(-) delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/APSendBlockService.kt delete mode 100644 hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/BlockActivityPubProcessor.kt delete mode 100644 hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/BlockTest.kt diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt deleted file mode 100644 index 5a3c12a9..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/Block.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.activitypub.domain.model - -import com.fasterxml.jackson.annotation.JsonProperty -import dev.usbharu.hideout.activitypub.domain.model.objects.Object - -open class Block( - override val actor: String, - override val id: String, - @JsonProperty("object") val apObject: String -) : - Object(listOf("Block")), HasId, HasActor { - - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - if (!super.equals(other)) return false - - other as Block - - if (actor != other.actor) return false - if (id != other.id) return false - if (apObject != other.apObject) return false - - return true - } - - override fun hashCode(): Int { - var result = super.hashCode() - result = 31 * result + actor.hashCode() - result = 31 * result + id.hashCode() - result = 31 * result + apObject.hashCode() - return result - } - - override fun toString(): String { - return "Block(" + - "actor='$actor', " + - "id='$id', " + - "apObject='$apObject'" + - ")" + - " ${super.toString()}" - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt index 09e3063d..1a554745 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/domain/model/objects/ObjectDeserializer.kt @@ -60,7 +60,7 @@ class ObjectDeserializer : JsonDeserializer() { ExtendedActivityVocabulary.Add -> null ExtendedActivityVocabulary.Announce -> p.codec.treeToValue(treeNode, Announce::class.java) ExtendedActivityVocabulary.Arrive -> null - ExtendedActivityVocabulary.Block -> p.codec.treeToValue(treeNode, Block::class.java) + ExtendedActivityVocabulary.Block -> null ExtendedActivityVocabulary.Create -> p.codec.treeToValue(treeNode, Create::class.java) ExtendedActivityVocabulary.Delete -> p.codec.treeToValue(treeNode, Delete::class.java) ExtendedActivityVocabulary.Dislike -> null diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/APSendBlockService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/APSendBlockService.kt deleted file mode 100644 index fb69f5dd..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/APSendBlockService.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.activitypub.service.activity.block - -import dev.usbharu.hideout.application.config.ApplicationConfig -import dev.usbharu.hideout.core.domain.model.actor.Actor -import dev.usbharu.owl.producer.api.OwlProducer -import org.springframework.stereotype.Service - -interface APSendBlockService { - suspend fun sendBlock(actor: Actor, target: Actor) -} - -@Service -class ApSendBlockServiceImpl( - private val applicationConfig: ApplicationConfig, - private val owlProducer: OwlProducer, -) : APSendBlockService { - override suspend fun sendBlock(actor: Actor, target: Actor) { -// val blockJobParam = DeliverBlockJobParam( -// actor.id, -// Block( -// actor.url, -// "${applicationConfig.url}/block/${actor.id}/${target.id}", -// target.url -// ), -// Reject( -// actor.url, -// "${applicationConfig.url}/reject/${actor.id}/${target.id}", -// Follow( -// apObject = actor.url, -// actor = target.url -// ) -// ), -// target.inbox -// ) -// owlProducer.publishTask(blockJobParam) - } -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/BlockActivityPubProcessor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/BlockActivityPubProcessor.kt deleted file mode 100644 index 5a5ac1d4..00000000 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/block/BlockActivityPubProcessor.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.activitypub.service.activity.block - -import dev.usbharu.hideout.activitypub.domain.model.Block -import dev.usbharu.hideout.activitypub.service.common.AbstractActivityPubProcessor -import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext -import dev.usbharu.hideout.activitypub.service.common.ActivityType -import dev.usbharu.hideout.application.external.Transaction -import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException -import dev.usbharu.hideout.core.domain.model.actor.ActorRepository -import dev.usbharu.hideout.core.service.relationship.RelationshipService -import org.springframework.stereotype.Service - -/** - * ブロックアクティビティを処理します - */ -@Service -class BlockActivityPubProcessor( - private val relationshipService: RelationshipService, - private val actorRepository: ActorRepository, - transaction: Transaction -) : - AbstractActivityPubProcessor(transaction) { - override suspend fun internalProcess(activity: ActivityPubProcessContext) { - val user = actorRepository.findByUrl(activity.activity.actor) - ?: throw UserNotFoundException.withUrl(activity.activity.actor) - val target = actorRepository.findByUrl(activity.activity.apObject) ?: throw UserNotFoundException.withUrl( - activity.activity.apObject - ) - relationshipService.block(user.id, target.id) - } - - override fun isSupported(activityType: ActivityType): Boolean = activityType == ActivityType.Block - - override fun type(): Class = Block::class.java -} diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoService.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoService.kt index 330a0e1b..80d4828b 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoService.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoService.kt @@ -20,5 +20,4 @@ import dev.usbharu.hideout.core.domain.model.actor.Actor interface APSendUndoService { suspend fun sendUndoFollow(actor: Actor, target: Actor) - suspend fun sendUndoBlock(actor: Actor, target: Actor) } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt index 1022ebd0..576e9463 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APSendUndoServiceImpl.kt @@ -16,7 +16,6 @@ package dev.usbharu.hideout.activitypub.service.activity.undo -import dev.usbharu.hideout.activitypub.domain.model.Block import dev.usbharu.hideout.activitypub.domain.model.Follow import dev.usbharu.hideout.activitypub.domain.model.Undo import dev.usbharu.hideout.application.config.ApplicationConfig @@ -49,22 +48,4 @@ class APSendUndoServiceImpl( owlProducer.publishTask(deliverUndoTask) } - override suspend fun sendUndoBlock(actor: Actor, target: Actor) { - val deliverUndoTask = DeliverUndoTask( - Undo( - actor = actor.url, - id = "${applicationConfig.url}/undo/block/${actor.id}/${target.url}", - apObject = Block( - apObject = actor.url, - actor = target.url, - id = "${applicationConfig.url}/block/${actor.id}/${target.id}" - ), - published = Instant.now().toString() - ), - target.inbox, - actor.id - ) - - owlProducer.publishTask(deliverUndoTask) - } } diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt index 805d8211..bd80e6f9 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/activitypub/service/activity/undo/APUndoProcessor.kt @@ -56,11 +56,6 @@ class APUndoProcessor( return } - "Block" -> { - block(undo) - return - } - "Accept" -> { accept(undo) return @@ -112,16 +107,6 @@ class APUndoProcessor( return } - private suspend fun block(undo: Undo) { - val block = undo.apObject as Block - - val blocker = apUserService.fetchPersonWithEntity(undo.actor, block.apObject).second - val target = actorRepository.findByUrl(block.apObject) ?: throw UserNotFoundException.withUrl(block.apObject) - - relationshipService.unblock(blocker.id, target.id) - return - } - private suspend fun follow(undo: Undo) { val follow = undo.apObject as Follow diff --git a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt index 24b24aa1..057a5224 100644 --- a/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt +++ b/hideout-core/src/main/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImpl.kt @@ -17,7 +17,6 @@ package dev.usbharu.hideout.core.service.relationship import dev.usbharu.hideout.activitypub.service.activity.accept.ApSendAcceptService -import dev.usbharu.hideout.activitypub.service.activity.block.APSendBlockService import dev.usbharu.hideout.activitypub.service.activity.follow.APSendFollowService import dev.usbharu.hideout.activitypub.service.activity.reject.ApSendRejectService import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService @@ -39,12 +38,11 @@ class RelationshipServiceImpl( private val applicationConfig: ApplicationConfig, private val relationshipRepository: RelationshipRepository, private val apSendFollowService: APSendFollowService, - private val apSendBlockService: APSendBlockService, private val apSendAcceptService: ApSendAcceptService, private val apSendRejectService: ApSendRejectService, private val apSendUndoService: APSendUndoService, private val actorRepository: ActorRepository, - private val notificationService: NotificationService + private val notificationService: NotificationService, ) : RelationshipService { override suspend fun followRequest(actorId: Long, targetId: Long) { logger.info("START Follow Request userId: {} targetId: {}", actorId, targetId) @@ -145,12 +143,6 @@ class RelationshipServiceImpl( if (blockedInverseRelationship != null) { relationshipRepository.save(blockedInverseRelationship) } - - val remoteUser = isRemoteUser(targetId) - - if (remoteUser != null) { - apSendBlockService.sendBlock(user, remoteUser) - } } override suspend fun acceptFollowRequest(actorId: Long, targetId: Long, force: Boolean) { @@ -298,12 +290,6 @@ class RelationshipServiceImpl( val copy = relationship.copy(blocking = false) relationshipRepository.save(copy) - - val remoteUser = isRemoteUser(targetId) - if (remoteUser != null) { - val user = actorRepository.findById(actorId) ?: throw UserNotFoundException.withId(actorId) - apSendUndoService.sendUndoBlock(user, remoteUser) - } } override suspend fun mute(actorId: Long, targetId: Long) { diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/BlockTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/BlockTest.kt deleted file mode 100644 index 33908843..00000000 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/activitypub/domain/model/BlockTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (C) 2024 usbharu - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package dev.usbharu.hideout.activitypub.domain.model - -import com.fasterxml.jackson.module.kotlin.readValue -import dev.usbharu.hideout.application.config.ActivityPubConfig -import org.assertj.core.api.Assertions.assertThat -import org.intellij.lang.annotations.Language -import org.junit.jupiter.api.Test -import org.springframework.boot.test.json.BasicJsonTester - -class BlockTest { - @Test - fun blockDeserializeTest() { - @Language("JSON") val json = """{ - "@context" : [ "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", { - "manuallyApprovesFollowers" : "as:manuallyApprovesFollowers", - "sensitive" : "as:sensitive", - "Hashtag" : "as:Hashtag", - "quoteUrl" : "as:quoteUrl", - "toot" : "http://joinmastodon.org/ns#", - "Emoji" : "toot:Emoji", - "featured" : "toot:featured", - "discoverable" : "toot:discoverable", - "schema" : "http://schema.org#", - "PropertyValue" : "schema:PropertyValue", - "value" : "schema:value", - "misskey" : "https://misskey-hub.net/ns#", - "_misskey_content" : "misskey:_misskey_content", - "_misskey_quote" : "misskey:_misskey_quote", - "_misskey_reaction" : "misskey:_misskey_reaction", - "_misskey_votes" : "misskey:_misskey_votes", - "_misskey_summary" : "misskey:_misskey_summary", - "isCat" : "misskey:isCat", - "vcard" : "http://www.w3.org/2006/vcard/ns#" - } ], - "type" : "Block", - "id" : "https://misskey.usbharu.dev/blocks/9myf6e40vm", - "actor" : "https://misskey.usbharu.dev/users/97ws8y3rj6", - "object" : "https://test-hideout.usbharu.dev/users/test-user2" -} -""" - - val objectMapper = ActivityPubConfig().objectMapper() - - val block = objectMapper.readValue(json) - - val expected = Block( - "https://misskey.usbharu.dev/users/97ws8y3rj6", - "https://misskey.usbharu.dev/blocks/9myf6e40vm", - "https://test-hideout.usbharu.dev/users/test-user2" - ).apply { context = listOf("https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1") } - assertThat(block).isEqualTo(expected) - } - - @Test - fun blockSerializeTest() { - val basicJsonTester = BasicJsonTester(javaClass) - - val block = Block( - "https://misskey.usbharu.dev/users/97ws8y3rj6", - "https://misskey.usbharu.dev/blocks/9myf6e40vm", - "https://test-hideout.usbharu.dev/users/test-user2" - ).apply { context = listOf("https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1") } - - val objectMapper = ActivityPubConfig().objectMapper() - - val writeValueAsString = objectMapper.writeValueAsString(block) - - val from = basicJsonTester.from(writeValueAsString) - assertThat(from).extractingJsonPathStringValue("$.actor") - .isEqualTo("https://misskey.usbharu.dev/users/97ws8y3rj6") - assertThat(from).extractingJsonPathStringValue("$.id") - .isEqualTo("https://misskey.usbharu.dev/blocks/9myf6e40vm") - assertThat(from).extractingJsonPathStringValue("$.object") - .isEqualTo("https://test-hideout.usbharu.dev/users/test-user2") - assertThat(from).extractingJsonPathStringValue("$.type").isEqualTo("Block") - - } -} diff --git a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt index de976be0..4af69e07 100644 --- a/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt +++ b/hideout-core/src/test/kotlin/dev/usbharu/hideout/core/service/relationship/RelationshipServiceImplTest.kt @@ -17,7 +17,6 @@ package dev.usbharu.hideout.core.service.relationship import dev.usbharu.hideout.activitypub.service.activity.accept.ApSendAcceptService -import dev.usbharu.hideout.activitypub.service.activity.block.APSendBlockService import dev.usbharu.hideout.activitypub.service.activity.follow.APSendFollowService import dev.usbharu.hideout.activitypub.service.activity.reject.ApSendRejectService import dev.usbharu.hideout.activitypub.service.activity.undo.APSendUndoService @@ -55,9 +54,6 @@ class RelationshipServiceImplTest { @Mock private lateinit var apSendFollowService: APSendFollowService - @Mock - private lateinit var apSendBlockService: APSendBlockService - @Mock private lateinit var apSendAcceptService: ApSendAcceptService @@ -272,8 +268,6 @@ class RelationshipServiceImplTest { ) ) ) - - verify(apSendBlockService, times(1)).sendBlock(eq(localUser), eq(remoteUser)) } @Test @@ -657,7 +651,6 @@ class RelationshipServiceImplTest { @Test fun `unblock ローカルユーザーの場合永続化される`() = runTest { - whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com")) whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( Relationship( actorId = 1234, @@ -685,17 +678,10 @@ class RelationshipServiceImplTest { ) ) ) - - verify(apSendUndoService, never()).sendUndoBlock(any(), any()) } @Test fun `unblock リモートユーザーの場合永続化されて配送される`() = runTest { - val localUser = UserBuilder.localUserOf(domain = "example.com") - whenever(actorRepository.findById(eq(1234))).doReturn(localUser) - - val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com") - whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser) whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn( Relationship( @@ -724,8 +710,6 @@ class RelationshipServiceImplTest { ) ) ) - - verify(apSendUndoService, times(1)).sendUndoBlock(eq(localUser), eq(remoteUser)) } @Test