mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Begin spec for proxy-side broker interaction
This commit is contained in:
parent
547cb9690a
commit
548c100160
3 changed files with 41 additions and 0 deletions
|
@ -14,6 +14,7 @@ FILES = [
|
||||||
FILES_SPEC = [
|
FILES_SPEC = [
|
||||||
'spec/util.spec.coffee'
|
'spec/util.spec.coffee'
|
||||||
'spec/ui.spec.coffee'
|
'spec/ui.spec.coffee'
|
||||||
|
'spec/broker.spec.coffee'
|
||||||
'spec/proxypair.spec.coffee'
|
'spec/proxypair.spec.coffee'
|
||||||
'spec/snowflake.spec.coffee'
|
'spec/snowflake.spec.coffee'
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,6 +17,7 @@ class Broker
|
||||||
|
|
||||||
clients: 0
|
clients: 0
|
||||||
id: null
|
id: null
|
||||||
|
request: null
|
||||||
|
|
||||||
# When interacting with the Broker, snowflake must generate a unique session
|
# When interacting with the Broker, snowflake must generate a unique session
|
||||||
# ID so the Broker can keep track of which signalling channel it's speaking
|
# ID so the Broker can keep track of which signalling channel it's speaking
|
||||||
|
@ -34,6 +35,7 @@ class Broker
|
||||||
getClientOffer: ->
|
getClientOffer: ->
|
||||||
new Promise (fulfill, reject) =>
|
new Promise (fulfill, reject) =>
|
||||||
xhr = new XMLHttpRequest()
|
xhr = new XMLHttpRequest()
|
||||||
|
@request = xhr
|
||||||
try
|
try
|
||||||
xhr.open 'POST', @url + 'proxy'
|
xhr.open 'POST', @url + 'proxy'
|
||||||
xhr.setRequestHeader('X-Session-ID', @id)
|
xhr.setRequestHeader('X-Session-ID', @id)
|
||||||
|
|
38
proxy/spec/broker.spec.coffee
Normal file
38
proxy/spec/broker.spec.coffee
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
###
|
||||||
|
jasmine tests for Snowflake broker
|
||||||
|
###
|
||||||
|
|
||||||
|
# fake xhr
|
||||||
|
class XMLHttpRequest
|
||||||
|
open: ->
|
||||||
|
send: ->
|
||||||
|
onreadystatechange: ->
|
||||||
|
DONE: 1
|
||||||
|
|
||||||
|
describe 'Broker', ->
|
||||||
|
|
||||||
|
it 'can be created', ->
|
||||||
|
b = new Broker('fake')
|
||||||
|
expect(b.url).toEqual 'https://fake/'
|
||||||
|
expect(b.id).not.toBeNull()
|
||||||
|
|
||||||
|
it 'polls for client offer', (done) ->
|
||||||
|
b = new Broker('fake')
|
||||||
|
# TODO: fix this
|
||||||
|
poll = b.getClientOffer()
|
||||||
|
spyOn(b.request, 'open')
|
||||||
|
spyOn(b.request, 'send').and.callFake ->
|
||||||
|
b.onreadystatechange()
|
||||||
|
poll.then = ->
|
||||||
|
done()
|
||||||
|
expect(poll).not.toBeNull()
|
||||||
|
# expect(b.request.open).toHaveBeenCalled()
|
||||||
|
# expect(b.request.send).toHaveBeenCalled()
|
||||||
|
# fake successful poll
|
||||||
|
b.request.readyState = XMLHttpRequest.DONE
|
||||||
|
b.request.status = STATUS_OK
|
||||||
|
b.request.responseText = 'test'
|
||||||
|
done()
|
||||||
|
|
||||||
|
it 'responds to the broker with answer', ->
|
||||||
|
# TODO
|
Loading…
Add table
Add a link
Reference in a new issue