BlockService should block any other type of Actor.

This commit is contained in:
Naoki Kosaka 2020-01-02 02:02:16 +09:00
parent 9f439a0629
commit 7e51cd7190
3 changed files with 16 additions and 1 deletions

View File

@ -162,7 +162,7 @@ func suitableRelay(activity *activitypub.Activity, actor *activitypub.Actor) boo
if contains(relayState.LimitedDomains, domain.Host) { if contains(relayState.LimitedDomains, domain.Host) {
return false return false
} }
if relayState.RelayConfig.BlockService && actor.Type == "Service" { if relayState.RelayConfig.BlockService && actor.Type != "Person" {
return false return false
} }
return true return true

View File

@ -242,6 +242,12 @@ func mockActor(req string) activitypub.Actor {
var actor activitypub.Actor var actor activitypub.Actor
json.Unmarshal(body, &actor) json.Unmarshal(body, &actor)
return 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: default:
panic("No assined request.") panic("No assined request.")
} }
@ -251,6 +257,7 @@ func TestSuitableRelayNoBlockService(t *testing.T) {
activity := mockActivity("Create") activity := mockActivity("Create")
personActor := mockActor("Person") personActor := mockActor("Person")
serviceActor := mockActor("Service") serviceActor := mockActor("Service")
applicationActor := mockActor("Application")
relayState.SetConfig(BlockService, false) relayState.SetConfig(BlockService, false)
@ -260,12 +267,16 @@ func TestSuitableRelayNoBlockService(t *testing.T) {
if suitableRelay(&activity, &serviceActor) != true { if suitableRelay(&activity, &serviceActor) != true {
t.Fatalf("Failed - Service status not relay") t.Fatalf("Failed - Service status not relay")
} }
if suitableRelay(&activity, &applicationActor) != true {
t.Fatalf("Failed - Service status not relay")
}
} }
func TestSuitableRelayBlockService(t *testing.T) { func TestSuitableRelayBlockService(t *testing.T) {
activity := mockActivity("Create") activity := mockActivity("Create")
personActor := mockActor("Person") personActor := mockActor("Person")
serviceActor := mockActor("Service") serviceActor := mockActor("Service")
applicationActor := mockActor("Application")
relayState.SetConfig(BlockService, true) relayState.SetConfig(BlockService, true)
@ -275,6 +286,9 @@ func TestSuitableRelayBlockService(t *testing.T) {
if suitableRelay(&activity, &serviceActor) != false { if suitableRelay(&activity, &serviceActor) != false {
t.Fatalf("Failed - Service status may relay when blocking mode") 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) relayState.SetConfig(BlockService, false)
} }

1
misc/application.json Normal file
View File

@ -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"}}