restify-cors-middleware/test/origin.spec.js

31 lines
837 B
JavaScript
Raw Normal View History

2017-05-22 12:03:45 -04:00
/* eslint-env mocha */
require('should')
var origin = require('../src/origin')
2017-05-22 12:03:45 -04:00
describe('Origin list', function () {
var list = [
'http://api.myapp.com',
'http://www.myapp.com'
2017-05-22 12:03:45 -04:00
]
2017-05-22 12:03:45 -04:00
it('returns null if the origin is not in the list', function () {
var o = origin.match('http://random-website.com', list);
2017-05-22 12:03:45 -04:00
(o === null).should.eql(true)
})
2017-05-22 12:03:45 -04:00
it('does not do partial matches', function () {
var o = origin.match('api.myapp.com', list);
2017-05-22 12:03:45 -04:00
(o === null).should.eql(true)
})
2017-05-22 12:03:45 -04:00
it('returns the origin if it matched', function () {
var o = origin.match('http://api.myapp.com', list)
o.should.eql('http://api.myapp.com')
})
2017-05-22 12:03:45 -04:00
it('returns the origin if the list contains *', function () {
var o = origin.match('http://random-website.com', ['*'])
o.should.eql('http://random-website.com')
})
})