mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
With, ./node_modules/.bin/coffee -b -c Cakefile `find . -path ./node_modules -prune -o -name '*.coffee'`
114 lines
2.6 KiB
JavaScript
114 lines
2.6 KiB
JavaScript
// Generated by CoffeeScript 2.4.1
|
|
/*
|
|
jasmine tests for Snowflake
|
|
*/
|
|
var FakeBroker, PeerConnection, SessionDescription, WebSocket, config, log, ui;
|
|
|
|
// Fake browser functionality:
|
|
PeerConnection = class PeerConnection {
|
|
setRemoteDescription() {
|
|
return true;
|
|
}
|
|
|
|
send(data) {}
|
|
|
|
};
|
|
|
|
SessionDescription = (function() {
|
|
class SessionDescription {};
|
|
|
|
SessionDescription.prototype.type = 'offer';
|
|
|
|
return SessionDescription;
|
|
|
|
}).call(this);
|
|
|
|
WebSocket = (function() {
|
|
class WebSocket {
|
|
constructor() {
|
|
this.bufferedAmount = 0;
|
|
}
|
|
|
|
send(data) {}
|
|
|
|
};
|
|
|
|
WebSocket.prototype.OPEN = 1;
|
|
|
|
WebSocket.prototype.CLOSED = 0;
|
|
|
|
return WebSocket;
|
|
|
|
}).call(this);
|
|
|
|
log = function() {};
|
|
|
|
config = new Config;
|
|
|
|
ui = new UI;
|
|
|
|
FakeBroker = class FakeBroker {
|
|
getClientOffer() {
|
|
return new Promise(function(F, R) {
|
|
return {};
|
|
});
|
|
}
|
|
|
|
};
|
|
|
|
describe('Snowflake', function() {
|
|
it('constructs correctly', function() {
|
|
var s;
|
|
s = new Snowflake(config, ui, {
|
|
fake: 'broker'
|
|
});
|
|
expect(s.rateLimit).not.toBeNull();
|
|
expect(s.broker).toEqual({
|
|
fake: 'broker'
|
|
});
|
|
expect(s.ui).not.toBeNull();
|
|
return expect(s.retries).toBe(0);
|
|
});
|
|
it('sets relay address correctly', function() {
|
|
var s;
|
|
s = new Snowflake(config, ui, null);
|
|
s.setRelayAddr('foo');
|
|
return expect(s.relayAddr).toEqual('foo');
|
|
});
|
|
it('initalizes WebRTC connection', function() {
|
|
var s;
|
|
s = new Snowflake(config, ui, new FakeBroker());
|
|
spyOn(s.broker, 'getClientOffer').and.callThrough();
|
|
s.beginWebRTC();
|
|
expect(s.retries).toBe(1);
|
|
return expect(s.broker.getClientOffer).toHaveBeenCalled();
|
|
});
|
|
it('receives SDP offer and sends answer', function() {
|
|
var pair, s;
|
|
s = new Snowflake(config, ui, new FakeBroker());
|
|
pair = {
|
|
receiveWebRTCOffer: function() {}
|
|
};
|
|
spyOn(pair, 'receiveWebRTCOffer').and.returnValue(true);
|
|
spyOn(s, 'sendAnswer');
|
|
s.receiveOffer(pair, '{"type":"offer","sdp":"foo"}');
|
|
return expect(s.sendAnswer).toHaveBeenCalled();
|
|
});
|
|
it('does not send answer when receiving invalid offer', function() {
|
|
var pair, s;
|
|
s = new Snowflake(config, ui, new FakeBroker());
|
|
pair = {
|
|
receiveWebRTCOffer: function() {}
|
|
};
|
|
spyOn(pair, 'receiveWebRTCOffer').and.returnValue(false);
|
|
spyOn(s, 'sendAnswer');
|
|
s.receiveOffer(pair, '{"type":"not a good offer","sdp":"foo"}');
|
|
return expect(s.sendAnswer).not.toHaveBeenCalled();
|
|
});
|
|
return it('can make a proxypair', function() {
|
|
var s;
|
|
s = new Snowflake(config, ui, new FakeBroker());
|
|
s.makeProxyPair();
|
|
return expect(s.proxyPairs.length).toBe(1);
|
|
});
|
|
});
|