Loading broker/snowflake-broker_test.go +10 −0 Original line number Diff line number Diff line Loading @@ -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) }) }) }) Loading client/lib/lib_test.go +21 −7 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ import ( "io/ioutil" "net" "net/http" "strings" "testing" "github.com/keroserene/go-webrtc" Loading @@ -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, Loading Loading @@ -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() { Loading Loading @@ -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) Loading @@ -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) Loading Loading
broker/snowflake-broker_test.go +10 −0 Original line number Diff line number Diff line Loading @@ -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) }) }) }) Loading
client/lib/lib_test.go +21 −7 Original line number Diff line number Diff line Loading @@ -6,7 +6,6 @@ import ( "io/ioutil" "net" "net/http" "strings" "testing" "github.com/keroserene/go-webrtc" Loading @@ -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, Loading Loading @@ -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() { Loading Loading @@ -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) Loading @@ -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) Loading