@@ -6616,3 +6616,55 @@ func TestIssue75(t *testing.T) {
66166616 t .Fatalf ("unexpected callback object: %s" , err )
66176617 }
66186618}
6619+
6620+ func TestDelivery_Bytes (t * testing.T ) {
6621+ app , socialApp , fedApp , socialCb , fedCb , d , httpClient , p := NewPubberTest (t )
6622+ PreparePubberPostOutboxTest (t , app , socialApp , fedApp , socialCb , fedCb , d , httpClient , p )
6623+ resp := httptest .NewRecorder ()
6624+ req := Sign (ActivityPubRequest (httptest .NewRequest ("POST" , testOutboxURI , bytes .NewBuffer (MustSerialize (testCreateNote )))))
6625+ socialCb .create = func (c context.Context , s * streams.Create ) error {
6626+ return nil
6627+ }
6628+ gotHttpDo := 0
6629+ var httpDeliveryRequest * http.Request
6630+ httpClient .do = func (req * http.Request ) (* http.Response , error ) {
6631+ gotHttpDo ++
6632+ if gotHttpDo == 1 {
6633+ actorResp := & http.Response {
6634+ StatusCode : http .StatusOK ,
6635+ Body : ioutil .NopCloser (bytes .NewBuffer (samActorJSON )),
6636+ }
6637+ return actorResp , nil
6638+ } else if gotHttpDo == 2 {
6639+ actorResp := & http.Response {
6640+ StatusCode : http .StatusOK ,
6641+ Body : ioutil .NopCloser (bytes .NewBuffer (sallyActorJSON )),
6642+ }
6643+ return actorResp , nil
6644+ } else if gotHttpDo == 3 {
6645+ httpDeliveryRequest = req
6646+ okResp := & http.Response {
6647+ StatusCode : http .StatusOK ,
6648+ Body : ioutil .NopCloser (bytes .NewBuffer ([]byte {})),
6649+ }
6650+ return okResp , nil
6651+ }
6652+ return nil , nil
6653+ }
6654+ handled , err := p .PostOutbox (context .Background (), resp , req )
6655+ if err != nil {
6656+ t .Fatal (err )
6657+ } else if ! handled {
6658+ t .Fatalf ("expected handled, got !handled" )
6659+ } else if gotHttpDo != 3 {
6660+ t .Fatalf ("expected %d, got %d" , 3 , gotHttpDo )
6661+ } else if httpDeliveryRequest .Method != "POST" {
6662+ t .Fatalf ("expected %s, got %s" , "POST" , httpDeliveryRequest .Method )
6663+ } else if deliveryBody , err := ioutil .ReadAll (httpDeliveryRequest .Body ); err != nil {
6664+ t .Fatal (err )
6665+ } else if len (deliveryBody ) == 0 {
6666+ t .Fatalf ("empty delivery body" )
6667+ } else if s := httpDeliveryRequest .URL .String (); s != samIRIInboxString {
6668+ t .Fatalf ("expected %s, got %s" , samIRIInboxString , s )
6669+ }
6670+ }
0 commit comments