aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api
diff options
context:
space:
mode:
authorJanos Guljas <janos@resenje.org>2018-02-09 19:23:30 +0800
committerJanos Guljas <janos@resenje.org>2018-02-22 21:23:17 +0800
commita3a07350dcef0ba39829a20d8ddba4bd3463d293 (patch)
tree100f2515cadd92105537a12e6981fab2193435ee /swarm/api
parent820cf09c98706f71d4b02b6c25e62db15830f3fb (diff)
parent1a4e68721a901e86322631fed1191025a6d14c52 (diff)
downloaddexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar.gz
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.tar.zst
dexon-a3a07350dcef0ba39829a20d8ddba4bd3463d293.zip
swarm, cmd/swarm: Merge branch 'master' into multiple-ens-endpoints
Diffstat (limited to 'swarm/api')
-rw-r--r--swarm/api/api.go2
-rw-r--r--swarm/api/api_test.go2
-rw-r--r--swarm/api/client/client.go6
-rw-r--r--swarm/api/http/roundtripper.go4
-rw-r--r--swarm/api/http/server.go67
-rw-r--r--swarm/api/http/server_test.go134
-rw-r--r--swarm/api/http/templates.go2
-rw-r--r--swarm/api/uri.go33
-rw-r--r--swarm/api/uri_test.go86
9 files changed, 277 insertions, 59 deletions
diff --git a/swarm/api/api.go b/swarm/api/api.go
index c143d8a3f..fdf76d390 100644
--- a/swarm/api/api.go
+++ b/swarm/api/api.go
@@ -159,7 +159,7 @@ func (self *Api) Resolve(uri *URI) (storage.Key, error) {
// if the URI is immutable, check if the address is a hash
isHash := hashMatcher.MatchString(uri.Addr)
- if uri.Immutable() {
+ if uri.Immutable() || uri.DeprecatedImmutable() {
if !isHash {
return nil, fmt.Errorf("immutable address not a content hash: %q", uri.Addr)
}
diff --git a/swarm/api/api_test.go b/swarm/api/api_test.go
index dbe7c1dac..4ee26bd8a 100644
--- a/swarm/api/api_test.go
+++ b/swarm/api/api_test.go
@@ -216,7 +216,7 @@ func TestAPIResolve(t *testing.T) {
api := &Api{dns: x.dns}
uri := &URI{Addr: x.addr, Scheme: "bzz"}
if x.immutable {
- uri.Scheme = "bzzi"
+ uri.Scheme = "bzz-immutable"
}
res, err := api.Resolve(uri)
if err == nil {
diff --git a/swarm/api/client/client.go b/swarm/api/client/client.go
index 7952d3fb6..8165d52d7 100644
--- a/swarm/api/client/client.go
+++ b/swarm/api/client/client.go
@@ -57,7 +57,7 @@ func (c *Client) UploadRaw(r io.Reader, size int64) (string, error) {
if size <= 0 {
return "", errors.New("data size must be greater than zero")
}
- req, err := http.NewRequest("POST", c.Gateway+"/bzzr:/", r)
+ req, err := http.NewRequest("POST", c.Gateway+"/bzz-raw:/", r)
if err != nil {
return "", err
}
@@ -79,7 +79,7 @@ func (c *Client) UploadRaw(r io.Reader, size int64) (string, error) {
// DownloadRaw downloads raw data from swarm
func (c *Client) DownloadRaw(hash string) (io.ReadCloser, error) {
- uri := c.Gateway + "/bzzr:/" + hash
+ uri := c.Gateway + "/bzz-raw:/" + hash
res, err := http.DefaultClient.Get(uri)
if err != nil {
return nil, err
@@ -269,7 +269,7 @@ func (c *Client) DownloadManifest(hash string) (*api.Manifest, error) {
//
// where entries ending with "/" are common prefixes.
func (c *Client) List(hash, prefix string) (*api.ManifestList, error) {
- res, err := http.DefaultClient.Get(c.Gateway + "/bzz:/" + hash + "/" + prefix + "?list=true")
+ res, err := http.DefaultClient.Get(c.Gateway + "/bzz-list:/" + hash + "/" + prefix)
if err != nil {
return nil, err
}
diff --git a/swarm/api/http/roundtripper.go b/swarm/api/http/roundtripper.go
index 328177a21..019431771 100644
--- a/swarm/api/http/roundtripper.go
+++ b/swarm/api/http/roundtripper.go
@@ -35,8 +35,8 @@ import (
client := httpclient.New()
// for (private) swarm proxy running locally
client.RegisterScheme("bzz", &http.RoundTripper{Port: port})
-client.RegisterScheme("bzzi", &http.RoundTripper{Port: port})
-client.RegisterScheme("bzzr", &http.RoundTripper{Port: port})
+client.RegisterScheme("bzz-immutable", &http.RoundTripper{Port: port})
+client.RegisterScheme("bzz-raw", &http.RoundTripper{Port: port})
The port you give the Roundtripper is the port the swarm proxy is listening on.
If Host is left empty, localhost is assumed.
diff --git a/swarm/api/http/server.go b/swarm/api/http/server.go
index 65f6afab7..74341899d 100644
--- a/swarm/api/http/server.go
+++ b/swarm/api/http/server.go
@@ -86,7 +86,7 @@ type Request struct {
uri *api.URI
}
-// HandlePostRaw handles a POST request to a raw bzzr:/ URI, stores the request
+// HandlePostRaw handles a POST request to a raw bzz-raw:/ URI, stores the request
// body in swarm and returns the resulting storage key as a text/plain response
func (s *Server) HandlePostRaw(w http.ResponseWriter, r *Request) {
if r.uri.Path != "" {
@@ -290,9 +290,12 @@ func (s *Server) HandleDelete(w http.ResponseWriter, r *Request) {
fmt.Fprint(w, newKey)
}
-// HandleGetRaw handles a GET request to bzzr://<key> and responds with
-// the raw content stored at the given storage key
-func (s *Server) HandleGetRaw(w http.ResponseWriter, r *Request) {
+// HandleGet handles a GET request to
+// - bzz-raw://<key> and responds with the raw content stored at the
+// given storage key
+// - bzz-hash://<key> and responds with the hash of the content stored
+// at the given storage key as a text/plain response
+func (s *Server) HandleGet(w http.ResponseWriter, r *Request) {
key, err := s.api.Resolve(r.uri)
if err != nil {
s.Error(w, r, fmt.Errorf("error resolving %s: %s", r.uri.Addr, err))
@@ -345,15 +348,22 @@ func (s *Server) HandleGetRaw(w http.ResponseWriter, r *Request) {
return
}
- // allow the request to overwrite the content type using a query
- // parameter
- contentType := "application/octet-stream"
- if typ := r.URL.Query().Get("content_type"); typ != "" {
- contentType = typ
- }
- w.Header().Set("Content-Type", contentType)
+ switch {
+ case r.uri.Raw():
+ // allow the request to overwrite the content type using a query
+ // parameter
+ contentType := "application/octet-stream"
+ if typ := r.URL.Query().Get("content_type"); typ != "" {
+ contentType = typ
+ }
+ w.Header().Set("Content-Type", contentType)
- http.ServeContent(w, &r.Request, "", time.Now(), reader)
+ http.ServeContent(w, &r.Request, "", time.Now(), reader)
+ case r.uri.Hash():
+ w.Header().Set("Content-Type", "text/plain")
+ w.WriteHeader(http.StatusOK)
+ fmt.Fprint(w, key)
+ }
}
// HandleGetFiles handles a GET request to bzz:/<manifest> with an Accept
@@ -424,14 +434,13 @@ func (s *Server) HandleGetFiles(w http.ResponseWriter, r *Request) {
}
}
-// HandleGetList handles a GET request to bzz:/<manifest>/<path> which has
-// the "list" query parameter set to "true" and returns a list of all files
-// contained in <manifest> under <path> grouped into common prefixes using
-// "/" as a delimiter
+// HandleGetList handles a GET request to bzz-list:/<manifest>/<path> and returns
+// a list of all files contained in <manifest> under <path> grouped into
+// common prefixes using "/" as a delimiter
func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
// ensure the root path has a trailing slash so that relative URLs work
if r.uri.Path == "" && !strings.HasSuffix(r.URL.Path, "/") {
- http.Redirect(w, &r.Request, r.URL.Path+"/?list=true", http.StatusMovedPermanently)
+ http.Redirect(w, &r.Request, r.URL.Path+"/", http.StatusMovedPermanently)
return
}
@@ -453,7 +462,11 @@ func (s *Server) HandleGetList(w http.ResponseWriter, r *Request) {
if strings.Contains(r.Header.Get("Accept"), "text/html") {
w.Header().Set("Content-Type", "text/html")
err := htmlListTemplate.Execute(w, &htmlListData{
- URI: r.uri,
+ URI: &api.URI{
+ Scheme: "bzz",
+ Addr: r.uri.Addr,
+ Path: r.uri.Path,
+ },
List: &list,
})
if err != nil {
@@ -589,7 +602,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "POST":
- if uri.Raw() {
+ if uri.Raw() || uri.DeprecatedRaw() {
s.HandlePostRaw(w, req)
} else {
s.HandlePostFiles(w, req)
@@ -601,7 +614,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// new manifest leaving the existing one intact, so it isn't
// strictly a traditional PUT request which replaces content
// at a URI, and POST is more ubiquitous)
- if uri.Raw() {
+ if uri.Raw() || uri.DeprecatedRaw() {
ShowError(w, r, fmt.Sprintf("No PUT to %s allowed.", uri), http.StatusBadRequest)
return
} else {
@@ -609,25 +622,25 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
case "DELETE":
- if uri.Raw() {
+ if uri.Raw() || uri.DeprecatedRaw() {
ShowError(w, r, fmt.Sprintf("No DELETE to %s allowed.", uri), http.StatusBadRequest)
return
}
s.HandleDelete(w, req)
case "GET":
- if uri.Raw() {
- s.HandleGetRaw(w, req)
+ if uri.Raw() || uri.Hash() || uri.DeprecatedRaw() {
+ s.HandleGet(w, req)
return
}
- if r.Header.Get("Accept") == "application/x-tar" {
- s.HandleGetFiles(w, req)
+ if uri.List() {
+ s.HandleGetList(w, req)
return
}
- if r.URL.Query().Get("list") == "true" {
- s.HandleGetList(w, req)
+ if r.Header.Get("Accept") == "application/x-tar" {
+ s.HandleGetFiles(w, req)
return
}
diff --git a/swarm/api/http/server_test.go b/swarm/api/http/server_test.go
index ffeaf6e0d..305d5cf7d 100644
--- a/swarm/api/http/server_test.go
+++ b/swarm/api/http/server_test.go
@@ -33,7 +33,7 @@ import (
"github.com/ethereum/go-ethereum/swarm/testutil"
)
-func TestBzzrGetPath(t *testing.T) {
+func TestBzzGetPath(t *testing.T) {
var err error
@@ -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,140 @@ func TestBzzrGetPath(t *testing.T) {
}
}
+ for k, v := range testrequests {
+ var resp *http.Response
+ var respbody []byte
+
+ url := srv.URL + "/bzz-hash:/"
+ if k[:] != "" {
+ url += common.ToHex(key[0])[2:] + "/" + k[1:]
+ }
+ resp, err = http.Get(url)
+ if err != nil {
+ t.Fatalf("Request failed: %v", err)
+ }
+ defer resp.Body.Close()
+ respbody, err = ioutil.ReadAll(resp.Body)
+ if err != nil {
+ t.Fatalf("Read request body: %v", err)
+ }
+
+ if string(respbody) != key[v].String() {
+ isexpectedfailrequest := false
+
+ for _, r := range expectedfailrequests {
+ if k[:] == r {
+ isexpectedfailrequest = true
+ }
+ }
+ if !isexpectedfailrequest {
+ t.Fatalf("Response body does not match, expected: %v, got %v", key[v], string(respbody))
+ }
+ }
+ }
+
+ 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",
+ srv.URL + "/bzz-hash:/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;",
+ "error resolving nonhash: no DNS to resolve name: &#34;nonhash&#34;",
}
for i, url := range nonhashtests {
diff --git a/swarm/api/http/templates.go b/swarm/api/http/templates.go
index 9ae434a7e..53ce7b5a2 100644
--- a/swarm/api/http/templates.go
+++ b/swarm/api/http/templates.go
@@ -52,7 +52,7 @@ var htmlListTemplate = template.Must(template.New("html-list").Funcs(template.Fu
<tbody>
{{ range .List.CommonPrefixes }}
<tr>
- <td><a href="{{ basename . }}/?list=true">{{ basename . }}/</a></td>
+ <td><a href="{{ basename . }}/">{{ basename . }}/</a></td>
<td>DIR</td>
<td>-</td>
</tr>
diff --git a/swarm/api/uri.go b/swarm/api/uri.go
index caed4212d..d8aafedf4 100644
--- a/swarm/api/uri.go
+++ b/swarm/api/uri.go
@@ -26,10 +26,18 @@ import (
type URI struct {
// Scheme has one of the following values:
//
- // * bzz - an entry in a swarm manifest
+ // * bzz - an entry in a swarm manifest
+ // * bzz-raw - raw swarm content
+ // * bzz-immutable - immutable URI of an entry in a swarm manifest
+ // (address is not resolved)
+ // * bzz-list - list of all files contained in a swarm manifest
+ //
+ // Deprecated Schemes:
// * bzzr - raw swarm content
// * bzzi - immutable URI of an entry in a swarm manifest
// (address is not resolved)
+ // * bzz-hash - hash of swarm content
+ //
Scheme string
// Addr is either a hexadecimal storage key or it an address which
@@ -50,7 +58,8 @@ type URI struct {
// * <scheme>://<addr>
// * <scheme>://<addr>/<path>
//
-// with scheme one of bzz, bzzr or bzzi
+// with scheme one of bzz, bzz-raw, bzz-immutable, bzz-list or bzz-hash
+// or deprecated ones bzzr and bzzi
func Parse(rawuri string) (*URI, error) {
u, err := url.Parse(rawuri)
if err != nil {
@@ -60,7 +69,7 @@ func Parse(rawuri string) (*URI, error) {
// check the scheme is valid
switch uri.Scheme {
- case "bzz", "bzzi", "bzzr":
+ case "bzz", "bzz-raw", "bzz-immutable", "bzz-list", "bzz-hash", "bzzr", "bzzi":
default:
return nil, fmt.Errorf("unknown scheme %q", u.Scheme)
}
@@ -84,13 +93,29 @@ func Parse(rawuri string) (*URI, error) {
}
func (u *URI) Raw() bool {
- return u.Scheme == "bzzr"
+ return u.Scheme == "bzz-raw"
}
func (u *URI) Immutable() bool {
+ return u.Scheme == "bzz-immutable"
+}
+
+func (u *URI) List() bool {
+ return u.Scheme == "bzz-list"
+}
+
+func (u *URI) DeprecatedRaw() bool {
+ return u.Scheme == "bzzr"
+}
+
+func (u *URI) DeprecatedImmutable() bool {
return u.Scheme == "bzzi"
}
+func (u *URI) Hash() bool {
+ return u.Scheme == "bzz-hash"
+}
+
func (u *URI) String() string {
return u.Scheme + ":/" + u.Addr + "/" + u.Path
}
diff --git a/swarm/api/uri_test.go b/swarm/api/uri_test.go
index 7d4160601..137b4505d 100644
--- a/swarm/api/uri_test.go
+++ b/swarm/api/uri_test.go
@@ -23,11 +23,15 @@ import (
func TestParseURI(t *testing.T) {
type test struct {
- uri string
- expectURI *URI
- expectErr bool
- expectRaw bool
- expectImmutable bool
+ uri string
+ expectURI *URI
+ expectErr bool
+ expectRaw bool
+ expectImmutable bool
+ expectList bool
+ expectHash bool
+ expectDeprecatedRaw bool
+ expectDeprecatedImmutable bool
}
tests := []test{
{
@@ -47,13 +51,13 @@ func TestParseURI(t *testing.T) {
expectURI: &URI{Scheme: "bzz"},
},
{
- uri: "bzzi:",
- expectURI: &URI{Scheme: "bzzi"},
+ uri: "bzz-immutable:",
+ expectURI: &URI{Scheme: "bzz-immutable"},
expectImmutable: true,
},
{
- uri: "bzzr:",
- expectURI: &URI{Scheme: "bzzr"},
+ uri: "bzz-raw:",
+ expectURI: &URI{Scheme: "bzz-raw"},
expectRaw: true,
},
{
@@ -69,18 +73,18 @@ func TestParseURI(t *testing.T) {
expectURI: &URI{Scheme: "bzz", Addr: "abc123", Path: "path/to/entry"},
},
{
- uri: "bzzr:/",
- expectURI: &URI{Scheme: "bzzr"},
+ uri: "bzz-raw:/",
+ expectURI: &URI{Scheme: "bzz-raw"},
expectRaw: true,
},
{
- uri: "bzzr:/abc123",
- expectURI: &URI{Scheme: "bzzr", Addr: "abc123"},
+ uri: "bzz-raw:/abc123",
+ expectURI: &URI{Scheme: "bzz-raw", Addr: "abc123"},
expectRaw: true,
},
{
- uri: "bzzr:/abc123/path/to/entry",
- expectURI: &URI{Scheme: "bzzr", Addr: "abc123", Path: "path/to/entry"},
+ uri: "bzz-raw:/abc123/path/to/entry",
+ expectURI: &URI{Scheme: "bzz-raw", Addr: "abc123", Path: "path/to/entry"},
expectRaw: true,
},
{
@@ -95,6 +99,46 @@ func TestParseURI(t *testing.T) {
uri: "bzz://abc123/path/to/entry",
expectURI: &URI{Scheme: "bzz", Addr: "abc123", Path: "path/to/entry"},
},
+ {
+ uri: "bzz-hash:",
+ expectURI: &URI{Scheme: "bzz-hash"},
+ expectHash: true,
+ },
+ {
+ uri: "bzz-hash:/",
+ expectURI: &URI{Scheme: "bzz-hash"},
+ expectHash: true,
+ },
+ {
+ uri: "bzz-list:",
+ expectURI: &URI{Scheme: "bzz-list"},
+ expectList: true,
+ },
+ {
+ uri: "bzz-list:/",
+ expectURI: &URI{Scheme: "bzz-list"},
+ expectList: true,
+ },
+ {
+ uri: "bzzr:",
+ expectURI: &URI{Scheme: "bzzr"},
+ expectDeprecatedRaw: true,
+ },
+ {
+ uri: "bzzr:/",
+ expectURI: &URI{Scheme: "bzzr"},
+ expectDeprecatedRaw: true,
+ },
+ {
+ uri: "bzzi:",
+ expectURI: &URI{Scheme: "bzzi"},
+ expectDeprecatedImmutable: true,
+ },
+ {
+ uri: "bzzi:/",
+ expectURI: &URI{Scheme: "bzzi"},
+ expectDeprecatedImmutable: true,
+ },
}
for _, x := range tests {
actual, err := Parse(x.uri)
@@ -116,5 +160,17 @@ func TestParseURI(t *testing.T) {
if actual.Immutable() != x.expectImmutable {
t.Fatalf("expected %s immutable to be %t, got %t", x.uri, x.expectImmutable, actual.Immutable())
}
+ if actual.List() != x.expectList {
+ t.Fatalf("expected %s list to be %t, got %t", x.uri, x.expectList, actual.List())
+ }
+ if actual.Hash() != x.expectHash {
+ t.Fatalf("expected %s hash to be %t, got %t", x.uri, x.expectHash, actual.Hash())
+ }
+ if actual.DeprecatedRaw() != x.expectDeprecatedRaw {
+ t.Fatalf("expected %s deprecated raw to be %t, got %t", x.uri, x.expectDeprecatedRaw, actual.DeprecatedRaw())
+ }
+ if actual.DeprecatedImmutable() != x.expectDeprecatedImmutable {
+ t.Fatalf("expected %s deprecated immutable to be %t, got %t", x.uri, x.expectDeprecatedImmutable, actual.DeprecatedImmutable())
+ }
}
}