diff --git a/swarm/api/http/server_test.go b/swarm/api/http/server_test.go index 6ec72330cb..901db68bc4 100644 --- a/swarm/api/http/server_test.go +++ b/swarm/api/http/server_test.go @@ -29,7 +29,6 @@ import ( "strings" "testing" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/swarm/api" swarm "github.com/ethereum/go-ethereum/swarm/api/client" @@ -218,23 +217,23 @@ func TestBzzResource(t *testing.T) { } func TestBzzGetPath(t *testing.T) { - // TODO: add encrypted test case testBzzGetPath(false, t) + testBzzGetPath(true, t) } func testBzzGetPath(encrypted bool, t *testing.T) { var err error testmanifest := []string{ - `{"entries":[{"path":"a/","hash":"674af7073604ebfc0282a4ab21e5ef1a3c22913866879ebc0816f8a89896b2ed","contentType":"application/bzz-manifest+json","status":0}]}`, - `{"entries":[{"path":"a","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"b/","hash":"0a87b1c3e4bf013686cdf107ec58590f2004610ee58cc2240f26939f691215f5","contentType":"application/bzz-manifest+json","status":0}]}`, `{"entries":[{"path":"b","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"c","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0}]}`, + `{"entries":[{"path":"a","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"b/","hash":"","contentType":"application/bzz-manifest+json","status":0}]}`, + `{"entries":[{"path":"a/","hash":"","contentType":"application/bzz-manifest+json","status":0}]}`, } testrequests := make(map[string]int) - testrequests["/"] = 0 + testrequests["/"] = 2 testrequests["/a/"] = 1 - testrequests["/a/b/"] = 2 + testrequests["/a/b/"] = 0 testrequests["/x"] = 0 testrequests[""] = 0 @@ -251,13 +250,19 @@ func testBzzGetPath(encrypted bool, t *testing.T) { reader[i] = bytes.NewReader([]byte(mf)) var wait func() key[i], wait, err = srv.Dpa.Store(reader[i], int64(len(mf)), encrypted) + for j := i + 1; j < len(testmanifest); j++ { + testmanifest[j] = strings.Replace(testmanifest[j], fmt.Sprintf("", i), key[i].Hex(), -1) + } if err != nil { t.Fatal(err) } wait() + fmt.Println("!!!!!!!!!!", i, key[i]) } - _, err = http.Get(srv.URL + "/bzz-raw:/" + common.ToHex(key[0])[2:] + "/a") + rootRef := key[2].Hex() + + _, err = http.Get(srv.URL + "/bzz-raw:/" + rootRef + "/a") if err != nil { t.Fatalf("Failed to connect to proxy: %v", err) } @@ -268,7 +273,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) { url := srv.URL + "/bzz-raw:/" if k[:] != "" { - url += common.ToHex(key[0])[2:] + "/" + k[1:] + "?content_type=text/plain" + url += rootRef + "/" + k[1:] + "?content_type=text/plain" } resp, err = http.Get(url) if err != nil { @@ -297,7 +302,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) { url := srv.URL + "/bzz-hash:/" if k[:] != "" { - url += common.ToHex(key[0])[2:] + "/" + k[1:] + url += rootRef + "/" + k[1:] } resp, err = http.Get(url) if err != nil { @@ -323,6 +328,8 @@ func testBzzGetPath(encrypted bool, t *testing.T) { } } + ref := key[2].Hex() + for _, c := range []struct { path string json string @@ -331,17 +338,17 @@ func testBzzGetPath(encrypted bool, t *testing.T) { { path: "/", json: `{"common_prefixes":["a/"]}`, - html: "\n\n\n \n \n\t\t\n\tSwarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/\n\n\n\n

Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/

\n
\n \n \n \n\t\n\t\n\t\n \n \n\n \n \n\t\n\t \n\t \n\t \n\t\n \n\n \n
PathTypeSize
a/DIR-
\n
\n\n", + html: fmt.Sprintf("\n\n\n \n \n\t\t\n\tSwarm index of bzz:/%s/\n\n\n\n

Swarm index of bzz:/%s/

\n
\n \n \n \n\t\n\t\n\t\n \n \n\n \n \n\t\n\t \n\t \n\t \n\t\n \n\n \n
PathTypeSize
a/DIR-
\n
\n\n", ref, ref), }, { path: "/a/", json: `{"common_prefixes":["a/b/"],"entries":[{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/a","mod_time":"0001-01-01T00:00:00Z"}]}`, - html: "\n\n\n \n \n\t\t\n\tSwarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/\n\n\n\n

Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/

\n
\n \n \n \n\t\n\t\n\t\n \n \n\n \n \n\t\n\t \n\t \n\t \n\t\n \n\n \n\t\n\t \n\t \n\t \n\t\n \n
PathTypeSize
b/DIR-
a0
\n
\n\n", + html: fmt.Sprintf("\n\n\n \n \n\t\t\n\tSwarm index of bzz:/%s/a/\n\n\n\n

Swarm index of bzz:/%s/a/

\n
\n \n \n \n\t\n\t\n\t\n \n \n\n \n \n\t\n\t \n\t \n\t \n\t\n \n\n \n\t\n\t \n\t \n\t \n\t\n \n
PathTypeSize
b/DIR-
a0
\n
\n\n", ref, ref), }, { path: "/a/b/", json: `{"entries":[{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/b/b","mod_time":"0001-01-01T00:00:00Z"},{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/b/c","mod_time":"0001-01-01T00:00:00Z"}]}`, - html: "\n\n\n \n \n\t\t\n\tSwarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/b/\n\n\n\n

Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/b/

\n
\n \n \n \n\t\n\t\n\t\n \n \n\n \n \n\n \n\t\n\t \n\t \n\t \n\t\n \n\t\n\t \n\t \n\t \n\t\n \n
PathTypeSize
b0
c0
\n
\n\n", + html: fmt.Sprintf("\n\n\n \n \n\t\t\n\tSwarm index of bzz:/%s/a/b/\n\n\n\n

Swarm index of bzz:/%s/a/b/

\n
\n \n \n \n\t\n\t\n\t\n \n \n\n \n \n\n \n\t\n\t \n\t \n\t \n\t\n \n\t\n\t \n\t \n\t \n\t\n \n
PathTypeSize
b0
c0
\n
\n\n", ref, ref), }, { path: "/x", @@ -353,7 +360,7 @@ func testBzzGetPath(encrypted bool, t *testing.T) { k := c.path url := srv.URL + "/bzz-list:/" if k[:] != "" { - url += common.ToHex(key[0])[2:] + "/" + k[1:] + url += rootRef + "/" + k[1:] } t.Run("json list "+c.path, func(t *testing.T) { resp, err := http.Get(url)