diff options
author | Elad Nachmias <theman@elad.im> | 2018-02-27 21:32:38 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-02-27 21:32:38 +0800 |
commit | b574b5776695eb30e034fd8c7a468b3f03d4c6b9 (patch) | |
tree | 307825284d30437ff656ecbc5feeb8846d2b075e /swarm/api/http/error_test.go | |
parent | 18bb3da55e4d2f6b5e9142b7f5d5bd76f2fb78b0 (diff) | |
download | go-tangerine-b574b5776695eb30e034fd8c7a468b3f03d4c6b9.tar.gz go-tangerine-b574b5776695eb30e034fd8c7a468b3f03d4c6b9.tar.zst go-tangerine-b574b5776695eb30e034fd8c7a468b3f03d4c6b9.zip |
swarm: give correct error on 0x hash prefix (#16195)
- added a case error struct that contains information about certain error cases
in which we would like to output more information to the client
- added a validation method that iterates and adds the information that is
stored in the error cases
Diffstat (limited to 'swarm/api/http/error_test.go')
-rw-r--r-- | swarm/api/http/error_test.go | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/swarm/api/http/error_test.go b/swarm/api/http/error_test.go index c2c8b908b..dc545722e 100644 --- a/swarm/api/http/error_test.go +++ b/swarm/api/http/error_test.go @@ -18,12 +18,13 @@ package http_test import ( "encoding/json" - "golang.org/x/net/html" "io/ioutil" "net/http" "strings" "testing" + "golang.org/x/net/html" + "github.com/ethereum/go-ethereum/swarm/testutil" ) @@ -96,8 +97,37 @@ func Test500Page(t *testing.T) { defer resp.Body.Close() respbody, err = ioutil.ReadAll(resp.Body) - if resp.StatusCode != 500 || !strings.Contains(string(respbody), "500") { - t.Fatalf("Invalid Status Code received, expected 500, got %d", resp.StatusCode) + if resp.StatusCode != 404 { + t.Fatalf("Invalid Status Code received, expected 404, got %d", resp.StatusCode) + } + + _, err = html.Parse(strings.NewReader(string(respbody))) + if err != nil { + t.Fatalf("HTML validation failed for error page returned!") + } +} +func Test500PageWith0xHashPrefix(t *testing.T) { + srv := testutil.NewTestSwarmServer(t) + defer srv.Close() + + var resp *http.Response + var respbody []byte + + url := srv.URL + "/bzz:/0xthisShouldFailWith500CodeAndAHelpfulMessage" + 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 resp.StatusCode != 404 { + t.Fatalf("Invalid Status Code received, expected 404, got %d", resp.StatusCode) + } + + if !strings.Contains(string(respbody), "The requested hash seems to be prefixed with") { + t.Fatalf("Did not receive the expected error message") } _, err = html.Parse(strings.NewReader(string(respbody))) @@ -127,8 +157,8 @@ func TestJsonResponse(t *testing.T) { defer resp.Body.Close() respbody, err = ioutil.ReadAll(resp.Body) - if resp.StatusCode != 500 { - t.Fatalf("Invalid Status Code received, expected 500, got %d", resp.StatusCode) + if resp.StatusCode != 404 { + t.Fatalf("Invalid Status Code received, expected 404, got %d", resp.StatusCode) } if !isJSON(string(respbody)) { |