mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Added tests to check large read guards
This commit is contained in:
parent
1d76d3ca2e
commit
0842dad38e
2 changed files with 31 additions and 7 deletions
|
@ -178,6 +178,16 @@ func TestBroker(t *testing.T) {
|
||||||
proxyAnswers(ctx, w, r)
|
proxyAnswers(ctx, w, r)
|
||||||
So(w.Code, ShouldEqual, http.StatusBadRequest)
|
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)
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/keroserene/go-webrtc"
|
"github.com/keroserene/go-webrtc"
|
||||||
|
@ -33,11 +32,14 @@ func (m *MockResponse) Read(p []byte) (int, error) {
|
||||||
}
|
}
|
||||||
func (m *MockResponse) Close() error { return nil }
|
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.
|
// Just returns a response with fake SDP answer.
|
||||||
func (m *MockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
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{
|
r := &http.Response{
|
||||||
StatusCode: m.statusOverride,
|
StatusCode: m.statusOverride,
|
||||||
Body: s,
|
Body: s,
|
||||||
|
@ -263,7 +265,10 @@ func TestSnowflakeClient(t *testing.T) {
|
||||||
|
|
||||||
Convey("Rendezvous", t, func() {
|
Convey("Rendezvous", t, func() {
|
||||||
webrtc.SetLoggingVerbosity(0)
|
webrtc.SetLoggingVerbosity(0)
|
||||||
transport := &MockTransport{http.StatusOK}
|
transport := &MockTransport{
|
||||||
|
http.StatusOK,
|
||||||
|
[]byte(`{"type":"answer","sdp":"fake"}`),
|
||||||
|
}
|
||||||
fakeOffer := webrtc.DeserializeSessionDescription("test")
|
fakeOffer := webrtc.DeserializeSessionDescription("test")
|
||||||
|
|
||||||
Convey("Construct BrokerChannel with no front domain", func() {
|
Convey("Construct BrokerChannel with no front domain", func() {
|
||||||
|
@ -291,7 +296,7 @@ func TestSnowflakeClient(t *testing.T) {
|
||||||
|
|
||||||
Convey("BrokerChannel.Negotiate fails with 503", func() {
|
Convey("BrokerChannel.Negotiate fails with 503", func() {
|
||||||
b := NewBrokerChannel("test.broker", "",
|
b := NewBrokerChannel("test.broker", "",
|
||||||
&MockTransport{http.StatusServiceUnavailable})
|
&MockTransport{http.StatusServiceUnavailable, []byte("\n")})
|
||||||
answer, err := b.Negotiate(fakeOffer)
|
answer, err := b.Negotiate(fakeOffer)
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
So(answer, ShouldBeNil)
|
So(answer, ShouldBeNil)
|
||||||
|
@ -300,16 +305,25 @@ func TestSnowflakeClient(t *testing.T) {
|
||||||
|
|
||||||
Convey("BrokerChannel.Negotiate fails with 400", func() {
|
Convey("BrokerChannel.Negotiate fails with 400", func() {
|
||||||
b := NewBrokerChannel("test.broker", "",
|
b := NewBrokerChannel("test.broker", "",
|
||||||
&MockTransport{http.StatusBadRequest})
|
&MockTransport{http.StatusBadRequest, []byte("\n")})
|
||||||
answer, err := b.Negotiate(fakeOffer)
|
answer, err := b.Negotiate(fakeOffer)
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
So(answer, ShouldBeNil)
|
So(answer, ShouldBeNil)
|
||||||
So(err.Error(), ShouldResemble, BrokerError400)
|
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() {
|
Convey("BrokerChannel.Negotiate fails with unexpected error", func() {
|
||||||
b := NewBrokerChannel("test.broker", "",
|
b := NewBrokerChannel("test.broker", "",
|
||||||
&MockTransport{123})
|
&MockTransport{123, []byte("")})
|
||||||
answer, err := b.Negotiate(fakeOffer)
|
answer, err := b.Negotiate(fakeOffer)
|
||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
So(answer, ShouldBeNil)
|
So(answer, ShouldBeNil)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue