Move CanAdd & CanRemove into Application interface
このコミットが含まれているのは:
コミット
6c1de66753
|
@ -624,7 +624,7 @@ func (f *federator) handleClientAdd(c context.Context, deliverable *bool) func(s
|
||||||
}
|
}
|
||||||
obj := raw.GetObject(i)
|
obj := raw.GetObject(i)
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
if !f.SocialAPI.CanAdd(c, obj, target) {
|
if !f.App.CanAdd(c, obj, target) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ct, ok := target.(vocab.CollectionType); ok {
|
if ct, ok := target.(vocab.CollectionType); ok {
|
||||||
|
@ -688,7 +688,7 @@ func (f *federator) handleClientRemove(c context.Context, deliverable *bool) fun
|
||||||
}
|
}
|
||||||
obj := raw.GetObject(i)
|
obj := raw.GetObject(i)
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
if !f.SocialAPI.CanRemove(c, obj, target) {
|
if !f.App.CanRemove(c, obj, target) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ct, ok := target.(vocab.CollectionType); ok {
|
if ct, ok := target.(vocab.CollectionType); ok {
|
||||||
|
@ -1028,7 +1028,7 @@ func (f *federator) handleAdd(c context.Context) func(s *streams.Add) error {
|
||||||
}
|
}
|
||||||
obj := raw.GetObject(i)
|
obj := raw.GetObject(i)
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
if !f.FederateAPI.CanFederateAdd(c, obj, target) {
|
if !f.App.CanAdd(c, obj, target) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ct, ok := target.(vocab.CollectionType); ok {
|
if ct, ok := target.(vocab.CollectionType); ok {
|
||||||
|
@ -1092,7 +1092,7 @@ func (f *federator) handleRemove(c context.Context) func(s *streams.Remove) erro
|
||||||
}
|
}
|
||||||
obj := raw.GetObject(i)
|
obj := raw.GetObject(i)
|
||||||
for _, target := range targets {
|
for _, target := range targets {
|
||||||
if !f.FederateAPI.CanFederateRemove(c, obj, target) {
|
if !f.App.CanRemove(c, obj, target) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if ct, ok := target.(vocab.CollectionType); ok {
|
if ct, ok := target.(vocab.CollectionType); ok {
|
||||||
|
|
|
@ -564,6 +564,8 @@ type MockApplication struct {
|
||||||
getOutbox func(c context.Context, r *http.Request, rw RWType) (vocab.OrderedCollectionType, error)
|
getOutbox func(c context.Context, r *http.Request, rw RWType) (vocab.OrderedCollectionType, error)
|
||||||
newId func(c context.Context, t Typer) *url.URL
|
newId func(c context.Context, t Typer) *url.URL
|
||||||
getPublicKey func(c context.Context, publicKeyId string) (crypto.PublicKey, httpsig.Algorithm, *url.URL, error)
|
getPublicKey func(c context.Context, publicKeyId string) (crypto.PublicKey, httpsig.Algorithm, *url.URL, error)
|
||||||
|
canAdd func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
||||||
|
canRemove func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockApplication) Owns(c context.Context, id *url.URL) bool {
|
func (m *MockApplication) Owns(c context.Context, id *url.URL) bool {
|
||||||
|
@ -629,32 +631,30 @@ func (m *MockApplication) GetPublicKey(c context.Context, publicKeyId string) (c
|
||||||
return m.getPublicKey(c, publicKeyId)
|
return m.getPublicKey(c, publicKeyId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockApplication) CanAdd(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
|
if m.canAdd == nil {
|
||||||
|
m.t.Fatal("unexpected call to MockApplication CanAdd")
|
||||||
|
}
|
||||||
|
return m.canAdd(c, o, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *MockApplication) CanRemove(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
|
if m.canRemove == nil {
|
||||||
|
m.t.Fatal("unexpected call to MockApplication CanRemove")
|
||||||
|
}
|
||||||
|
return m.canRemove(c, o, t)
|
||||||
|
}
|
||||||
|
|
||||||
var _ SocialApplication = &MockSocialApp{}
|
var _ SocialApplication = &MockSocialApp{}
|
||||||
|
|
||||||
type MockSocialApp struct {
|
type MockSocialApp struct {
|
||||||
*MockApplication
|
*MockApplication
|
||||||
t *testing.T
|
t *testing.T
|
||||||
canAdd func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
|
||||||
canRemove func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
|
||||||
actorIRI func(c context.Context, r *http.Request) (*url.URL, error)
|
actorIRI func(c context.Context, r *http.Request) (*url.URL, error)
|
||||||
getPublicKeyForOutbox func(c context.Context, publicKeyId string, boxIRI *url.URL) (crypto.PublicKey, httpsig.Algorithm, error)
|
getPublicKeyForOutbox func(c context.Context, publicKeyId string, boxIRI *url.URL) (crypto.PublicKey, httpsig.Algorithm, error)
|
||||||
getSocialAPIVerifier func(c context.Context) SocialAPIVerifier
|
getSocialAPIVerifier func(c context.Context) SocialAPIVerifier
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockSocialApp) CanAdd(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
|
||||||
if m.canAdd == nil {
|
|
||||||
m.t.Fatal("unexpected call to MockSocialApp CanAdd")
|
|
||||||
}
|
|
||||||
return m.canAdd(c, o, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockSocialApp) CanRemove(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
|
||||||
if m.canRemove == nil {
|
|
||||||
m.t.Fatal("unexpected call to MockSocialApp CanRemove")
|
|
||||||
}
|
|
||||||
return m.canRemove(c, o, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockSocialApp) ActorIRI(c context.Context, r *http.Request) (*url.URL, error) {
|
func (m *MockSocialApp) ActorIRI(c context.Context, r *http.Request) (*url.URL, error) {
|
||||||
if m.actorIRI == nil {
|
if m.actorIRI == nil {
|
||||||
m.t.Fatal("unexpected call to MockSocialApp ActorIRI")
|
m.t.Fatal("unexpected call to MockSocialApp ActorIRI")
|
||||||
|
@ -797,8 +797,6 @@ var _ FederateApplication = &MockFederateApp{}
|
||||||
type MockFederateApp struct {
|
type MockFederateApp struct {
|
||||||
*MockApplication
|
*MockApplication
|
||||||
t *testing.T
|
t *testing.T
|
||||||
canAdd func(c context.Context, obj vocab.ObjectType, target vocab.ObjectType) bool
|
|
||||||
canRemove func(c context.Context, obj vocab.ObjectType, target vocab.ObjectType) bool
|
|
||||||
onFollow func(c context.Context, s *streams.Follow) FollowResponse
|
onFollow func(c context.Context, s *streams.Follow) FollowResponse
|
||||||
unblocked func(c context.Context, actorIRIs []*url.URL) error
|
unblocked func(c context.Context, actorIRIs []*url.URL) error
|
||||||
getFollowing func(c context.Context, actor *url.URL) (vocab.CollectionType, error)
|
getFollowing func(c context.Context, actor *url.URL) (vocab.CollectionType, error)
|
||||||
|
@ -807,20 +805,6 @@ type MockFederateApp struct {
|
||||||
privateKey func(boxIRI *url.URL) (crypto.PrivateKey, string, error)
|
privateKey func(boxIRI *url.URL) (crypto.PrivateKey, string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockFederateApp) CanFederateAdd(c context.Context, obj vocab.ObjectType, target vocab.ObjectType) bool {
|
|
||||||
if m.canAdd == nil {
|
|
||||||
m.t.Fatal("unexpected call to MockFederateApp CanFederateAdd")
|
|
||||||
}
|
|
||||||
return m.canAdd(c, obj, target)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockFederateApp) CanFederateRemove(c context.Context, obj vocab.ObjectType, target vocab.ObjectType) bool {
|
|
||||||
if m.canRemove == nil {
|
|
||||||
m.t.Fatal("unexpected call to MockFederateApp CanFederateRemove")
|
|
||||||
}
|
|
||||||
return m.canRemove(c, obj, target)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MockFederateApp) OnFollow(c context.Context, s *streams.Follow) FollowResponse {
|
func (m *MockFederateApp) OnFollow(c context.Context, s *streams.Follow) FollowResponse {
|
||||||
if m.onFollow == nil {
|
if m.onFollow == nil {
|
||||||
m.t.Fatal("unexpected call to MockFederateApp OnFollow")
|
m.t.Fatal("unexpected call to MockFederateApp OnFollow")
|
||||||
|
@ -897,6 +881,12 @@ func (m *MockSocialFederateApp) NewId(c context.Context, t Typer) *url.URL {
|
||||||
func (m *MockSocialFederateApp) GetPublicKey(c context.Context, publicKeyId string) (crypto.PublicKey, httpsig.Algorithm, *url.URL, error) {
|
func (m *MockSocialFederateApp) GetPublicKey(c context.Context, publicKeyId string) (crypto.PublicKey, httpsig.Algorithm, *url.URL, error) {
|
||||||
return m.MockFederateApp.GetPublicKey(c, publicKeyId)
|
return m.MockFederateApp.GetPublicKey(c, publicKeyId)
|
||||||
}
|
}
|
||||||
|
func (m *MockSocialFederateApp) CanAdd(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
|
return m.MockFederateApp.CanAdd(c, o, t)
|
||||||
|
}
|
||||||
|
func (m *MockSocialFederateApp) CanRemove(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
|
return m.MockFederateApp.CanRemove(c, o, t)
|
||||||
|
}
|
||||||
|
|
||||||
var _ Deliverer = &MockDeliverer{}
|
var _ Deliverer = &MockDeliverer{}
|
||||||
|
|
||||||
|
@ -3391,7 +3381,7 @@ func TestPostInbox_Add_AddIfTargetOwnedAndAppCanAdd(t *testing.T) {
|
||||||
gotCanAdd := 0
|
gotCanAdd := 0
|
||||||
var gotCanAddObject vocab.ObjectType
|
var gotCanAddObject vocab.ObjectType
|
||||||
var gotCanAddTarget vocab.ObjectType
|
var gotCanAddTarget vocab.ObjectType
|
||||||
fedApp.canAdd = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canAdd = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanAdd++
|
gotCanAdd++
|
||||||
gotCanAddObject = o
|
gotCanAddObject = o
|
||||||
gotCanAddTarget = t
|
gotCanAddTarget = t
|
||||||
|
@ -3460,7 +3450,7 @@ func TestPostInbox_Add_DoesNotAddIfAppCannotAdd(t *testing.T) {
|
||||||
gotCanAdd := 0
|
gotCanAdd := 0
|
||||||
var gotCanAddObject vocab.ObjectType
|
var gotCanAddObject vocab.ObjectType
|
||||||
var gotCanAddTarget vocab.ObjectType
|
var gotCanAddTarget vocab.ObjectType
|
||||||
fedApp.canAdd = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canAdd = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanAdd++
|
gotCanAdd++
|
||||||
gotCanAddObject = o
|
gotCanAddObject = o
|
||||||
gotCanAddTarget = t
|
gotCanAddTarget = t
|
||||||
|
@ -3503,7 +3493,7 @@ func TestPostInbox_Add_CallsCallback(t *testing.T) {
|
||||||
v := &vocab.Collection{}
|
v := &vocab.Collection{}
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
fedApp.canAdd = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canAdd = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
gotCallback := 0
|
gotCallback := 0
|
||||||
|
@ -3579,7 +3569,7 @@ func TestPostInbox_Remove_RemoveIfTargetOwnedAndCanRemove(t *testing.T) {
|
||||||
gotCanRemove := 0
|
gotCanRemove := 0
|
||||||
var gotCanRemoveObject vocab.ObjectType
|
var gotCanRemoveObject vocab.ObjectType
|
||||||
var gotCanRemoveTarget vocab.ObjectType
|
var gotCanRemoveTarget vocab.ObjectType
|
||||||
fedApp.canRemove = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canRemove = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanRemove++
|
gotCanRemove++
|
||||||
gotCanRemoveObject = o
|
gotCanRemoveObject = o
|
||||||
gotCanRemoveTarget = t
|
gotCanRemoveTarget = t
|
||||||
|
@ -3647,7 +3637,7 @@ func TestPostInbox_Remove_DoesNotRemoveIfAppCannotRemove(t *testing.T) {
|
||||||
gotCanRemove := 0
|
gotCanRemove := 0
|
||||||
var gotCanRemoveObject vocab.ObjectType
|
var gotCanRemoveObject vocab.ObjectType
|
||||||
var gotCanRemoveTarget vocab.ObjectType
|
var gotCanRemoveTarget vocab.ObjectType
|
||||||
fedApp.canRemove = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canRemove = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanRemove++
|
gotCanRemove++
|
||||||
gotCanRemoveObject = o
|
gotCanRemoveObject = o
|
||||||
gotCanRemoveTarget = t
|
gotCanRemoveTarget = t
|
||||||
|
@ -3692,7 +3682,7 @@ func TestPostInbox_Remove_CallsCallback(t *testing.T) {
|
||||||
v := &vocab.Collection{}
|
v := &vocab.Collection{}
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
fedApp.canRemove = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canRemove = func(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
gotCallback := 0
|
gotCallback := 0
|
||||||
|
@ -5316,7 +5306,7 @@ func TestPostOutbox_Add_AddsIfTargetOwnedAndAppCanAdd(t *testing.T) {
|
||||||
gotCanAdd := 0
|
gotCanAdd := 0
|
||||||
var canAddObj vocab.ObjectType
|
var canAddObj vocab.ObjectType
|
||||||
var canAddTarget vocab.ObjectType
|
var canAddTarget vocab.ObjectType
|
||||||
socialApp.canAdd = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canAdd = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanAdd++
|
gotCanAdd++
|
||||||
canAddObj = obj
|
canAddObj = obj
|
||||||
canAddTarget = t
|
canAddTarget = t
|
||||||
|
@ -5379,7 +5369,7 @@ func TestPostOutbox_Add_DoesNotAddIfAppCannotAdd(t *testing.T) {
|
||||||
gotCanAdd := 0
|
gotCanAdd := 0
|
||||||
var canAddObj vocab.ObjectType
|
var canAddObj vocab.ObjectType
|
||||||
var canAddTarget vocab.ObjectType
|
var canAddTarget vocab.ObjectType
|
||||||
socialApp.canAdd = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canAdd = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanAdd++
|
gotCanAdd++
|
||||||
canAddObj = obj
|
canAddObj = obj
|
||||||
canAddTarget = t
|
canAddTarget = t
|
||||||
|
@ -5534,7 +5524,7 @@ func TestPostOutbox_Remove_RemoveIfTargetOwnedAndCanRemove(t *testing.T) {
|
||||||
gotCanRemove := 0
|
gotCanRemove := 0
|
||||||
var canRemoveObj vocab.ObjectType
|
var canRemoveObj vocab.ObjectType
|
||||||
var canRemoveTarget vocab.ObjectType
|
var canRemoveTarget vocab.ObjectType
|
||||||
socialApp.canRemove = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canRemove = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanRemove++
|
gotCanRemove++
|
||||||
canRemoveObj = obj
|
canRemoveObj = obj
|
||||||
canRemoveTarget = t
|
canRemoveTarget = t
|
||||||
|
@ -5597,7 +5587,7 @@ func TestPostOutbox_Remove_DoesNotRemoveIfAppCannotRemove(t *testing.T) {
|
||||||
gotCanRemove := 0
|
gotCanRemove := 0
|
||||||
var canRemoveObj vocab.ObjectType
|
var canRemoveObj vocab.ObjectType
|
||||||
var canRemoveTarget vocab.ObjectType
|
var canRemoveTarget vocab.ObjectType
|
||||||
socialApp.canRemove = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
app.MockFederateApp.canRemove = func(c context.Context, obj vocab.ObjectType, t vocab.ObjectType) bool {
|
||||||
gotCanRemove++
|
gotCanRemove++
|
||||||
canRemoveObj = obj
|
canRemoveObj = obj
|
||||||
canRemoveTarget = t
|
canRemoveTarget = t
|
||||||
|
|
|
@ -105,6 +105,14 @@ type Application interface {
|
||||||
// key id. It also determines which algorithm to use to verify the
|
// key id. It also determines which algorithm to use to verify the
|
||||||
// signature.
|
// signature.
|
||||||
GetPublicKey(c context.Context, publicKeyId string) (pubKey crypto.PublicKey, algo httpsig.Algorithm, user *url.URL, err error)
|
GetPublicKey(c context.Context, publicKeyId string) (pubKey crypto.PublicKey, algo httpsig.Algorithm, user *url.URL, err error)
|
||||||
|
// CanAdd returns true if the provided object is allowed to be added to
|
||||||
|
// the given target collection. Applicable to either or both of the
|
||||||
|
// SocialAPI and FederateAPI.
|
||||||
|
CanAdd(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
||||||
|
// CanRemove returns true if the provided object is allowed to be
|
||||||
|
// removed from the given target collection. Applicable to either or
|
||||||
|
// both of the SocialAPI and FederateAPI.
|
||||||
|
CanRemove(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// RWType indicates the kind of reading being done.
|
// RWType indicates the kind of reading being done.
|
||||||
|
@ -120,12 +128,6 @@ const (
|
||||||
// SocialAPI is provided by users of this library and designed to handle
|
// SocialAPI is provided by users of this library and designed to handle
|
||||||
// receiving messages from ActivityPub clients through the Social API.
|
// receiving messages from ActivityPub clients through the Social API.
|
||||||
type SocialAPI interface {
|
type SocialAPI interface {
|
||||||
// CanAdd returns true if the provided object is allowed to be added to
|
|
||||||
// the given target collection.
|
|
||||||
CanAdd(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
|
||||||
// CanRemove returns true if the provided object is allowed to be
|
|
||||||
// removed from the given target collection.
|
|
||||||
CanRemove(c context.Context, o vocab.ObjectType, t vocab.ObjectType) bool
|
|
||||||
// AddToOutboxResolver(c context.Context) (*streams.Resolver, error)
|
// AddToOutboxResolver(c context.Context) (*streams.Resolver, error)
|
||||||
// ActorIRI returns the actor's IRI associated with the given request.
|
// ActorIRI returns the actor's IRI associated with the given request.
|
||||||
ActorIRI(c context.Context, r *http.Request) (*url.URL, error)
|
ActorIRI(c context.Context, r *http.Request) (*url.URL, error)
|
||||||
|
@ -149,12 +151,6 @@ type SocialAPI interface {
|
||||||
// FederateAPI is provided by users of this library and designed to handle
|
// FederateAPI is provided by users of this library and designed to handle
|
||||||
// receiving messages from ActivityPub servers through the Federative API.
|
// receiving messages from ActivityPub servers through the Federative API.
|
||||||
type FederateAPI interface {
|
type FederateAPI interface {
|
||||||
// CanFederateAdd returns true if the provided object is allowed to be added to
|
|
||||||
// the given target collection.
|
|
||||||
CanFederateAdd(c context.Context, obj vocab.ObjectType, target vocab.ObjectType) bool
|
|
||||||
// CanFederateRemove returns true if the provided object is allowed to be added to
|
|
||||||
// the given target collection.
|
|
||||||
CanFederateRemove(c context.Context, obj vocab.ObjectType, target vocab.ObjectType) bool
|
|
||||||
// OnFollow determines whether to take any automatic reactions in
|
// OnFollow determines whether to take any automatic reactions in
|
||||||
// response to this follow. Note that if this application does not own
|
// response to this follow. Note that if this application does not own
|
||||||
// an object on the activity, then the 'AutomaticAccept' and
|
// an object on the activity, then the 'AutomaticAccept' and
|
||||||
|
|
読み込み中…
新しいイシューから参照