rack-cors 1.0.5 → 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,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
@@ -1,8 +0,0 @@
1
- require 'rack/cors'
2
-
3
- use Rack::Cors do
4
- allow do
5
- origins 'com.company.app'
6
- resource '/public'
7
- end
8
- end
data/test/unit/test.ru DELETED
@@ -1,62 +0,0 @@
1
- require 'rack/cors'
2
-
3
- #use Rack::Cors, :debug => true, :logger => ::Logger.new(STDOUT) do
4
- use Rack::Lint
5
- use Rack::Cors do
6
- allow do
7
- origins 'localhost:3000',
8
- '127.0.0.1:3000',
9
- /http:\/\/192\.168\.0\.\d{1,3}(:\d+)?/,
10
- 'file://',
11
- /http:\/\/(.*?)\.example\.com/
12
-
13
- resource '/get-only', :methods => :get
14
- resource '/', :headers => :any, :methods => :any
15
- resource '/options', :methods => :options
16
- resource '/single_header', :headers => 'x-domain-token'
17
- resource '/two_headers', :headers => %w{x-domain-token x-requested-with}
18
- resource '/expose_single_header', :expose => 'expose-test'
19
- resource '/expose_multiple_headers', :expose => %w{expose-test-1 expose-test-2}
20
- resource '/conditional', :methods => :get, :if => proc { |env| !!env['HTTP_X_OK'] }
21
- resource '/vary_test', :methods => :get, :vary => %w{ Origin Host }
22
- resource '/patch_test', :methods => :patch
23
- # resource '/file/at/*',
24
- # :methods => [:get, :post, :put, :delete],
25
- # :headers => :any,
26
- # :max_age => 0
27
- end
28
-
29
- allow do
30
- origins do |source,env|
31
- source.end_with?("10.10.10.10:3000")
32
- end
33
- resource '/proc-origin'
34
- end
35
-
36
- allow do
37
- origins -> (source, env) { source.end_with?("10.10.10.10:3000") }
38
- resource '/lambda-origin'
39
- end
40
-
41
- allow do
42
- origins '*'
43
- resource '/public'
44
- resource '/public/*'
45
- resource '/public_without_credentials', :credentials => false
46
- end
47
-
48
- allow do
49
- origins 'mucho-grande.com'
50
- resource '/multi-allow-config', :max_age => 600
51
- end
52
-
53
- allow do
54
- origins '*'
55
- resource '/multi-allow-config', :max_age => 300, :credentials => false
56
- end
57
-
58
- allow do
59
- origins ''
60
- resource '/blank-origin'
61
- end
62
- end