From 7e51cd7190c1f39ee2754b041bad31d4e090c5d6 Mon Sep 17 00:00:00 2001 From: Naoki Kosaka Date: Thu, 2 Jan 2020 02:02:16 +0900 Subject: [PATCH] BlockService should block any other type of Actor. --- handle.go | 2 +- handle_test.go | 14 ++++++++++++++ misc/application.json | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 misc/application.json diff --git a/handle.go b/handle.go index b894420..2a2558e 100644 --- a/handle.go +++ b/handle.go @@ -162,7 +162,7 @@ func suitableRelay(activity *activitypub.Activity, actor *activitypub.Actor) boo if contains(relayState.LimitedDomains, domain.Host) { return false } - if relayState.RelayConfig.BlockService && actor.Type == "Service" { + if relayState.RelayConfig.BlockService && actor.Type != "Person" { return false } return true diff --git a/handle_test.go b/handle_test.go index e7aac9b..b34164f 100644 --- a/handle_test.go +++ b/handle_test.go @@ -242,6 +242,12 @@ func mockActor(req string) activitypub.Actor { var actor activitypub.Actor json.Unmarshal(body, &actor) return actor + case "Application": + file, _ := os.Open("./misc/application.json") + body, _ := ioutil.ReadAll(file) + var actor activitypub.Actor + json.Unmarshal(body, &actor) + return actor default: panic("No assined request.") } @@ -251,6 +257,7 @@ func TestSuitableRelayNoBlockService(t *testing.T) { activity := mockActivity("Create") personActor := mockActor("Person") serviceActor := mockActor("Service") + applicationActor := mockActor("Application") relayState.SetConfig(BlockService, false) @@ -260,12 +267,16 @@ func TestSuitableRelayNoBlockService(t *testing.T) { if suitableRelay(&activity, &serviceActor) != true { t.Fatalf("Failed - Service status not relay") } + if suitableRelay(&activity, &applicationActor) != true { + t.Fatalf("Failed - Service status not relay") + } } func TestSuitableRelayBlockService(t *testing.T) { activity := mockActivity("Create") personActor := mockActor("Person") serviceActor := mockActor("Service") + applicationActor := mockActor("Application") relayState.SetConfig(BlockService, true) @@ -275,6 +286,9 @@ func TestSuitableRelayBlockService(t *testing.T) { if suitableRelay(&activity, &serviceActor) != false { t.Fatalf("Failed - Service status may relay when blocking mode") } + if suitableRelay(&activity, &applicationActor) != false { + t.Fatalf("Failed - Application status may relay when blocking mode") + } relayState.SetConfig(BlockService, false) } diff --git a/misc/application.json b/misc/application.json new file mode 100644 index 0000000..f8b43db --- /dev/null +++ b/misc/application.json @@ -0,0 +1 @@ +{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"manuallyApprovesFollowers":"as:manuallyApprovesFollowers","sensitive":"as:sensitive","movedTo":{"@id":"as:movedTo","@type":"@id"},"Hashtag":"as:Hashtag","ostatus":"http://ostatus.org#","atomUri":"ostatus:atomUri","inReplyToAtomUri":"ostatus:inReplyToAtomUri","conversation":"ostatus:conversation","toot":"http://joinmastodon.org/ns#","Emoji":"toot:Emoji","focalPoint":{"@container":"@list","@id":"toot:focalPoint"},"featured":{"@id":"toot:featured","@type":"@id"},"schema":"http://schema.org#","PropertyValue":"schema:PropertyValue","value":"schema:value"}],"id":"https://innocent.yukimochi.io/users/YUKIMOCHI","type":"Application","following":"https://innocent.yukimochi.io/users/YUKIMOCHI/following","followers":"https://innocent.yukimochi.io/users/YUKIMOCHI/followers","inbox":"https://innocent.yukimochi.io/users/YUKIMOCHI/inbox","outbox":"https://innocent.yukimochi.io/users/YUKIMOCHI/outbox","featured":"https://innocent.yukimochi.io/users/YUKIMOCHI/collections/featured","preferredUsername":"YUKIMOCHI","name":"雪餅🌟","summary":"\u003cp\u003e実験鯖です。連合して痛い目に合っても自己責任です・・・?(COM3D2の無垢ちゃん、かわいいかわいい!!)\u003c/p\u003e","url":"https://innocent.yukimochi.io/@YUKIMOCHI","manuallyApprovesFollowers":false,"publicKey":{"id":"https://innocent.yukimochi.io/users/YUKIMOCHI#main-key","owner":"https://innocent.yukimochi.io/users/YUKIMOCHI","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzNxXtpYOLYtpTUCxJDTq\nokV++p35C8lV+UlA8XIj8i1t64fWCqT1ULmlDEyiL1gWHEOVlV45z9PsCtJ2b2lV\nRFVBdQ1AeNKmaaTuX7CYM3wtli2cQQUlGEwWh1sgAv/LeoKRP90sA6O9M8M9H6T4\nF2cVHAaEnDFwjBQKtk/Bt70+esSkbe1qsc7vmrkaONAZrNVy6JY70r2Tg2uv7I3K\ndBpau6Igt1g87odVTPIhIVec8vnBzJvrHM1zorzRK+kPGjjAQ5XvZhkZzvjSfkkg\nqN5jDQrjfoW53vCfIJlbinEdWkJtGrDAnN1PjYIvH1bkOVJLDGUAtRtkTuCqJHPf\nMQIDAQAB\n-----END PUBLIC KEY-----\n"},"tag":[],"attachment":[],"endpoints":{"sharedInbox":"https://innocent.yukimochi.io/inbox"},"icon":{"type":"Image","mediaType":"image/png","url":"https://media.innocent.yukimochi.io/innocent/accounts/avatars/000/000/001/original/9f015d132fa2ef58.png"},"image":{"type":"Image","mediaType":"image/png","url":"https://media.innocent.yukimochi.io/innocent/accounts/headers/000/000/001/original/81300f90185e4d38.png"}} \ No newline at end of file