@@ -13,6 +13,7 @@ import (
1313 "mime"
1414 "mime/multipart"
1515 "net/http"
16+ "net/url"
1617 "strconv"
1718 "strings"
1819 "testing"
@@ -26,6 +27,7 @@ import (
2627 "github.com/ethersphere/bee/v2/pkg/manifest"
2728 mockbatchstore "github.com/ethersphere/bee/v2/pkg/postage/batchstore/mock"
2829 mockpost "github.com/ethersphere/bee/v2/pkg/postage/mock"
30+ testingsoc "github.com/ethersphere/bee/v2/pkg/soc/testing"
2931 "github.com/ethersphere/bee/v2/pkg/storage/inmemchunkstore"
3032 mockstorer "github.com/ethersphere/bee/v2/pkg/storer/mock"
3133 "github.com/ethersphere/bee/v2/pkg/swarm"
@@ -759,11 +761,24 @@ func TestFeedIndirection(t *testing.T) {
759761 updateData = []byte ("<h1>Swarm Feeds Hello World!</h1>" )
760762 logger = log .Noop
761763 storer = mockstorer .New ()
764+ ctx = context .Background ()
762765 client , _ , _ , _ = newTestServer (t , testServerOptions {
763766 Storer : storer ,
764767 Logger : logger ,
765768 Post : mockpost .New (mockpost .WithAcceptAll ()),
766769 })
770+ bzzDownloadResource = func (addr , path string , legacyFeed bool ) string {
771+ values := url.Values {}
772+ if legacyFeed {
773+ values .Set ("swarm-feed-legacy-resolve" , strconv .FormatBool (legacyFeed ))
774+ }
775+
776+ baseURL := "/bzz/" + addr + "/" + path
777+ if len (values ) > 0 {
778+ return baseURL + "?" + values .Encode ()
779+ }
780+ return baseURL
781+ }
767782 )
768783 // tar all the test case files
769784 tarReader := tarFiles (t , []f {
@@ -794,29 +809,6 @@ func TestFeedIndirection(t *testing.T) {
794809 t .Fatalf ("expected file reference, did not got any" )
795810 }
796811
797- // now use the "content" to mock the feed lookup
798- // also, use the mocked mantaray chunks that unmarshal
799- // into a real manifest with the mocked feed values when
800- // called from the bzz endpoint. then call the bzz endpoint with
801- // the pregenerated feed root manifest hash
802-
803- feedUpdate := toChunk (t , 121212 , resp .Reference .Bytes ())
804-
805- var (
806- look = newMockLookup (- 1 , 0 , feedUpdate , nil , & id {}, nil )
807- factory = newMockFactory (look )
808- bzzDownloadResource = func (addr , path string ) string { return "/bzz/" + addr + "/" + path }
809- ctx = context .Background ()
810- )
811- client , _ , _ , _ = newTestServer (t , testServerOptions {
812- Storer : storer ,
813- Logger : logger ,
814- Feeds : factory ,
815- })
816- err := storer .Cache ().Put (ctx , feedUpdate )
817- if err != nil {
818- t .Fatal (err )
819- }
820812 m , err := manifest .NewDefaultManifest (
821813 loadsave .New (storer .ChunkStore (), storer .Cache (), pipelineFactory (storer .Cache (), false , 0 ), redundancy .DefaultLevel ),
822814 false ,
@@ -838,14 +830,66 @@ func TestFeedIndirection(t *testing.T) {
838830 t .Fatal (err )
839831 }
840832
841- jsonhttptest .Request (t , client , http .MethodGet , bzzDownloadResource (manifRef .String (), "" ), http .StatusOK ,
842- jsonhttptest .WithExpectedResponse (updateData ),
843- jsonhttptest .WithExpectedContentLength (len (updateData )),
844- jsonhttptest .WithExpectedResponseHeader (api .AccessControlExposeHeaders , api .SwarmFeedIndexHeader ),
845- jsonhttptest .WithExpectedResponseHeader (api .AccessControlExposeHeaders , api .ContentDispositionHeader ),
846- jsonhttptest .WithExpectedResponseHeader (api .ContentDispositionHeader , `inline; filename="index.html"` ),
847- jsonhttptest .WithExpectedResponseHeader (api .ContentTypeHeader , "text/html; charset=utf-8" ),
848- )
833+ // now use the "content" root chunk to mock the feed lookup
834+ // also, use the mocked mantaray chunks that unmarshal
835+ // into a real manifest with the mocked feed values when
836+ // called from the bzz endpoint. then call the bzz endpoint with
837+ // the pregenerated feed root manifest hash
838+
839+ t .Run ("legacy feed" , func (t * testing.T ) {
840+ feedUpdate := toChunk (t , 121212 , resp .Reference .Bytes ())
841+
842+ var (
843+ look = newMockLookup (- 1 , 0 , feedUpdate , nil , & id {}, nil )
844+ factory = newMockFactory (look )
845+ )
846+ client , _ , _ , _ = newTestServer (t , testServerOptions {
847+ Storer : storer ,
848+ Logger : logger ,
849+ Feeds : factory ,
850+ })
851+
852+ jsonhttptest .Request (t , client , http .MethodGet , bzzDownloadResource (manifRef .String (), "" , true ), http .StatusOK ,
853+ jsonhttptest .WithExpectedResponse (updateData ),
854+ jsonhttptest .WithExpectedContentLength (len (updateData )),
855+ jsonhttptest .WithExpectedResponseHeader (api .AccessControlExposeHeaders , api .SwarmFeedIndexHeader ),
856+ jsonhttptest .WithExpectedResponseHeader (api .AccessControlExposeHeaders , api .ContentDispositionHeader ),
857+ jsonhttptest .WithExpectedResponseHeader (api .ContentDispositionHeader , `inline; filename="index.html"` ),
858+ jsonhttptest .WithExpectedResponseHeader (api .ContentTypeHeader , "text/html; charset=utf-8" ),
859+ )
860+
861+ jsonhttptest .Request (t , client , http .MethodGet , bzzDownloadResource (manifRef .String (), "" , false ), http .StatusNotFound )
862+ })
863+
864+ t .Run ("wrapped feed" , func (t * testing.T ) {
865+ // get root chunk of data and wrap it in a feed
866+ rootCh , err := storer .ChunkStore ().Get (ctx , resp .Reference )
867+ if err != nil {
868+ t .Fatal (err )
869+ }
870+ socRootCh := testingsoc .GenerateMockSOC (t , rootCh .Data ()[swarm .SpanSize :]).Chunk ()
871+
872+ var (
873+ look = newMockLookup (- 1 , 0 , socRootCh , nil , & id {}, nil )
874+ factory = newMockFactory (look )
875+ )
876+ client , _ , _ , _ = newTestServer (t , testServerOptions {
877+ Storer : storer ,
878+ Logger : logger ,
879+ Feeds : factory ,
880+ })
881+
882+ jsonhttptest .Request (t , client , http .MethodGet , bzzDownloadResource (manifRef .String (), "" , false ), http .StatusOK ,
883+ jsonhttptest .WithExpectedResponse (updateData ),
884+ jsonhttptest .WithExpectedContentLength (len (updateData )),
885+ jsonhttptest .WithExpectedResponseHeader (api .AccessControlExposeHeaders , api .SwarmFeedIndexHeader ),
886+ jsonhttptest .WithExpectedResponseHeader (api .AccessControlExposeHeaders , api .ContentDispositionHeader ),
887+ jsonhttptest .WithExpectedResponseHeader (api .ContentDispositionHeader , `inline; filename="index.html"` ),
888+ jsonhttptest .WithExpectedResponseHeader (api .ContentTypeHeader , "text/html; charset=utf-8" ),
889+ )
890+
891+ jsonhttptest .Request (t , client , http .MethodGet , bzzDownloadResource (manifRef .String (), "" , true ), http .StatusBadRequest )
892+ })
849893}
850894
851895func Test_bzzDownloadHandler_invalidInputs (t * testing.T ) {
0 commit comments