rack-cors 1.1.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,63 +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 '/wildcard/*', :methods => :any
24
- # resource '/file/at/*',
25
- # :methods => [:get, :post, :put, :delete],
26
- # :headers => :any,
27
- # :max_age => 0
28
- end
29
-
30
- allow do
31
- origins do |source,env|
32
- source.end_with?("10.10.10.10:3000")
33
- end
34
- resource '/proc-origin'
35
- end
36
-
37
- allow do
38
- origins -> (source, env) { source.end_with?("10.10.10.10:3000") }
39
- resource '/lambda-origin'
40
- end
41
-
42
- allow do
43
- origins '*'
44
- resource '/public'
45
- resource '/public/*'
46
- resource '/public_without_credentials', :credentials => false
47
- end
48
-
49
- allow do
50
- origins 'mucho-grande.com'
51
- resource '/multi-allow-config', :max_age => 600
52
- end
53
-
54
- allow do
55
- origins '*'
56
- resource '/multi-allow-config', :max_age => 300, :credentials => false
57
- end
58
-
59
- allow do
60
- origins ''
61
- resource '/blank-origin'
62
- end
63
- end