Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
The Tor Project
Anti-censorship
Pluggable Transports
Snowflake
Commits
0842dad3
Commit
0842dad3
authored
May 10, 2019
by
Cecylia Bocovich
Browse files
Added tests to check large read guards
parent
1d76d3ca
Changes
2
Hide whitespace changes
Inline
Side-by-side
broker/snowflake-broker_test.go
View file @
0842dad3
...
...
@@ -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
)
})
})
})
...
...
client/lib/lib_test.go
View file @
0842dad3
...
...
@@ -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
(
string
s
.
NewReader
(
`{"type":"answer","sdp":"fake"}`
))
s
:=
ioutil
.
NopCloser
(
byte
s
.
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
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment