mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Test ProxyPair with ArrayBuffers, not strings.
This commit is contained in:
parent
7c519b2975
commit
297ae7b1b8
1 changed files with 25 additions and 4 deletions
|
@ -2,6 +2,25 @@
|
||||||
jasmine tests for Snowflake proxypair
|
jasmine tests for Snowflake proxypair
|
||||||
###
|
###
|
||||||
|
|
||||||
|
# Replacement for MessageEvent constructor.
|
||||||
|
# https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/MessageEvent
|
||||||
|
MessageEvent = (type, init) ->
|
||||||
|
init
|
||||||
|
|
||||||
|
# Asymmetic matcher that checks that two arrays have the same contents.
|
||||||
|
arrayMatching = (sample) -> {
|
||||||
|
asymmetricMatch: (other) ->
|
||||||
|
a = new Uint8Array(sample)
|
||||||
|
b = new Uint8Array(other)
|
||||||
|
if a.length != b.length
|
||||||
|
return false
|
||||||
|
for _, i in a
|
||||||
|
if a[i] != b[i]
|
||||||
|
return false
|
||||||
|
true
|
||||||
|
jasmineToString: ->
|
||||||
|
'<arrayMatchine(' + jasmine.pp(sample) + ')>'
|
||||||
|
}
|
||||||
|
|
||||||
describe 'ProxyPair', ->
|
describe 'ProxyPair', ->
|
||||||
fakeRelay = Parse.address '0.0.0.0:12345'
|
fakeRelay = Parse.address '0.0.0.0:12345'
|
||||||
|
@ -76,17 +95,19 @@ describe 'ProxyPair', ->
|
||||||
}
|
}
|
||||||
spyOn pp.client, 'send'
|
spyOn pp.client, 'send'
|
||||||
spyOn pp.relay, 'send'
|
spyOn pp.relay, 'send'
|
||||||
pp.c2rSchedule.push 'foo'
|
msg = new MessageEvent("message", { data: Uint8Array.from([1, 2, 3]).buffer })
|
||||||
|
pp.onClientToRelayMessage(msg)
|
||||||
pp.flush()
|
pp.flush()
|
||||||
expect(pp.client.send).not.toHaveBeenCalled()
|
expect(pp.client.send).not.toHaveBeenCalled()
|
||||||
expect(pp.relay.send).toHaveBeenCalledWith 'foo'
|
expect(pp.relay.send).toHaveBeenCalledWith arrayMatching([1, 2, 3])
|
||||||
|
|
||||||
it 'proxies data from relay to client', ->
|
it 'proxies data from relay to client', ->
|
||||||
spyOn pp.client, 'send'
|
spyOn pp.client, 'send'
|
||||||
spyOn pp.relay, 'send'
|
spyOn pp.relay, 'send'
|
||||||
pp.r2cSchedule.push 'bar'
|
msg = new MessageEvent("message", { data: Uint8Array.from([4, 5, 6]).buffer })
|
||||||
|
pp.onRelayToClientMessage(msg)
|
||||||
pp.flush()
|
pp.flush()
|
||||||
expect(pp.client.send).toHaveBeenCalledWith 'bar'
|
expect(pp.client.send).toHaveBeenCalledWith arrayMatching([4, 5, 6])
|
||||||
expect(pp.relay.send).not.toHaveBeenCalled()
|
expect(pp.relay.send).not.toHaveBeenCalled()
|
||||||
|
|
||||||
it 'sends nothing with nothing to flush', ->
|
it 'sends nothing with nothing to flush', ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue