commit 297ae7b1b8800f7c70d31da034ae3802c39273c9 Author: David Fifield david@bamsoftware.com Date: Tue Dec 4 16:55:12 2018 -0700
Test ProxyPair with ArrayBuffers, not strings. --- proxy/spec/proxypair.spec.coffee | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/proxy/spec/proxypair.spec.coffee b/proxy/spec/proxypair.spec.coffee index 4cbb38d..566c6f1 100644 --- a/proxy/spec/proxypair.spec.coffee +++ b/proxy/spec/proxypair.spec.coffee @@ -2,6 +2,25 @@ jasmine tests for Snowflake proxypair ###
+# Replacement for MessageEvent constructor. +# https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/MessageEvent +MessageEvent = (type, init) -> + init + +# Asymmetic matcher that checks that two arrays have the same contents. +arrayMatching = (sample) -> { + asymmetricMatch: (other) -> + a = new Uint8Array(sample) + b = new Uint8Array(other) + if a.length != b.length + return false + for _, i in a + if a[i] != b[i] + return false + true + jasmineToString: -> + '<arrayMatchine(' + jasmine.pp(sample) + ')>' +}
describe 'ProxyPair', -> fakeRelay = Parse.address '0.0.0.0:12345' @@ -76,17 +95,19 @@ describe 'ProxyPair', -> } spyOn pp.client, 'send' spyOn pp.relay, 'send' - pp.c2rSchedule.push 'foo' + msg = new MessageEvent("message", { data: Uint8Array.from([1, 2, 3]).buffer }) + pp.onClientToRelayMessage(msg) pp.flush() expect(pp.client.send).not.toHaveBeenCalled() - expect(pp.relay.send).toHaveBeenCalledWith 'foo' + expect(pp.relay.send).toHaveBeenCalledWith arrayMatching([1, 2, 3])
it 'proxies data from relay to client', -> spyOn pp.client, 'send' spyOn pp.relay, 'send' - pp.r2cSchedule.push 'bar' + msg = new MessageEvent("message", { data: Uint8Array.from([4, 5, 6]).buffer }) + pp.onRelayToClientMessage(msg) pp.flush() - expect(pp.client.send).toHaveBeenCalledWith 'bar' + expect(pp.client.send).toHaveBeenCalledWith arrayMatching([4, 5, 6]) expect(pp.relay.send).not.toHaveBeenCalled()
it 'sends nothing with nothing to flush', ->
tor-commits@lists.torproject.org