/
main-node.js
56 lines (47 loc) · 1.63 KB
/
main-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
var expect = require('expect.js')
, proxyquire = require('proxyquire')
;
describe('SockJS', function() {
describe('Constructor', function () {
describe('WebSocket specification step #2', function () {
var main = proxyquire('../../lib/main', { './location': {
protocol: 'https:'
}});
var sjs = proxyquire('../../lib/entry', { './main': main });
it('should throw SecurityError for an insecure url from a secure page', function () {
expect(function () {
sjs('http://localhost');
}).to.throwException(function (e) {
expect(e).to.be.a(Error);
expect(e.message).to.contain('SecurityError');
});
});
// https://www.w3.org/TR/secure-contexts/#is-origin-trustworthy
it('should NOT throw SecurityError for 127.0.0.1/8 url from a secure page', function () {
expect(function () {
sjs('http://127.0.0.1');
}).to.not.throwException();
});
it('should NOT throw SecurityError for ::1 url from a secure page', function () {
expect(function () {
sjs('http://::1');
}).to.not.throwException();
});
it('should throw SyntaxError for an invalid url', function () {
expect(function () {
sjs('//localhost');
}).to.throwException(function (e) {
expect(e).to.be.a(SyntaxError);
});
});
it('should throw SyntaxError for an empty url - #8', function () {
expect(function () {
sjs('');
}).to.throwException(function (e) {
expect(e).to.be.a(SyntaxError);
});
});
});
});
});