rack-cors 1.0.2 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +0,0 @@
1
- <html>
2
- <head>
3
- <meta charset="utf-8">
4
- <title>Mocha Tests</title>
5
- <link rel="stylesheet" href="mocha.css" />
6
- </head>
7
- <body>
8
- <div id="mocha"></div>
9
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
10
- <script src="expect.js"></script>
11
- <script src="mocha.js"></script>
12
- <script>mocha.setup('bdd')</script>
13
- <script src="test.cors.js"></script>
14
- <script>
15
- mocha.checkLeaks();
16
- mocha.globals(['jQuery']);
17
- mocha.run();
18
- </script>
19
- </body>
20
- </html>
@@ -1,42 +0,0 @@
1
- CORS_SERVER = '127.0.0.1.xip.io:9292'
2
-
3
- describe 'CORS', ->
4
-
5
- it 'should allow access to dynamic resource', (done) ->
6
- $.get "http://#{CORS_SERVER}/", (data, status, xhr) ->
7
- expect(data).to.eql('Hello world')
8
- done()
9
-
10
- it 'should allow PUT access to dynamic resource', (done) ->
11
- $.ajax("http://#{CORS_SERVER}/", type: 'PUT').done (data, textStatus, jqXHR) ->
12
- expect(data).to.eql('Hello world')
13
- done()
14
-
15
- it 'should allow HEAD access to dynamic resource', (done) ->
16
- $.ajax("http://#{CORS_SERVER}/", type: 'HEAD').done (data, textStatus, jqXHR) ->
17
- expect(jqXHR.status).to.eql(200)
18
- done()
19
-
20
- it 'should allow DELETE access to dynamic resource', (done) ->
21
- $.ajax("http://#{CORS_SERVER}/", type: 'DELETE').done (data, textStatus, jqXHR) ->
22
- expect(data).to.eql('Hello world')
23
- done()
24
-
25
- it 'should allow OPTIONS access to dynamic resource', (done) ->
26
- $.ajax("http://#{CORS_SERVER}/", type: 'OPTIONS').done (data, textStatus, jqXHR) ->
27
- expect(jqXHR.status).to.eql(200)
28
- done()
29
-
30
- it 'should allow access to static resource', (done) ->
31
- $.get "http://#{CORS_SERVER}/static.txt", (data, status, xhr) ->
32
- expect($.trim(data)).to.eql("hello world")
33
- done()
34
-
35
- it 'should allow post resource', (done) ->
36
- $.ajax
37
- type: 'POST'
38
- url: "http://#{CORS_SERVER}/cors"
39
- beforeSend: (xhr) -> xhr.setRequestHeader('X-Requested-With', 'XMLHTTPRequest')
40
- success:(data, status, xhr) ->
41
- expect($.trim(data)).to.eql("OK!")
42
- done()
@@ -1,67 +0,0 @@
1
- // Generated by CoffeeScript 1.12.6
2
- (function() {
3
- var CORS_SERVER;
4
-
5
- CORS_SERVER = '127.0.0.1.xip.io:9292';
6
-
7
- describe('CORS', function() {
8
- it('should allow access to dynamic resource', function(done) {
9
- return $.get("http://" + CORS_SERVER + "/", function(data, status, xhr) {
10
- expect(data).to.eql('Hello world');
11
- return done();
12
- });
13
- });
14
- it('should allow PUT access to dynamic resource', function(done) {
15
- return $.ajax("http://" + CORS_SERVER + "/", {
16
- type: 'PUT'
17
- }).done(function(data, textStatus, jqXHR) {
18
- expect(data).to.eql('Hello world');
19
- return done();
20
- });
21
- });
22
- it('should allow HEAD access to dynamic resource', function(done) {
23
- return $.ajax("http://" + CORS_SERVER + "/", {
24
- type: 'HEAD'
25
- }).done(function(data, textStatus, jqXHR) {
26
- expect(jqXHR.status).to.eql(200);
27
- return done();
28
- });
29
- });
30
- it('should allow DELETE access to dynamic resource', function(done) {
31
- return $.ajax("http://" + CORS_SERVER + "/", {
32
- type: 'DELETE'
33
- }).done(function(data, textStatus, jqXHR) {
34
- expect(data).to.eql('Hello world');
35
- return done();
36
- });
37
- });
38
- it('should allow OPTIONS access to dynamic resource', function(done) {
39
- return $.ajax("http://" + CORS_SERVER + "/", {
40
- type: 'OPTIONS'
41
- }).done(function(data, textStatus, jqXHR) {
42
- expect(jqXHR.status).to.eql(200);
43
- return done();
44
- });
45
- });
46
- it('should allow access to static resource', function(done) {
47
- return $.get("http://" + CORS_SERVER + "/static.txt", function(data, status, xhr) {
48
- expect($.trim(data)).to.eql("hello world");
49
- return done();
50
- });
51
- });
52
- return it('should allow post resource', function(done) {
53
- return $.ajax({
54
- type: 'POST',
55
- url: "http://" + CORS_SERVER + "/cors",
56
- beforeSend: function(xhr) {
57
- return xhr.setRequestHeader('X-Requested-With', 'XMLHTTPRequest');
58
- },
59
- success: function(data, status, xhr) {
60
- expect($.trim(data)).to.eql("OK!");
61
- return done();
62
- }
63
- });
64
- });
65
- });
66
-
67
- }).call(this);
@@ -1,482 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rack/test'
3
- require 'mocha/setup'
4
- require 'rack/cors'
5
- require 'ostruct'
6
-
7
- Rack::Test::Session.class_eval do
8
- unless defined? :options
9
- def options(uri, params = {}, env = {}, &block)
10
- env = env_for(uri, env.merge(:method => "OPTIONS", :params => params))
11
- process_request(uri, env, &block)
12
- end
13
- end
14
- end
15
-
16
- Rack::Test::Methods.class_eval do
17
- def_delegator :current_session, :options
18
- end
19
-
20
- module MiniTest::Assertions
21
- def assert_cors_success(response)
22
- assert !response.headers['Access-Control-Allow-Origin'].nil?, "Expected a successful CORS response"
23
- end
24
-
25
- def assert_not_cors_success(response)
26
- assert response.headers['Access-Control-Allow-Origin'].nil?, "Expected a failed CORS response"
27
- end
28
- end
29
-
30
- class CaptureResult
31
- def initialize(app, options = {})
32
- @app = app
33
- @result_holder = options[:holder]
34
- end
35
-
36
- def call(env)
37
- response = @app.call(env)
38
- @result_holder.cors_result = env[Rack::Cors::RACK_CORS]
39
- return response
40
- end
41
- end
42
-
43
- Rack::MockResponse.infect_an_assertion :assert_cors_success, :must_render_cors_success, :only_one_argument
44
- Rack::MockResponse.infect_an_assertion :assert_not_cors_success, :wont_render_cors_success, :only_one_argument
45
-
46
- describe Rack::Cors do
47
- include Rack::Test::Methods
48
-
49
- attr_accessor :cors_result
50
-
51
- def load_app(name)
52
- test = self
53
- Rack::Builder.new do
54
- use CaptureResult, :holder => test
55
- eval File.read(File.dirname(__FILE__) + "/#{name}.ru")
56
- map('/') do
57
- run proc { |env|
58
- [200, {'Content-Type' => 'text/html'}, ['success']]
59
- }
60
- end
61
- end
62
- end
63
-
64
- let(:app) { load_app('test') }
65
-
66
- it 'should support simple CORS request' do
67
- successful_cors_request
68
- cors_result.must_be :hit
69
- end
70
-
71
- it "should not return CORS headers if Origin header isn't present" do
72
- get '/'
73
- last_response.wont_render_cors_success
74
- cors_result.wont_be :hit
75
- end
76
-
77
- it 'should support OPTIONS CORS request' do
78
- successful_cors_request '/options', :method => :options
79
- end
80
-
81
- it 'should support regex origins configuration' do
82
- successful_cors_request :origin => 'http://192.168.0.1:1234'
83
- end
84
-
85
- it 'should support subdomain example' do
86
- successful_cors_request :origin => 'http://subdomain.example.com'
87
- end
88
-
89
- it 'should support proc origins configuration' do
90
- successful_cors_request '/proc-origin', :origin => 'http://10.10.10.10:3000'
91
- end
92
-
93
- it 'should support lambda origin configuration' do
94
- successful_cors_request '/lambda-origin', :origin => 'http://10.10.10.10:3000'
95
- end
96
-
97
- it 'should support proc origins configuration (inverse)' do
98
- cors_request '/proc-origin', :origin => 'http://bad.guy'
99
- last_response.wont_render_cors_success
100
- end
101
-
102
- it 'should not mix up path rules across origins' do
103
- header 'Origin', 'http://10.10.10.10:3000'
104
- get '/' # / is configured in a separate rule block
105
- last_response.wont_render_cors_success
106
- end
107
-
108
- it 'should support alternative X-Origin header' do
109
- header 'X-Origin', 'http://localhost:3000'
110
- get '/'
111
- last_response.must_render_cors_success
112
- end
113
-
114
- it 'should support expose header configuration' do
115
- successful_cors_request '/expose_single_header'
116
- last_response.headers['Access-Control-Expose-Headers'].must_equal 'expose-test'
117
- end
118
-
119
- it 'should support expose multiple header configuration' do
120
- successful_cors_request '/expose_multiple_headers'
121
- last_response.headers['Access-Control-Expose-Headers'].must_equal 'expose-test-1, expose-test-2'
122
- end
123
-
124
- # Explanation: http://www.fastly.com/blog/best-practices-for-using-the-vary-header/
125
- it "should add Vary header if resource matches even if Origin header isn't present" do
126
- get '/'
127
- last_response.wont_render_cors_success
128
- last_response.headers['Vary'].must_equal 'Origin'
129
- end
130
-
131
- it "should add Vary header based on :vary option" do
132
- successful_cors_request '/vary_test'
133
- last_response.headers['Vary'].must_equal 'Origin, Host'
134
- end
135
-
136
- it 'should add Vary header if Access-Control-Allow-Origin header was added and if it is specific' do
137
- successful_cors_request '/', :origin => "http://192.168.0.3:8080"
138
- last_response.headers['Access-Control-Allow-Origin'].must_equal 'http://192.168.0.3:8080'
139
- last_response.headers['Vary'].wont_be_nil
140
- end
141
-
142
- it 'should add Vary header even if Access-Control-Allow-Origin header was added and it is generic (*)' do
143
- successful_cors_request '/public_without_credentials', :origin => "http://192.168.1.3:8080"
144
- last_response.headers['Access-Control-Allow-Origin'].must_equal '*'
145
- last_response.headers['Vary'].must_equal 'Origin'
146
- end
147
-
148
- it 'should support multi allow configurations for the same resource' do
149
- successful_cors_request '/multi-allow-config', :origin => "http://mucho-grande.com"
150
- last_response.headers['Access-Control-Allow-Origin'].must_equal 'http://mucho-grande.com'
151
- last_response.headers['Vary'].must_equal 'Origin'
152
-
153
- successful_cors_request '/multi-allow-config', :origin => "http://192.168.1.3:8080"
154
- last_response.headers['Access-Control-Allow-Origin'].must_equal '*'
155
- last_response.headers['Vary'].must_equal 'Origin'
156
- end
157
-
158
- it "should not return CORS headers on OPTIONS request if Access-Control-Allow-Origin is not present" do
159
- options '/get-only'
160
- last_response.headers['Access-Control-Allow-Origin'].must_be_nil
161
- end
162
-
163
- it "should not apply CORS headers if it does not match conditional on resource" do
164
- header 'Origin', 'http://192.168.0.1:1234'
165
- get '/conditional'
166
- last_response.wont_render_cors_success
167
- end
168
-
169
- it "should apply CORS headers if it does match conditional on resource" do
170
- header 'X-OK', '1'
171
- successful_cors_request '/conditional', :origin => 'http://192.168.0.1:1234'
172
- end
173
-
174
- it "should not allow everything if Origin is configured as blank string" do
175
- cors_request '/blank-origin', origin: "http://example.net"
176
- last_response.wont_render_cors_success
177
- end
178
-
179
- it "should not allow credentials for public resources" do
180
- successful_cors_request '/public'
181
- last_response.headers['Access-Control-Allow-Credentials'].must_be_nil
182
- end
183
-
184
- describe 'logging' do
185
- it 'should not log debug messages if debug option is false' do
186
- app = mock
187
- app.stubs(:call).returns(200, {}, [''])
188
-
189
- logger = mock
190
- logger.expects(:debug).never
191
-
192
- cors = Rack::Cors.new(app, :debug => false, :logger => logger) {}
193
- cors.send(:debug, {}, 'testing')
194
- end
195
-
196
- it 'should log debug messages if debug option is true' do
197
- app = mock
198
- app.stubs(:call).returns(200, {}, [''])
199
-
200
- logger = mock
201
- logger.expects(:debug)
202
-
203
- cors = Rack::Cors.new(app, :debug => true, :logger => logger) {}
204
- cors.send(:debug, {}, 'testing')
205
- end
206
-
207
- it 'should use rack.logger if available' do
208
- app = mock
209
- app.stubs(:call).returns([200, {}, ['']])
210
-
211
- logger = mock
212
- logger.expects(:debug).at_least_once
213
-
214
- cors = Rack::Cors.new(app, :debug => true) {}
215
- cors.call({'rack.logger' => logger, 'HTTP_ORIGIN' => 'test.com'})
216
- end
217
-
218
- it 'should use logger proc' do
219
- app = mock
220
- app.stubs(:call).returns([200, {}, ['']])
221
-
222
- logger = mock
223
- logger.expects(:debug)
224
-
225
- cors = Rack::Cors.new(app, :debug => true, :logger => proc { logger }) {}
226
- cors.call({'HTTP_ORIGIN' => 'test.com'})
227
- end
228
-
229
- describe 'with Rails setup' do
230
- after do
231
- ::Rails.logger = nil if defined?(::Rails)
232
- end
233
-
234
- it 'should use Rails.logger if available' do
235
- app = mock
236
- app.stubs(:call).returns([200, {}, ['']])
237
-
238
- logger = mock
239
- logger.expects(:debug)
240
-
241
- ::Rails = OpenStruct.new(:logger => logger)
242
-
243
- cors = Rack::Cors.new(app, :debug => true) {}
244
- cors.call({'HTTP_ORIGIN' => 'test.com'})
245
- end
246
- end
247
- end
248
-
249
- describe 'preflight requests' do
250
- it 'should fail if origin is invalid' do
251
- preflight_request('http://allyourdataarebelongtous.com', '/')
252
- last_response.wont_render_cors_success
253
- cors_result.wont_be :hit
254
- cors_result.must_be :preflight
255
- end
256
-
257
- it 'should fail if Access-Control-Request-Method is not allowed' do
258
- preflight_request('http://localhost:3000', '/get-only', :method => :post)
259
- last_response.wont_render_cors_success
260
- cors_result.miss_reason.must_equal Rack::Cors::Result::MISS_DENY_METHOD
261
- cors_result.wont_be :hit
262
- cors_result.must_be :preflight
263
- end
264
-
265
- it 'should fail if header is not allowed' do
266
- preflight_request('http://localhost:3000', '/single_header', :headers => 'Fooey')
267
- last_response.wont_render_cors_success
268
- cors_result.miss_reason.must_equal Rack::Cors::Result::MISS_DENY_HEADER
269
- cors_result.wont_be :hit
270
- cors_result.must_be :preflight
271
- end
272
-
273
- it 'should allow any header if headers = :any' do
274
- preflight_request('http://localhost:3000', '/', :headers => 'Fooey')
275
- last_response.must_render_cors_success
276
- end
277
-
278
- it 'should allow any method if methods = :any' do
279
- preflight_request('http://localhost:3000', '/', :methods => :any)
280
- last_response.must_render_cors_success
281
- end
282
-
283
- it 'should allow header case insensitive match' do
284
- preflight_request('http://localhost:3000', '/single_header', :headers => 'X-Domain-Token')
285
- last_response.must_render_cors_success
286
- end
287
-
288
- it 'should allow multiple headers match' do
289
- # Webkit style
290
- preflight_request('http://localhost:3000', '/two_headers', :headers => 'X-Requested-With, X-Domain-Token')
291
- last_response.must_render_cors_success
292
-
293
- # Gecko style
294
- preflight_request('http://localhost:3000', '/two_headers', :headers => 'x-requested-with,x-domain-token')
295
- last_response.must_render_cors_success
296
- end
297
-
298
- it 'should * origin should allow any origin' do
299
- preflight_request('http://locohost:3000', '/public')
300
- last_response.must_render_cors_success
301
- last_response.headers['Access-Control-Allow-Origin'].must_equal '*'
302
- end
303
-
304
- it 'should * origin should allow any origin, and set * if no credentials required' do
305
- preflight_request('http://locohost:3000', '/public_without_credentials')
306
- last_response.must_render_cors_success
307
- last_response.headers['Access-Control-Allow-Origin'].must_equal '*'
308
- end
309
-
310
- it 'should return "file://" as header with "file://" as origin' do
311
- preflight_request('file://', '/')
312
- last_response.must_render_cors_success
313
- last_response.headers['Access-Control-Allow-Origin'].must_equal 'file://'
314
- end
315
-
316
- it 'should return a Content-Type' do
317
- preflight_request('http://localhost:3000', '/')
318
- last_response.must_render_cors_success
319
- last_response.headers['Content-Type'].wont_be_nil
320
- end
321
-
322
- describe '' do
323
-
324
- let(:app) do
325
- test = self
326
- Rack::Builder.new do
327
- use CaptureResult, holder: test
328
- use Rack::Cors, debug: true, logger: Logger.new(StringIO.new) do
329
- allow do
330
- origins '*'
331
- resource '/', :methods => :post
332
- end
333
- end
334
- map('/') do
335
- run ->(env) { [500, {'Content-Type' => 'text/plain'}, ['FAIL!']] }
336
- end
337
- end
338
- end
339
-
340
- it "should not send failed preflight requests thru the app" do
341
- preflight_request('http://localhost', '/', :method => :unsupported)
342
- last_response.wont_render_cors_success
343
- last_response.status.must_equal 200
344
- cors_result.must_be :preflight
345
- cors_result.wont_be :hit
346
- cors_result.miss_reason.must_equal Rack::Cors::Result::MISS_DENY_METHOD
347
- end
348
- end
349
- end
350
-
351
- describe "with insecure configuration" do
352
- let(:app) { load_app('insecure') }
353
-
354
- it "should raise an error" do
355
- proc { cors_request '/public' }.must_raise Rack::Cors::Resource::CorsMisconfigurationError
356
- end
357
- end
358
-
359
- describe "with non HTTP config" do
360
- let(:app) { load_app("non_http") }
361
-
362
- it 'should support non http/https origins' do
363
- successful_cors_request '/public', origin: 'content://com.company.app'
364
- end
365
- end
366
-
367
- describe 'Rack::Lint' do
368
- def app
369
- @app ||= Rack::Builder.new do
370
- use Rack::Cors
371
- use Rack::Lint
372
- run ->(env) { [200, {'Content-Type' => 'text/html'}, ['hello']] }
373
- end
374
- end
375
-
376
- it 'is lint-compliant with non-CORS request' do
377
- get '/'
378
- last_response.status.must_equal 200
379
- end
380
- end
381
-
382
- describe 'with app overriding CORS header' do
383
- let(:app) do
384
- Rack::Builder.new do
385
- use Rack::Cors, debug: true, logger: Logger.new(StringIO.new) do
386
- allow do
387
- origins '*'
388
- resource '/'
389
- end
390
- end
391
- map('/') do
392
- run ->(env) { [200, {'Content-Type' => 'text/plain', 'Access-Control-Allow-Origin' => 'http://foo.net'}, ['success']] }
393
- end
394
- end
395
- end
396
-
397
- it "should return app header" do
398
- successful_cors_request origin: "http://example.net"
399
- last_response.headers['Access-Control-Allow-Origin'].must_equal "http://foo.net"
400
- end
401
-
402
- it "should return original headers if in debug" do
403
- successful_cors_request origin: "http://example.net"
404
- last_response.headers['X-Rack-CORS-Original-Access-Control-Allow-Origin'].must_equal "*"
405
- end
406
- end
407
-
408
- describe 'with headers set to nil' do
409
- let(:app) do
410
- Rack::Builder.new do
411
- use Rack::Cors do
412
- allow do
413
- origins '*'
414
- resource '/', headers: nil
415
- end
416
- end
417
- map('/') do
418
- run ->(env) { [200, {'Content-Type' => 'text/html'}, ['hello']] }
419
- end
420
- end
421
- end
422
-
423
- it 'should succeed with CORS simple headers' do
424
- preflight_request('http://localhost:3000', '/', :headers => 'Accept')
425
- last_response.must_render_cors_success
426
- end
427
- end
428
-
429
- describe 'with custom allowed headers' do
430
- let(:app) do
431
- Rack::Builder.new do
432
- use Rack::Cors do
433
- allow do
434
- origins '*'
435
- resource '/', headers: []
436
- end
437
- end
438
- map('/') do
439
- run ->(env) { [200, {'Content-Type' => 'text/html'}, ['hello']] }
440
- end
441
- end
442
- end
443
-
444
- it 'should succeed with CORS simple headers' do
445
- preflight_request('http://localhost:3000', '/', :headers => 'Accept')
446
- last_response.must_render_cors_success
447
- preflight_request('http://localhost:3000', '/', :headers => 'Accept-Language')
448
- last_response.must_render_cors_success
449
- preflight_request('http://localhost:3000', '/', :headers => 'Content-Type')
450
- last_response.must_render_cors_success
451
- preflight_request('http://localhost:3000', '/', :headers => 'Content-Language')
452
- last_response.must_render_cors_success
453
- end
454
- end
455
-
456
- protected
457
- def cors_request(*args)
458
- path = args.first.is_a?(String) ? args.first : '/'
459
-
460
- opts = { :method => :get, :origin => 'http://localhost:3000' }
461
- opts.merge! args.last if args.last.is_a?(Hash)
462
-
463
- header 'Origin', opts[:origin]
464
- current_session.__send__ opts[:method], path, {}, test: self
465
- end
466
-
467
- def successful_cors_request(*args)
468
- cors_request(*args)
469
- last_response.must_render_cors_success
470
- end
471
-
472
- def preflight_request(origin, path, opts = {})
473
- header 'Origin', origin
474
- unless opts.key?(:method) && opts[:method].nil?
475
- header 'Access-Control-Request-Method', opts[:method] ? opts[:method].to_s.upcase : 'GET'
476
- end
477
- if opts[:headers]
478
- header 'Access-Control-Request-Headers', opts[:headers]
479
- end
480
- options path
481
- end
482
- end
@@ -1,69 +0,0 @@
1
- require 'rubygems'
2
- require 'minitest/autorun'
3
- require 'rack/cors'
4
-
5
-
6
- describe Rack::Cors, 'DSL' do
7
- it 'should support explicit config object dsl mode' do
8
- cors = Rack::Cors.new(Proc.new {}) do |cfg|
9
- cfg.allow do |allow|
10
- allow.origins 'localhost:3000', '127.0.0.1:3000' do |source,env|
11
- source == "http://10.10.10.10:3000" &&
12
- env["USER_AGENT"] == "test-agent"
13
- end
14
- allow.resource '/get-only', :methods => :get
15
- allow.resource '/', :headers => :any
16
- end
17
- end
18
- resources = cors.send :all_resources
19
-
20
- resources.length.must_equal 1
21
- resources.first.allow_origin?('http://localhost:3000').must_equal true
22
- resources.first.allow_origin?('http://10.10.10.10:3000',{"USER_AGENT" => "test-agent" }).must_equal true
23
- resources.first.allow_origin?('http://10.10.10.10:3001',{"USER_AGENT" => "test-agent" }).wont_equal true
24
- resources.first.allow_origin?('http://10.10.10.10:3000',{"USER_AGENT" => "other-agent"}).wont_equal true
25
- end
26
-
27
- it 'should support implicit config object dsl mode' do
28
- cors = Rack::Cors.new(Proc.new {}) do
29
- allow do
30
- origins 'localhost:3000', '127.0.0.1:3000' do |source,env|
31
- source == "http://10.10.10.10:3000" &&
32
- env["USER_AGENT"] == "test-agent"
33
- end
34
- resource '/get-only', :methods => :get
35
- resource '/', :headers => :any
36
- end
37
- end
38
- resources = cors.send :all_resources
39
-
40
- resources.length.must_equal 1
41
- resources.first.allow_origin?('http://localhost:3000').must_equal true
42
- resources.first.allow_origin?('http://10.10.10.10:3000',{"USER_AGENT" => "test-agent" }).must_equal true
43
- resources.first.allow_origin?('http://10.10.10.10:3001',{"USER_AGENT" => "test-agent" }).wont_equal true
44
- resources.first.allow_origin?('http://10.10.10.10:3000',{"USER_AGENT" => "other-agent"}).wont_equal true
45
- end
46
-
47
- it 'should support "file://" origin' do
48
- cors = Rack::Cors.new(Proc.new {}) do
49
- allow do
50
- origins 'file://'
51
- resource '/', :headers => :any
52
- end
53
- end
54
- resources = cors.send :all_resources
55
-
56
- resources.first.allow_origin?('file://').must_equal true
57
- end
58
-
59
- it 'should default credentials option to false' do
60
- cors = Rack::Cors.new(Proc.new {}) do
61
- allow do
62
- origins 'example.net'
63
- resource '/', :headers => :any
64
- end
65
- end
66
- resources = cors.send :all_resources
67
- resources.first.resources.first.credentials.must_equal false
68
- end
69
- end
@@ -1,8 +0,0 @@
1
- require 'rack/cors'
2
-
3
- use Rack::Cors do
4
- allow do
5
- origins '*'
6
- resource '/public', credentials: true
7
- end
8
- end