aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/http_test.go
diff options
context:
space:
mode:
authorArmani Ferrante <armaniferrante@berkeley.edu>2017-11-17 20:07:11 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-11-17 20:07:11 +0800
commitc5b8569707cabe19f861cb67062c07598aff2aa1 (patch)
tree7dd031f6854f6900e7d1767fda97f0176adfd801 /rpc/http_test.go
parentb0190189a386d13eb2e8bbdb6d64d9ef8c0e572a (diff)
downloadgo-tangerine-c5b8569707cabe19f861cb67062c07598aff2aa1.tar
go-tangerine-c5b8569707cabe19f861cb67062c07598aff2aa1.tar.gz
go-tangerine-c5b8569707cabe19f861cb67062c07598aff2aa1.tar.bz2
go-tangerine-c5b8569707cabe19f861cb67062c07598aff2aa1.tar.lz
go-tangerine-c5b8569707cabe19f861cb67062c07598aff2aa1.tar.xz
go-tangerine-c5b8569707cabe19f861cb67062c07598aff2aa1.tar.zst
go-tangerine-c5b8569707cabe19f861cb67062c07598aff2aa1.zip
rpc: disallow PUT and DELETE on HTTP (#15501)
Fixes #15493
Diffstat (limited to 'rpc/http_test.go')
-rw-r--r--rpc/http_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/rpc/http_test.go b/rpc/http_test.go
new file mode 100644
index 000000000..f4afd5216
--- /dev/null
+++ b/rpc/http_test.go
@@ -0,0 +1,40 @@
+package rpc
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+)
+
+func TestHTTPErrorResponseWithDelete(t *testing.T) {
+ httpErrorResponseTest(t, "DELETE", contentType, "", http.StatusMethodNotAllowed)
+}
+
+func TestHTTPErrorResponseWithPut(t *testing.T) {
+ httpErrorResponseTest(t, "PUT", contentType, "", http.StatusMethodNotAllowed)
+}
+
+func TestHTTPErrorResponseWithMaxContentLength(t *testing.T) {
+ body := make([]rune, maxHTTPRequestContentLength+1, maxHTTPRequestContentLength+1)
+ httpErrorResponseTest(t,
+ "POST", contentType, string(body), http.StatusRequestEntityTooLarge)
+}
+
+func TestHTTPErrorResponseWithEmptyContentType(t *testing.T) {
+ httpErrorResponseTest(t, "POST", "", "", http.StatusUnsupportedMediaType)
+}
+
+func TestHTTPErrorResponseWithValidRequest(t *testing.T) {
+ httpErrorResponseTest(t, "POST", contentType, "", 0)
+}
+
+func httpErrorResponseTest(t *testing.T,
+ method, contentType, body string, expectedResponse int) {
+
+ request := httptest.NewRequest(method, "http://url.com", strings.NewReader(body))
+ request.Header.Set("content-type", contentType)
+ if response, _ := httpErrorResponse(request); response != expectedResponse {
+ t.Fatalf("response code should be %d not %d", expectedResponse, response)
+ }
+}