mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
rendezvous / BrokerChannel tests for client
This commit is contained in:
parent
5edac195f6
commit
5aae41c901
2 changed files with 63 additions and 5 deletions
|
@ -4,6 +4,10 @@ import (
|
|||
"bytes"
|
||||
"github.com/keroserene/go-webrtc"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"net/http"
|
||||
// "net/http/httptest"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -21,6 +25,29 @@ func (*MockDataChannel) Close() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type MockResponse struct{}
|
||||
|
||||
func (m *MockResponse) Read(p []byte) (int, error) {
|
||||
p = []byte(`{"type":"answer","sdp":"fake"}`)
|
||||
return 0, nil
|
||||
}
|
||||
func (m *MockResponse) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type MockTransport struct {
|
||||
}
|
||||
|
||||
// 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"}`))
|
||||
r := &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: s,
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func TestConnect(t *testing.T) {
|
||||
Convey("Snowflake", t, func() {
|
||||
|
||||
|
@ -72,6 +99,35 @@ func TestConnect(t *testing.T) {
|
|||
// TODO
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Convey("Rendezvous", t, func() {
|
||||
|
||||
Convey("BrokerChannel with no front domain", func() {
|
||||
b := NewBrokerChannel("test.broker", "")
|
||||
So(b.url, ShouldNotBeNil)
|
||||
So(b.url.Path, ShouldResemble, "test.broker")
|
||||
So(b.transport, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("BrokerChannel with front domain", func() {
|
||||
b := NewBrokerChannel("test.broker", "front")
|
||||
So(b.url, ShouldNotBeNil)
|
||||
So(b.url.Path, ShouldResemble, "test.broker")
|
||||
So(b.url.Host, ShouldResemble, "front")
|
||||
So(b.transport, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("BrokerChannel Negotiate responds with answer", func() {
|
||||
b := NewBrokerChannel("test.broker", "")
|
||||
sdp := webrtc.DeserializeSessionDescription("test")
|
||||
// Replace transport with a mock.
|
||||
b.transport = &MockTransport{}
|
||||
answer, err := b.Negotiate(sdp)
|
||||
So(err, ShouldBeNil)
|
||||
So(answer, ShouldNotBeNil)
|
||||
So(answer.Sdp, ShouldResemble, "fake")
|
||||
})
|
||||
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,7 +20,8 @@ type BrokerChannel struct {
|
|||
// different from the host name in URL).
|
||||
Host string
|
||||
url *url.URL
|
||||
transport http.Transport // Used to make all requests.
|
||||
// transport http.Transport // Used to make all requests.
|
||||
transport http.RoundTripper // Used to make all requests.
|
||||
}
|
||||
|
||||
// Construct a new BrokerChannel, where:
|
||||
|
@ -41,8 +42,9 @@ func NewBrokerChannel(broker string, front string) *BrokerChannel {
|
|||
// We make a copy of DefaultTransport because we want the default Dial
|
||||
// and TLSHandshakeTimeout settings. But we want to disable the default
|
||||
// ProxyFromEnvironment setting.
|
||||
bc.transport = *http.DefaultTransport.(*http.Transport)
|
||||
bc.transport.Proxy = nil
|
||||
transport := http.DefaultTransport.(*http.Transport)
|
||||
transport.Proxy = nil
|
||||
bc.transport = transport
|
||||
return bc
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue