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
|
@ -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