aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/http/server_test.go
diff options
context:
space:
mode:
authorJanoš Guljaš <janos@users.noreply.github.com>2017-12-19 16:49:30 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-12-19 16:49:30 +0800
commitc786f75389121c29d4380c53a013759254457776 (patch)
treedc43ce4aa2371c934c364c5c22e0f7fd7b7d45ae /swarm/api/http/server_test.go
parent7f9d94fe9aacd4122f12f1fa75223ac9f8c9380e (diff)
downloadgo-tangerine-c786f75389121c29d4380c53a013759254457776.tar
go-tangerine-c786f75389121c29d4380c53a013759254457776.tar.gz
go-tangerine-c786f75389121c29d4380c53a013759254457776.tar.bz2
go-tangerine-c786f75389121c29d4380c53a013759254457776.tar.lz
go-tangerine-c786f75389121c29d4380c53a013759254457776.tar.xz
go-tangerine-c786f75389121c29d4380c53a013759254457776.tar.zst
go-tangerine-c786f75389121c29d4380c53a013759254457776.zip
swarm: bzz-list, bzz-raw and bzz-immutable schemes (#15667)
* swarm/api: url scheme bzz-list for getting list of files from manifest Replace query parameter list=true for listing all files contained in a swarm manifest with a new URL scheme bzz-list. * swarm: replaace bzzr and bzzi schemes with bzz-raw and bzz-immutable New URI Shemes are added and old ones are deprecated, but not removed. Old Schemes bzzr and bzzi are functional for backward compatibility. * swarm/api: completely remove bzzr and bzzi schemes Remove old schemes in favour of bzz-raw and bzz-immutable. * swarm/api: revert "completely remove bzzr and bzzi schemes" Keep bzzr and bzzi schemes for backward compatibility. At least until 0.3 swarm release.
Diffstat (limited to 'swarm/api/http/server_test.go')
-rw-r--r--swarm/api/http/server_test.go98
1 files changed, 94 insertions, 4 deletions
diff --git a/swarm/api/http/server_test.go b/swarm/api/http/server_test.go
index ffeaf6e0d..dbbfa3b07 100644
--- a/swarm/api/http/server_test.go
+++ b/swarm/api/http/server_test.go
@@ -70,7 +70,7 @@ func TestBzzrGetPath(t *testing.T) {
wg.Wait()
}
- _, err = http.Get(srv.URL + "/bzzr:/" + common.ToHex(key[0])[2:] + "/a")
+ _, err = http.Get(srv.URL + "/bzz-raw:/" + common.ToHex(key[0])[2:] + "/a")
if err != nil {
t.Fatalf("Failed to connect to proxy: %v", err)
}
@@ -79,7 +79,7 @@ func TestBzzrGetPath(t *testing.T) {
var resp *http.Response
var respbody []byte
- url := srv.URL + "/bzzr:/"
+ url := srv.URL + "/bzz-raw:/"
if k[:] != "" {
url += common.ToHex(key[0])[2:] + "/" + k[1:] + "?content_type=text/plain"
}
@@ -104,16 +104,106 @@ func TestBzzrGetPath(t *testing.T) {
}
}
+ for _, c := range []struct {
+ path string
+ json string
+ html string
+ }{
+ {
+ path: "/",
+ json: `{"common_prefixes":["a/"]}`,
+ html: "<!DOCTYPE html>\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/</title>\n</head>\n\n<body>\n <h1>Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/</h1>\n <hr>\n <table>\n <thead>\n <tr>\n\t<th>Path</th>\n\t<th>Type</th>\n\t<th>Size</th>\n </tr>\n </thead>\n\n <tbody>\n \n\t<tr>\n\t <td><a href=\"a/\">a/</a></td>\n\t <td>DIR</td>\n\t <td>-</td>\n\t</tr>\n \n\n \n </table>\n <hr>\n</body>\n",
+ },
+ {
+ path: "/a/",
+ json: `{"common_prefixes":["a/b/"],"entries":[{"hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","path":"a/a","mod_time":"0001-01-01T00:00:00Z"}]}`,
+ html: "<!DOCTYPE html>\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/</title>\n</head>\n\n<body>\n <h1>Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/</h1>\n <hr>\n <table>\n <thead>\n <tr>\n\t<th>Path</th>\n\t<th>Type</th>\n\t<th>Size</th>\n </tr>\n </thead>\n\n <tbody>\n \n\t<tr>\n\t <td><a href=\"b/\">b/</a></td>\n\t <td>DIR</td>\n\t <td>-</td>\n\t</tr>\n \n\n \n\t<tr>\n\t <td><a href=\"a\">a</a></td>\n\t <td></td>\n\t <td>0</td>\n\t</tr>\n \n </table>\n <hr>\n</body>\n",
+ },
+ {
+ 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: "<!DOCTYPE html>\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <title>Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/b/</title>\n</head>\n\n<body>\n <h1>Swarm index of bzz:/262e5c08c03c2789b6daef487dfa14b4d132f5340d781a3ecb1d5122ab65640c/a/b/</h1>\n <hr>\n <table>\n <thead>\n <tr>\n\t<th>Path</th>\n\t<th>Type</th>\n\t<th>Size</th>\n </tr>\n </thead>\n\n <tbody>\n \n\n \n\t<tr>\n\t <td><a href=\"b\">b</a></td>\n\t <td></td>\n\t <td>0</td>\n\t</tr>\n \n\t<tr>\n\t <td><a href=\"c\">c</a></td>\n\t <td></td>\n\t <td>0</td>\n\t</tr>\n \n </table>\n <hr>\n</body>\n",
+ },
+ {
+ path: "/x",
+ },
+ {
+ path: "",
+ },
+ } {
+ k := c.path
+ url := srv.URL + "/bzz-list:/"
+ if k[:] != "" {
+ url += common.ToHex(key[0])[2:] + "/" + k[1:]
+ }
+ t.Run("json list "+c.path, func(t *testing.T) {
+ resp, err := http.Get(url)
+ if err != nil {
+ t.Fatalf("HTTP request: %v", err)
+ }
+ defer resp.Body.Close()
+ respbody, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ t.Fatalf("Read response body: %v", err)
+ }
+
+ body := strings.TrimSpace(string(respbody))
+ if body != c.json {
+ isexpectedfailrequest := false
+
+ for _, r := range expectedfailrequests {
+ if k[:] == r {
+ isexpectedfailrequest = true
+ }
+ }
+ if !isexpectedfailrequest {
+ t.Errorf("Response list body %q does not match, expected: %v, got %v", k, c.json, body)
+ }
+ }
+ })
+ t.Run("html list "+c.path, func(t *testing.T) {
+ req, err := http.NewRequest(http.MethodGet, url, nil)
+ if err != nil {
+ t.Fatalf("New request: %v", err)
+ }
+ req.Header.Set("Accept", "text/html")
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ t.Fatalf("HTTP request: %v", err)
+ }
+ defer resp.Body.Close()
+ respbody, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ t.Fatalf("Read response body: %v", err)
+ }
+
+ if string(respbody) != c.html {
+ isexpectedfailrequest := false
+
+ for _, r := range expectedfailrequests {
+ if k[:] == r {
+ isexpectedfailrequest = true
+ }
+ }
+ if !isexpectedfailrequest {
+ t.Errorf("Response list body %q does not match, expected: %q, got %q", k, c.html, string(respbody))
+ }
+ }
+ })
+ }
+
nonhashtests := []string{
srv.URL + "/bzz:/name",
- srv.URL + "/bzzi:/nonhash",
- srv.URL + "/bzzr:/nonhash",
+ srv.URL + "/bzz-immutable:/nonhash",
+ srv.URL + "/bzz-raw:/nonhash",
+ srv.URL + "/bzz-list:/nonhash",
}
nonhashresponses := []string{
"error resolving name: no DNS to resolve name: &#34;name&#34;",
"error resolving nonhash: immutable address not a content hash: &#34;nonhash&#34;",
"error resolving nonhash: no DNS to resolve name: &#34;nonhash&#34;",
+ "error resolving nonhash: no DNS to resolve name: &#34;nonhash&#34;",
}
for i, url := range nonhashtests {