[tor-commits] [snowflake/master] Begin spec for proxy-side broker interaction

serene at torproject.org serene at torproject.org
Wed Feb 10 22:04:09 UTC 2016


commit 548c100160f17e5daa78dd59810f963f362888cd
Author: Serene Han <keroserene+git at gmail.com>
Date:   Mon Feb 8 19:26:58 2016 -0800

    Begin spec for proxy-side broker interaction
---
 proxy/Cakefile                |  1 +
 proxy/broker.coffee           |  2 ++
 proxy/spec/broker.spec.coffee | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

diff --git a/proxy/Cakefile b/proxy/Cakefile
index 88d142b..045468f 100644
--- a/proxy/Cakefile
+++ b/proxy/Cakefile
@@ -14,6 +14,7 @@ FILES = [
 FILES_SPEC = [
   'spec/util.spec.coffee'
   'spec/ui.spec.coffee'
+  'spec/broker.spec.coffee'
   'spec/proxypair.spec.coffee'
   'spec/snowflake.spec.coffee'
 ]
diff --git a/proxy/broker.coffee b/proxy/broker.coffee
index acd5a5f..b196df5 100644
--- a/proxy/broker.coffee
+++ b/proxy/broker.coffee
@@ -17,6 +17,7 @@ class Broker
 
   clients: 0
   id: null
+  request: null
 
   # 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
@@ -34,6 +35,7 @@ class Broker
   getClientOffer: ->
     new Promise (fulfill, reject) =>
       xhr = new XMLHttpRequest()
+      @request = xhr
       try
         xhr.open 'POST', @url + 'proxy'
         xhr.setRequestHeader('X-Session-ID', @id)
diff --git a/proxy/spec/broker.spec.coffee b/proxy/spec/broker.spec.coffee
new file mode 100644
index 0000000..2844cdb
--- /dev/null
+++ b/proxy/spec/broker.spec.coffee
@@ -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





More information about the tor-commits mailing list