mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 14:11:23 -04:00
Initialize snowflake instance with a config
This commit is contained in:
parent
edbbea1d03
commit
2d8a1690ba
11 changed files with 125 additions and 113 deletions
|
@ -25,7 +25,7 @@ describe 'Broker', ->
|
|||
# fake successful request and response from broker.
|
||||
spyOn(b, '_postRequest').and.callFake ->
|
||||
b._xhr.readyState = b._xhr.DONE
|
||||
b._xhr.status = Broker.STATUS_OK
|
||||
b._xhr.status = Broker.STATUS.OK
|
||||
b._xhr.responseText = 'fake offer'
|
||||
b._xhr.onreadystatechange()
|
||||
poll = b.getClientOffer()
|
||||
|
@ -35,7 +35,7 @@ describe 'Broker', ->
|
|||
expect(desc).toEqual 'fake offer'
|
||||
done()
|
||||
.catch ->
|
||||
fail 'should not reject on Broker.STATUS_OK'
|
||||
fail 'should not reject on Broker.STATUS.OK'
|
||||
done()
|
||||
|
||||
it 'rejects if the broker timed-out', (done) ->
|
||||
|
@ -43,16 +43,16 @@ describe 'Broker', ->
|
|||
# fake timed-out request from broker
|
||||
spyOn(b, '_postRequest').and.callFake ->
|
||||
b._xhr.readyState = b._xhr.DONE
|
||||
b._xhr.status = Broker.STATUS_GATEWAY_TIMEOUT
|
||||
b._xhr.status = Broker.STATUS.GATEWAY_TIMEOUT
|
||||
b._xhr.onreadystatechange()
|
||||
poll = b.getClientOffer()
|
||||
expect(poll).not.toBeNull()
|
||||
expect(b._postRequest).toHaveBeenCalled()
|
||||
poll.then (desc) ->
|
||||
fail 'should not fulfill on GATEWAY_TIMEOUT'
|
||||
fail 'should not fulfill on Broker.STATUS.GATEWAY_TIMEOUT'
|
||||
done()
|
||||
, (err) ->
|
||||
expect(err).toBe Broker.MESSAGE_TIMEOUT
|
||||
expect(err).toBe Broker.MESSAGE.TIMEOUT
|
||||
done()
|
||||
|
||||
it 'rejects on any other status', (done) ->
|
||||
|
@ -69,7 +69,7 @@ describe 'Broker', ->
|
|||
fail 'should not fulfill on non-OK status'
|
||||
done()
|
||||
, (err) ->
|
||||
expect(err).toBe Broker.MESSAGE_UNEXPECTED
|
||||
expect(err).toBe Broker.MESSAGE.UNEXPECTED
|
||||
expect(b._xhr.status).toBe 1337
|
||||
done()
|
||||
|
||||
|
|
28
proxy/spec/init.spec.coffee
Normal file
28
proxy/spec/init.spec.coffee
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
# Fake snowflake to interact with
|
||||
snowflake =
|
||||
ui: new UI
|
||||
broker:
|
||||
sendAnswer: ->
|
||||
state: Snowflake.MODE.INIT
|
||||
|
||||
describe 'Init', ->
|
||||
|
||||
it 'gives a dialog when closing, only while active', ->
|
||||
silenceNotifications = false
|
||||
snowflake.state = Snowflake.MODE.WEBRTC_READY
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe Snowflake.MODE.WEBRTC_READY
|
||||
expect(msg).toBe Snowflake.MESSAGE.CONFIRMATION
|
||||
|
||||
snowflake.state = Snowflake.MODE.INIT
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe Snowflake.MODE.INIT
|
||||
expect(msg).toBe null
|
||||
|
||||
it 'does not give a dialog when silent flag is on', ->
|
||||
silenceNotifications = true
|
||||
snowflake.state = Snowflake.MODE.WEBRTC_READY
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe Snowflake.MODE.WEBRTC_READY
|
||||
expect(msg).toBe null
|
|
@ -24,10 +24,11 @@ arrayMatching = (sample) -> {
|
|||
|
||||
describe 'ProxyPair', ->
|
||||
fakeRelay = Parse.address '0.0.0.0:12345'
|
||||
rateLimit = new DummyRateLimit()
|
||||
rateLimit = new DummyRateLimit
|
||||
config = new Config
|
||||
destination = []
|
||||
# Using the mock PeerConnection definition from spec/snowflake.spec.coffee.
|
||||
pp = new ProxyPair(fakeRelay, rateLimit)
|
||||
pp = new ProxyPair(fakeRelay, rateLimit, config.pcConfig)
|
||||
|
||||
beforeEach ->
|
||||
pp.begin()
|
||||
|
|
|
@ -15,40 +15,38 @@ class WebSocket
|
|||
constructor: ->
|
||||
@bufferedAmount = 0
|
||||
send: (data) ->
|
||||
|
||||
log = ->
|
||||
fakeUI = new UI()
|
||||
|
||||
config = new Config
|
||||
ui = new UI
|
||||
|
||||
class FakeBroker
|
||||
getClientOffer: -> new Promise((F,R) -> {})
|
||||
# Fake snowflake to interact with
|
||||
snowflake =
|
||||
ui: fakeUI
|
||||
broker:
|
||||
sendAnswer: ->
|
||||
state: Snowflake.MODE.INIT
|
||||
|
||||
describe 'Snowflake', ->
|
||||
|
||||
it 'constructs correctly', ->
|
||||
s = new Snowflake({ fake: 'broker' }, fakeUI)
|
||||
s = new Snowflake(config, ui, { fake: 'broker' })
|
||||
expect(s.rateLimit).not.toBeNull()
|
||||
expect(s.broker).toEqual { fake: 'broker' }
|
||||
expect(s.ui).not.toBeNull()
|
||||
expect(s.retries).toBe 0
|
||||
|
||||
it 'sets relay address correctly', ->
|
||||
s = new Snowflake(null, fakeUI)
|
||||
s = new Snowflake(config, ui, null)
|
||||
s.setRelayAddr 'foo'
|
||||
expect(s.relayAddr).toEqual 'foo'
|
||||
|
||||
it 'initalizes WebRTC connection', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s = new Snowflake(config, ui, new FakeBroker())
|
||||
spyOn(s.broker, 'getClientOffer').and.callThrough()
|
||||
s.beginWebRTC()
|
||||
expect(s.retries).toBe 1
|
||||
expect(s.broker.getClientOffer).toHaveBeenCalled()
|
||||
|
||||
it 'receives SDP offer and sends answer', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s = new Snowflake(config, ui, new FakeBroker())
|
||||
pair = { receiveWebRTCOffer: -> }
|
||||
spyOn(pair, 'receiveWebRTCOffer').and.returnValue true
|
||||
spyOn(s, 'sendAnswer')
|
||||
|
@ -56,7 +54,7 @@ describe 'Snowflake', ->
|
|||
expect(s.sendAnswer).toHaveBeenCalled()
|
||||
|
||||
it 'does not send answer when receiving invalid offer', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s = new Snowflake(config, ui, new FakeBroker())
|
||||
pair = { receiveWebRTCOffer: -> }
|
||||
spyOn(pair, 'receiveWebRTCOffer').and.returnValue false
|
||||
spyOn(s, 'sendAnswer')
|
||||
|
@ -64,25 +62,6 @@ describe 'Snowflake', ->
|
|||
expect(s.sendAnswer).not.toHaveBeenCalled()
|
||||
|
||||
it 'can make a proxypair', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s = new Snowflake(config, ui, new FakeBroker())
|
||||
s.makeProxyPair()
|
||||
expect(s.proxyPairs.length).toBe 1
|
||||
|
||||
it 'gives a dialog when closing, only while active', ->
|
||||
silenceNotifications = false
|
||||
snowflake.state = Snowflake.MODE.WEBRTC_READY
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe Snowflake.MODE.WEBRTC_READY
|
||||
expect(msg).toBe CONFIRMATION_MESSAGE
|
||||
|
||||
snowflake.state = Snowflake.MODE.INIT
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe Snowflake.MODE.INIT
|
||||
expect(msg).toBe null
|
||||
|
||||
it 'does not give a dialog when silent flag is on', ->
|
||||
silenceNotifications = true
|
||||
snowflake.state = Snowflake.MODE.WEBRTC_READY
|
||||
msg = window.onbeforeunload()
|
||||
expect(snowflake.state).toBe Snowflake.MODE.WEBRTC_READY
|
||||
expect(msg).toBe null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue