UNPKG

3.58 kBtext/coffeescriptView Raw
1###
2Module dependencies.
3###
4WhiteList = require '../libs/white-list'
5
6describe 'Lib', ->
7
8 describe 'WhiteList', ->
9
10 it 'should receive an optional list in the constructor', (done) ->
11
12 customList = [
13 '/route/one'
14 '/route/two'
15 new RegExp '^admin.*Content$'
16 ]
17
18 whiteList = new WhiteList(customList)
19 whiteList.publicUris.length.should.be.equal 3
20 done()
21
22 describe '#addToPublicUris()', ->
23
24 whiteList = new WhiteList
25
26 it 'should exist as a public function', (done) ->
27
28 whiteList.addToPublicUris.should.be.a.Function
29 done()
30
31 it 'should throw an error if no publicUris was passed as parameter', (done) ->
32
33 whiteList.addToPublicUris.bind(null).should.throw '"publicUris" is required'
34 done()
35
36 it 'should be able to receive a single string and add it to publicUris property', (done) ->
37
38 whiteList = new WhiteList
39
40 newPublicUri = '/admin/route'
41
42 whiteList.addToPublicUris newPublicUri
43 whiteList.publicUris.should.containEql '/admin/route'
44 done()
45
46 it 'should be able to receive a single regexp and add it to publicUris property', (done) ->
47
48 whiteList = new WhiteList
49
50 newPublicUri = new RegExp '^admin.*Content$'
51
52 whiteList.addToPublicUris newPublicUri
53 whiteList.publicUris.should.containEql /^admin.*Content$/
54 done()
55
56 it 'should be able to receive an array containing multiple publicUris and concatenate to publicUris property', (done) ->
57
58 whiteList = new WhiteList
59
60 newPublicUrisList = [
61 '/route/1'
62 '/route/2'
63 new RegExp '^admin.*Content$'
64 ]
65
66 whiteList.addToPublicUris newPublicUrisList
67 whiteList.publicUris.should.containEql '/route/1'
68 whiteList.publicUris.should.containEql '/route/2'
69 whiteList.publicUris.should.containEql /^admin.*Content$/
70 done()
71
72 describe '#isInWhiteList()', ->
73
74 whiteList = new WhiteList
75
76 it 'should exist as a public function', (done) ->
77 whiteList.isInWhiteList.should.be.a.Function
78 done()
79
80 it 'should throw an error if url string was not passed as parameter', (done) ->
81
82 whiteList.isInWhiteList.bind(null).should.throw '"url" parameter is required'
83 done()
84
85 it 'should return true if url is /admin/Content', (done) ->
86
87 url = '/admin/Content'
88
89 whiteList.isInWhiteList(url).should.be.true
90 done()
91
92 it 'should return true if url is /admin/Scripts', (done) ->
93
94 url = '/admin/Scripts'
95
96 whiteList.isInWhiteList(url).should.be.true
97 done()
98
99 it 'should return true if url is /meta/whoami', (done) ->
100
101 url = '/meta/whoami'
102
103 whiteList.isInWhiteList(url).should.be.true
104 done()
105
106 it 'should return true if url start with /admin/login', (done) ->
107
108 url = '/admin/login?RedirectUrl=/admin/checkout'
109
110 whiteList.isInWhiteList(url).should.be.true
111 done()
112
113 it 'should return false if url contains but does not start with /admin/login', (done) ->
114
115 url = '/admin/checkout?RedirectUrl=/admin/login'
116
117 whiteList.isInWhiteList(url).should.be.false
118 done()
119
120 it 'should return false if url is not in white list', (done) ->
121
122 url = '/admin/checkout'
123
124 whiteList.isInWhiteList(url).should.be.false
125 done()
126
127 it 'should return true for favicon', (done) ->
128
129 url = '/favicon.ico'
130
131 whiteList.isInWhiteList(url).should.be.true
132 done()