mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 14:11:23 -04:00
more jasmine specs for proxypair, ui, and snowflake coffee files
This commit is contained in:
parent
e0081ea954
commit
547cb9690a
9 changed files with 159 additions and 56 deletions
|
@ -1,27 +1,13 @@
|
|||
###
|
||||
jasmine tests for Snowflake
|
||||
jasmine tests for Snowflake proxypair
|
||||
###
|
||||
|
||||
# Stubs to fake browser functionality.
|
||||
class PeerConnection
|
||||
class WebSocket
|
||||
OPEN: 1
|
||||
CLOSED: 0
|
||||
ui =
|
||||
log: ->
|
||||
setActive: ->
|
||||
log = ->
|
||||
|
||||
describe 'ProxyPair', ->
|
||||
fakeRelay = Parse.address '0.0.0.0:12345'
|
||||
rateLimit = new DummyRateLimit()
|
||||
destination = []
|
||||
fakeClient = send: (d) -> destination.push d
|
||||
# Fake snowflake to interact with
|
||||
snowflake = {
|
||||
broker:
|
||||
sendAnswer: ->
|
||||
}
|
||||
pp = new ProxyPair(fakeClient, fakeRelay, rateLimit)
|
||||
|
||||
it 'begins webrtc connection', ->
|
||||
|
|
60
proxy/spec/snowflake.spec.coffee
Normal file
60
proxy/spec/snowflake.spec.coffee
Normal file
|
@ -0,0 +1,60 @@
|
|||
###
|
||||
jasmine tests for Snowflake
|
||||
###
|
||||
|
||||
query = {}
|
||||
# Fake browser functionality:
|
||||
class PeerConnection
|
||||
class RTCSessionDescription
|
||||
type: 'offer'
|
||||
class WebSocket
|
||||
OPEN: 1
|
||||
CLOSED: 0
|
||||
log = ->
|
||||
class FakeUI
|
||||
log: ->
|
||||
setActive: ->
|
||||
setStatus: ->
|
||||
fakeUI = new FakeUI()
|
||||
class FakeBroker
|
||||
getClientOffer: -> new Promise((F,R) -> {})
|
||||
# Fake snowflake to interact with
|
||||
snowflake =
|
||||
ui: fakeUI
|
||||
broker:
|
||||
sendAnswer: ->
|
||||
|
||||
describe 'Snowflake', ->
|
||||
|
||||
it 'constructs correctly', ->
|
||||
s = new Snowflake({ fake: 'broker' }, fakeUI)
|
||||
query['ratelimit'] = 'off'
|
||||
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.setRelayAddr 'foo'
|
||||
expect(s.relayAddr).toEqual 'foo'
|
||||
|
||||
it 'initalizes WebRTC connection', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
spyOn(s.broker, 'getClientOffer').and.callThrough()
|
||||
s.beginWebRTC()
|
||||
expect(s.retries).toBe 1
|
||||
expect(s.broker.getClientOffer).toHaveBeenCalled()
|
||||
|
||||
it 'receives SDP offer', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s.proxyPair = { receiveWebRTCOffer: -> }
|
||||
spyOn(s.proxyPair, 'receiveWebRTCOffer').and.returnValue true
|
||||
spyOn(s, 'sendAnswer')
|
||||
s.receiveOffer 'foo'
|
||||
expect(s.sendAnswer).toHaveBeenCalled()
|
||||
|
||||
it 'can make a proxypair', ->
|
||||
s = new Snowflake(new FakeBroker(), fakeUI)
|
||||
s.makeProxyPair()
|
||||
expect(s.proxyPairs.length).toBe 2
|
75
proxy/spec/ui.spec.coffee
Normal file
75
proxy/spec/ui.spec.coffee
Normal file
|
@ -0,0 +1,75 @@
|
|||
###
|
||||
jasmine tests for Snowflake UI
|
||||
###
|
||||
|
||||
document =
|
||||
getElementById: (id) ->
|
||||
|
||||
describe 'UI', ->
|
||||
|
||||
it 'activates debug mode when badge does not exist', ->
|
||||
spyOn(document, 'getElementById').and.callFake (id) ->
|
||||
return null if 'badge' == id
|
||||
return {
|
||||
focus: ->
|
||||
}
|
||||
u = new UI()
|
||||
expect(u.debug).toBe true
|
||||
expect(document.getElementById.calls.count()).toEqual 5
|
||||
expect(u.$status).not.toBeNull()
|
||||
expect(u.$msglog).not.toBeNull()
|
||||
expect(u.$send).not.toBeNull()
|
||||
expect(u.$input).not.toBeNull()
|
||||
|
||||
it 'is not debug mode when badge exists', ->
|
||||
spyOn(document, 'getElementById').and.callFake (id) ->
|
||||
return {} if 'badge' == id
|
||||
return null
|
||||
u = new UI()
|
||||
expect(u.debug).toBe false
|
||||
expect(document.getElementById).toHaveBeenCalled()
|
||||
expect(document.getElementById.calls.count()).toEqual 1
|
||||
expect(u.$status).toBeNull()
|
||||
expect(u.$msglog).toBeNull()
|
||||
expect(u.$send).toBeNull()
|
||||
expect(u.$input).toBeNull()
|
||||
|
||||
it 'sets status message only when in debug mode', ->
|
||||
u = new UI()
|
||||
u.$status = { innerHTML: '' }
|
||||
u.debug = false
|
||||
u.setStatus('test')
|
||||
expect(u.$status.innerHTML).toEqual ''
|
||||
u.debug = true
|
||||
u.setStatus('test')
|
||||
expect(u.$status.innerHTML).toEqual 'Status: test'
|
||||
|
||||
it 'sets message log css correctly for debug mode', ->
|
||||
u = new UI()
|
||||
u.debug = true
|
||||
u.$msglog = {}
|
||||
u.setActive true
|
||||
expect(u.$msglog.className).toEqual 'active'
|
||||
u.setActive false
|
||||
expect(u.$msglog.className).toEqual ''
|
||||
|
||||
it 'sets badge css correctly for non-debug mode', ->
|
||||
u = new UI()
|
||||
u.debug = false
|
||||
u.$badge = {}
|
||||
u.setActive true
|
||||
expect(u.$badge.className).toEqual 'active'
|
||||
u.setActive false
|
||||
expect(u.$badge.className).toEqual ''
|
||||
|
||||
it 'logs to the textarea correctly, only when debug mode', ->
|
||||
u = new UI()
|
||||
u.$msglog = { value: '', scrollTop: 0, scrollHeight: 1337 }
|
||||
u.debug = false
|
||||
u.log 'test'
|
||||
expect(u.$msglog.value).toEqual ''
|
||||
expect(u.$msglog.scrollTop).toEqual 0
|
||||
u.debug = true
|
||||
u.log 'test'
|
||||
expect(u.$msglog.value).toEqual 'test\n'
|
||||
expect(u.$msglog.scrollTop).toEqual 1337
|
|
@ -1,17 +1,7 @@
|
|||
###
|
||||
jasmine tests for Snowflake
|
||||
jasmine tests for Snowflake utils
|
||||
###
|
||||
|
||||
# Stubs to fake browser functionality.
|
||||
class PeerConnection
|
||||
class WebSocket
|
||||
OPEN: 1
|
||||
CLOSED: 0
|
||||
ui =
|
||||
log: ->
|
||||
setActive: ->
|
||||
log = ->
|
||||
|
||||
describe 'BuildUrl', ->
|
||||
it 'should parse just protocol and host', ->
|
||||
expect(buildUrl('http', 'example.com')).toBe 'http://example.com'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue