aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/api/http/server_test.go
diff options
context:
space:
mode:
authorJanoš Guljaš <janos@users.noreply.github.com>2017-12-21 20:47:10 +0800
committerPéter Szilágyi <peterke@gmail.com>2017-12-21 20:47:10 +0800
commit542d51895f54b9f869379cf4ad5549c82e525711 (patch)
tree4f485778b2c28de2d7c4ab446407e7f01eab9b20 /swarm/api/http/server_test.go
parent5258785c81959109138ebeca613f12c277188abc (diff)
downloaddexon-542d51895f54b9f869379cf4ad5549c82e525711.tar
dexon-542d51895f54b9f869379cf4ad5549c82e525711.tar.gz
dexon-542d51895f54b9f869379cf4ad5549c82e525711.tar.bz2
dexon-542d51895f54b9f869379cf4ad5549c82e525711.tar.lz
dexon-542d51895f54b9f869379cf4ad5549c82e525711.tar.xz
dexon-542d51895f54b9f869379cf4ad5549c82e525711.tar.zst
dexon-542d51895f54b9f869379cf4ad5549c82e525711.zip
swarm/api: url scheme bzz-hash to get hashes of swarm content (#15238) (#15715)
* swarm/api: url scheme bzz-hash to get hashes of swarm content (#15238) Update URI to support bzz-hash scheme and handle such HTTP requests by responding with hash of the content as a text/plain response. * swarm/api: return hash of the content for bzz-hash:// requests * swarm/api: revert "return hash of the content for bzz-hash:// requests" Return hashes of the content that would be returned by bzz-raw request. * swarm/api/http: handle error in TestBzzGetPath * swarm/api: remove extra blank line in comment
Diffstat (limited to 'swarm/api/http/server_test.go')
-rw-r--r--swarm/api/http/server_test.go36
1 files changed, 35 insertions, 1 deletions
diff --git a/swarm/api/http/server_test.go b/swarm/api/http/server_test.go
index dbbfa3b07..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
@@ -104,6 +104,38 @@ 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
@@ -197,6 +229,7 @@ func TestBzzrGetPath(t *testing.T) {
srv.URL + "/bzz-immutable:/nonhash",
srv.URL + "/bzz-raw:/nonhash",
srv.URL + "/bzz-list:/nonhash",
+ srv.URL + "/bzz-hash:/nonhash",
}
nonhashresponses := []string{
@@ -204,6 +237,7 @@ func TestBzzrGetPath(t *testing.T) {
"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 {