commit 3cd8519ec94198181803345260be9fd20d0de324 Author: David Fifield david@bamsoftware.com Date: Tue Dec 4 15:07:42 2018 -0700
Fix the ProxyPair tests exposed by the previous commit.
This was mainly a matter of more complete mocking. --- proxy/spec/proxypair.spec.coffee | 35 +++++++++++++++++++++++++++-------- proxy/spec/snowflake.spec.coffee | 6 ++++++ 2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/proxy/spec/proxypair.spec.coffee b/proxy/spec/proxypair.spec.coffee index 1ef4a7e..4cbb38d 100644 --- a/proxy/spec/proxypair.spec.coffee +++ b/proxy/spec/proxypair.spec.coffee @@ -7,24 +7,32 @@ describe 'ProxyPair', -> fakeRelay = Parse.address '0.0.0.0:12345' rateLimit = new DummyRateLimit() destination = [] + # Using the mock PeerConnection definition from spec/snowflake.spec.coffee. pp = new ProxyPair(fakeRelay, rateLimit)
- it 'begins webrtc connection', -> + beforeEach -> pp.begin() + + it 'begins webrtc connection', -> expect(pp.pc).not.toBeNull()
describe 'accepts WebRTC offer from some client', -> + beforeEach -> + pp.begin() + it 'rejects invalid offers', -> + expect(typeof(pp.pc.setRemoteDescription)).toBe("function") + expect(pp.pc).not.toBeNull() expect(pp.receiveWebRTCOffer {}).toBe false - expect pp.receiveWebRTCOffer { + expect(pp.receiveWebRTCOffer { type: 'answer' - }.toBeFalse() + }).toBe false it 'accepts valid offers', -> - goodOffer = { + expect(pp.pc).not.toBeNull() + expect(pp.receiveWebRTCOffer { type: 'offer' sdp: 'foo' - } - expect(pp.receiveWebRTCOffer goodOffer).toBe true + }).toBe true
it 'responds with a WebRTC answer correctly', -> spyOn snowflake.broker, 'sendAnswer' @@ -59,20 +67,31 @@ describe 'ProxyPair', -> describe 'flushes data between client and relay', ->
it 'proxies data from client to relay', -> + pp.pc.ondatachannel { + channel: { + bufferedAmount: 0 + readyState: "open" + send: (data) -> + } + } + spyOn pp.client, 'send' spyOn pp.relay, 'send' - pp.c2rSchedule.push { data: 'foo' } + pp.c2rSchedule.push 'foo' pp.flush() expect(pp.client.send).not.toHaveBeenCalled() expect(pp.relay.send).toHaveBeenCalledWith 'foo'
it 'proxies data from relay to client', -> spyOn pp.client, 'send' - pp.r2cSchedule.push { data: 'bar' } + spyOn pp.relay, 'send' + pp.r2cSchedule.push 'bar' pp.flush() expect(pp.client.send).toHaveBeenCalledWith 'bar' expect(pp.relay.send).not.toHaveBeenCalled()
it 'sends nothing with nothing to flush', -> + spyOn pp.client, 'send' + spyOn pp.relay, 'send' pp.flush() expect(pp.client.send).not.toHaveBeenCalled() expect(pp.relay.send).not.toHaveBeenCalled() diff --git a/proxy/spec/snowflake.spec.coffee b/proxy/spec/snowflake.spec.coffee index 2865795..05dd843 100644 --- a/proxy/spec/snowflake.spec.coffee +++ b/proxy/spec/snowflake.spec.coffee @@ -5,11 +5,17 @@ jasmine tests for Snowflake query = {} # Fake browser functionality: class PeerConnection + setRemoteDescription: -> + true + send: (data) -> class SessionDescription type: 'offer' class WebSocket OPEN: 1 CLOSED: 0 + constructor: -> + @bufferedAmount = 0 + send: (data) -> log = -> class FakeUI log: ->
tor-commits@lists.torproject.org