mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
test(client): add test for BrokerChannel
This commit is contained in:
parent
2bbd4d0643
commit
78f4b9dbc5
1 changed files with 51 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -13,11 +14,13 @@ import (
|
||||||
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
"github.com/aws/aws-sdk-go-v2/service/sqs"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/pion/webrtc/v3"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/amp"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/amp"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/messages"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/nat"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/nat"
|
||||||
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/sqsclient"
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/sqsclient"
|
||||||
|
"gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/v2/common/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mockTransport's RoundTrip method returns a response with a fake status and
|
// mockTransport's RoundTrip method returns a response with a fake status and
|
||||||
|
@ -386,3 +389,51 @@ func TestSQSRendezvous(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBrokerChannel(t *testing.T) {
|
||||||
|
Convey("Requests a proxy and handles response", t, func() {
|
||||||
|
answerSdp := &webrtc.SessionDescription{
|
||||||
|
Type: webrtc.SDPTypeAnswer,
|
||||||
|
SDP: "test",
|
||||||
|
}
|
||||||
|
answerSdpStr, _ := util.SerializeSessionDescription(answerSdp)
|
||||||
|
serverResponse, _ := (&messages.ClientPollResponse{
|
||||||
|
Answer: answerSdpStr,
|
||||||
|
}).EncodePollResponse()
|
||||||
|
|
||||||
|
offerSdp := &webrtc.SessionDescription{
|
||||||
|
Type: webrtc.SDPTypeOffer,
|
||||||
|
SDP: "test",
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBodyChan := make(chan []byte)
|
||||||
|
mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
body, _ := io.ReadAll(r.Body)
|
||||||
|
go func() {
|
||||||
|
requestBodyChan <- body
|
||||||
|
}()
|
||||||
|
w.Write(serverResponse)
|
||||||
|
}))
|
||||||
|
defer mockServer.Close()
|
||||||
|
|
||||||
|
brokerChannel, err := newBrokerChannelFromConfig(ClientConfig{
|
||||||
|
BrokerURL: mockServer.URL,
|
||||||
|
BridgeFingerprint: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
||||||
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
brokerChannel.SetNATType(nat.NATRestricted)
|
||||||
|
|
||||||
|
answerSdpReturned, err := brokerChannel.Negotiate(offerSdp)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(answerSdpReturned, ShouldEqual, answerSdp)
|
||||||
|
|
||||||
|
body := <-requestBodyChan
|
||||||
|
pollReq, err := messages.DecodeClientPollRequest(body)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(pollReq.Fingerprint, ShouldEqual, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
|
||||||
|
So(pollReq.NAT, ShouldEqual, nat.NATRestricted)
|
||||||
|
requestSdp, err := util.DeserializeSessionDescription(pollReq.Offer)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(requestSdp, ShouldEqual, offerSdp)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue