|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | require('should')
|
3 |
| -var origin = require('../src/origin') |
| 3 | +var originMatcher = require('../src/origin-matcher') |
4 | 4 |
|
5 | 5 | describe('Origin list', function () {
|
6 | 6 | it('returns false if the request has no origin', function () {
|
7 | 7 | var list = ['http://api.myapp.com', 'http://www.myapp.com']
|
8 |
| - origin.allowed(list, null).should.eql(false) |
| 8 | + var matcher = originMatcher.create(list) |
| 9 | + matcher(null).should.eql(false) |
| 10 | + matcher('').should.eql(false) |
9 | 11 | })
|
10 | 12 |
|
11 | 13 | it('returns false if the origin is not in the list', function () {
|
12 | 14 | var list = ['http://api.myapp.com', 'http://www.myapp.com']
|
13 |
| - origin.allowed(list, 'http://random-website.com').should.eql(false) |
| 15 | + var matcher = originMatcher.create(list) |
| 16 | + matcher('http://random-website.com').should.eql(false) |
14 | 17 | })
|
15 | 18 |
|
16 | 19 | it('returns true if the origin matched', function () {
|
17 | 20 | var list = ['http://api.myapp.com', 'http://www.myapp.com']
|
18 |
| - origin.allowed(list, 'http://api.myapp.com').should.eql(true) |
| 21 | + var matcher = originMatcher.create(list) |
| 22 | + matcher('http://api.myapp.com').should.eql(true) |
19 | 23 | })
|
20 | 24 |
|
21 | 25 | it('does not do partial matches by default', function () {
|
22 | 26 | var list = ['http://api.myapp.com', 'http://www.myapp.com']
|
23 |
| - origin.allowed(list, 'api.myapp.com').should.eql(false) |
| 27 | + var matcher = originMatcher.create(list) |
| 28 | + matcher('api.myapp.com').should.eql(false) |
24 | 29 | })
|
25 | 30 |
|
26 | 31 | it('always matches if the list contains *', function () {
|
27 | 32 | var list = ['*']
|
28 |
| - origin.allowed(list, 'http://random-website.com').should.eql(true) |
| 33 | + var matcher = originMatcher.create(list) |
| 34 | + matcher('http://random-website.com').should.eql(true) |
29 | 35 | })
|
30 | 36 |
|
31 | 37 | it('supports * for partial matches', function () {
|
32 | 38 | var list = ['http://*.myapp.com', 'http://other-website.com']
|
33 |
| - origin.allowed(list, 'http://api.myapp.com').should.eql(true) |
| 39 | + var matcher = originMatcher.create(list) |
| 40 | + matcher('http://api.myapp.com').should.eql(true) |
34 | 41 | })
|
35 | 42 |
|
36 | 43 | it('escapes the partial regex properly', function () {
|
37 | 44 | // the "." should be a real dot, not mean "[any character]myapp"
|
38 | 45 | var list = ['http://*.myapp.com', 'http://other-website.com']
|
39 |
| - origin.allowed(list, 'http://xmyapp.com').should.eql(false) |
| 46 | + var matcher = originMatcher.create(list) |
| 47 | + matcher('http://xmyapp.com').should.eql(false) |
40 | 48 | })
|
41 | 49 |
|
42 | 50 | it('returns false if there was no partial match', function () {
|
43 | 51 | var list = ['http://*.myapp.com']
|
44 |
| - origin.allowed(list, 'http://random-website.com').should.eql(false) |
| 52 | + var matcher = originMatcher.create(list) |
| 53 | + matcher('http://random-website.com').should.eql(false) |
45 | 54 | })
|
46 | 55 | })
|
0 commit comments