From a1fc177bc78d2b9ab1808b9eabda9338a1926e3e Mon Sep 17 00:00:00 2001 From: Cory Slep Date: Wed, 6 Jun 2018 22:45:36 +0200 Subject: [PATCH] PostOutbox Create actor & attributedTo uses IRIs Part of normalizing IRIs and preventing overly embedding objects. --- pub/fed.go | 29 ++++++++++++++++++++++------- pub/fed_test.go | 2 +- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pub/fed.go b/pub/fed.go index 358480a..e2ed249 100644 --- a/pub/fed.go +++ b/pub/fed.go @@ -400,7 +400,6 @@ func (f *federator) getPostOutboxResolver(c context.Context, rawJson map[string] } } -// TODO: Only Set IRIs func (f *federator) handleClientCreate(ctx context.Context, deliverable *bool, toAddToOutbox *map[string]interface{}) func(s *streams.Create) error { return func(s *streams.Create) error { *deliverable = true @@ -457,26 +456,42 @@ func (f *federator) handleClientCreate(ctx context.Context, deliverable *bool, t for k, v := range createActorIds { for i, attributedToMap := range objectAttributedToIds { if _, ok := attributedToMap[k]; !ok { + var iri *url.URL if vObj, ok := v.(vocab.ObjectType); ok { - obj[i].AppendAttributedToObject(vObj) + if !vObj.HasId() { + return fmt.Errorf("create actor object missing id") + } + iri = vObj.GetId() } else if vLink, ok := v.(vocab.LinkType); ok { - obj[i].AppendAttributedToLink(vLink) + if !vLink.HasHref() { + return fmt.Errorf("create actor link missing href") + } + iri = vLink.GetHref() } else if vIRI, ok := v.(*url.URL); ok { - obj[i].AppendAttributedToIRI(vIRI) + iri = vIRI } + obj[i].AppendAttributedToIRI(iri) } } } for _, attributedToMap := range objectAttributedToIds { for k, v := range attributedToMap { if _, ok := createActorIds[k]; !ok { + var iri *url.URL if vObj, ok := v.(vocab.ObjectType); ok { - c.AppendActorObject(vObj) + if !vObj.HasId() { + return fmt.Errorf("attributedTo object missing id") + } + iri = vObj.GetId() } else if vLink, ok := v.(vocab.LinkType); ok { - c.AppendActorLink(vLink) + if !vLink.HasHref() { + return fmt.Errorf("attributedTo link missing href") + } + iri = vLink.GetHref() } else if vIRI, ok := v.(*url.URL); ok { - c.AppendActorIRI(vIRI) + iri = vIRI } + c.AppendActorIRI(iri) } } } diff --git a/pub/fed_test.go b/pub/fed_test.go index 0e2f4a8..5397495 100644 --- a/pub/fed_test.go +++ b/pub/fed_test.go @@ -267,7 +267,7 @@ func init() { testClientExpectedNote.SetId(testNewIRI2) testClientExpectedNote.AppendNameString(noteName) testClientExpectedNote.AppendContentString("This is a simple note") - testClientExpectedNote.AppendAttributedToObject(sallyActor) + testClientExpectedNote.AppendAttributedToIRI(sallyIRI) testClientExpectedNote.AppendToIRI(samIRI) testClientExpectedCreateNote = &vocab.Create{} testClientExpectedCreateNote.SetId(testNewIRI)