[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Added tests to check large read guards



commit 0842dad38e6cfd464166f16ed8088b02055714e3
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date:   Fri May 10 15:39:05 2019 -0400

    Added tests to check large read guards
---
 broker/snowflake-broker_test.go | 10 ++++++++++
 client/lib/lib_test.go          | 28 +++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/broker/snowflake-broker_test.go b/broker/snowflake-broker_test.go
index 0d50035..03aa2b4 100644
--- a/broker/snowflake-broker_test.go
+++ b/broker/snowflake-broker_test.go
@@ -178,6 +178,16 @@ func TestBroker(t *testing.T) {
 				proxyAnswers(ctx, w, r)
 				So(w.Code, ShouldEqual, http.StatusBadRequest)
 			})
+
+			Convey("with error if the proxy writes too much data", func() {
+				data := bytes.NewReader(make([]byte, 100001, 100001))
+				r, err := http.NewRequest("POST", "snowflake.broker/answer", data)
+				r.Header.Set("X-Session-ID", "test")
+				So(err, ShouldBeNil)
+				proxyAnswers(ctx, w, r)
+				So(w.Code, ShouldEqual, http.StatusBadRequest)
+			})
+
 		})
 	})
 
diff --git a/client/lib/lib_test.go b/client/lib/lib_test.go
index 5a9a2e5..4f74cb3 100644
--- a/client/lib/lib_test.go
+++ b/client/lib/lib_test.go
@@ -6,7 +6,6 @@ import (
 	"io/ioutil"
 	"net"
 	"net/http"
-	"strings"
 	"testing"
 
 	"github.com/keroserene/go-webrtc"
@@ -33,11 +32,14 @@ func (m *MockResponse) Read(p []byte) (int, error) {
 }
 func (m *MockResponse) Close() error { return nil }
 
-type MockTransport struct{ statusOverride int }
+type MockTransport struct {
+	statusOverride int
+	body           []byte
+}
 
 // Just returns a response with fake SDP answer.
 func (m *MockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
-	s := ioutil.NopCloser(strings.NewReader(`{"type":"answer","sdp":"fake"}`))
+	s := ioutil.NopCloser(bytes.NewReader(m.body))
 	r := &http.Response{
 		StatusCode: m.statusOverride,
 		Body:       s,
@@ -263,7 +265,10 @@ func TestSnowflakeClient(t *testing.T) {
 
 	Convey("Rendezvous", t, func() {
 		webrtc.SetLoggingVerbosity(0)
-		transport := &MockTransport{http.StatusOK}
+		transport := &MockTransport{
+			http.StatusOK,
+			[]byte(`{"type":"answer","sdp":"fake"}`),
+		}
 		fakeOffer := webrtc.DeserializeSessionDescription("test")
 
 		Convey("Construct BrokerChannel with no front domain", func() {
@@ -291,7 +296,7 @@ func TestSnowflakeClient(t *testing.T) {
 
 		Convey("BrokerChannel.Negotiate fails with 503", func() {
 			b := NewBrokerChannel("test.broker", "",
-				&MockTransport{http.StatusServiceUnavailable})
+				&MockTransport{http.StatusServiceUnavailable, []byte("\n")})
 			answer, err := b.Negotiate(fakeOffer)
 			So(err, ShouldNotBeNil)
 			So(answer, ShouldBeNil)
@@ -300,16 +305,25 @@ func TestSnowflakeClient(t *testing.T) {
 
 		Convey("BrokerChannel.Negotiate fails with 400", func() {
 			b := NewBrokerChannel("test.broker", "",
-				&MockTransport{http.StatusBadRequest})
+				&MockTransport{http.StatusBadRequest, []byte("\n")})
 			answer, err := b.Negotiate(fakeOffer)
 			So(err, ShouldNotBeNil)
 			So(answer, ShouldBeNil)
 			So(err.Error(), ShouldResemble, BrokerError400)
 		})
 
+		Convey("BrokerChannel.Negotiate fails with large read", func() {
+			b := NewBrokerChannel("test.broker", "",
+				&MockTransport{http.StatusOK, make([]byte, 100001, 100001)})
+			answer, err := b.Negotiate(fakeOffer)
+			So(err, ShouldNotBeNil)
+			So(answer, ShouldBeNil)
+			So(err.Error(), ShouldResemble, "unexpected EOF")
+		})
+
 		Convey("BrokerChannel.Negotiate fails with unexpected error", func() {
 			b := NewBrokerChannel("test.broker", "",
-				&MockTransport{123})
+				&MockTransport{123, []byte("")})
 			answer, err := b.Negotiate(fakeOffer)
 			So(err, ShouldNotBeNil)
 			So(answer, ShouldBeNil)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits