rack-cors 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack-cors might be problematic. Click here for more details.
- checksums.yaml +15 -0
- data/Gemfile +3 -11
- data/LICENSE.txt +3 -1
- data/README.rdoc +9 -6
- data/Rakefile +2 -27
- data/lib/rack/cors.rb +11 -5
- data/lib/rack/cors/version.rb +5 -0
- data/rack-cors.gemspec +22 -63
- data/test/cors/expect.js +1286 -0
- data/test/cors/mocha.css +250 -0
- data/test/cors/mocha.js +5373 -0
- data/test/cors/runner.html +20 -0
- data/test/cors/test.cors.coffee +23 -0
- data/test/cors/test.cors.js +34 -0
- data/test/unit/cors_test.rb +22 -10
- data/test/unit/dsl_test.rb +1 -0
- data/test/unit/test.ru +12 -0
- metadata +33 -66
- data/VERSION +0 -1
@@ -0,0 +1,20 @@
|
|
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>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
CORS_SERVER = 'cors-server:3000'
|
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 access to static resource', (done) ->
|
11
|
+
$.get "http://#{CORS_SERVER}/static.txt", (data, status, xhr) ->
|
12
|
+
expect($.trim(data)).to.eql("hello world")
|
13
|
+
done()
|
14
|
+
|
15
|
+
it 'should allow post resource', (done) ->
|
16
|
+
$.ajax
|
17
|
+
type: 'POST'
|
18
|
+
url: "http://#{CORS_SERVER}/cors"
|
19
|
+
beforeSend: (xhr) -> xhr.setRequestHeader('X-Requested-With', 'XMLHTTPRequest')
|
20
|
+
success:(data, status, xhr) ->
|
21
|
+
expect($.trim(data)).to.eql("OK!")
|
22
|
+
done()
|
23
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
(function() {
|
2
|
+
var CORS_SERVER;
|
3
|
+
|
4
|
+
CORS_SERVER = 'cors-server:3000';
|
5
|
+
|
6
|
+
describe('CORS', function() {
|
7
|
+
it('should allow access to dynamic resource', function(done) {
|
8
|
+
return $.get("http://" + CORS_SERVER + "/", function(data, status, xhr) {
|
9
|
+
expect(data).to.eql('Hello world');
|
10
|
+
return done();
|
11
|
+
});
|
12
|
+
});
|
13
|
+
it('should allow access to static resource', function(done) {
|
14
|
+
return $.get("http://" + CORS_SERVER + "/static.txt", function(data, status, xhr) {
|
15
|
+
expect($.trim(data)).to.eql("hello world");
|
16
|
+
return done();
|
17
|
+
});
|
18
|
+
});
|
19
|
+
return it('should allow post resource', function(done) {
|
20
|
+
return $.ajax({
|
21
|
+
type: 'POST',
|
22
|
+
url: "http://" + CORS_SERVER + "/cors",
|
23
|
+
beforeSend: function(xhr) {
|
24
|
+
return xhr.setRequestHeader('X-Requested-With', 'XMLHTTPRequest');
|
25
|
+
},
|
26
|
+
success: function(data, status, xhr) {
|
27
|
+
expect($.trim(data)).to.eql("OK!");
|
28
|
+
return done();
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
34
|
+
}).call(this);
|
data/test/unit/cors_test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'test/unit'
|
2
3
|
require 'rack/test'
|
3
4
|
require 'shoulda'
|
4
|
-
require 'mocha'
|
5
|
+
require 'mocha/setup'
|
5
6
|
require 'rack/cors'
|
6
7
|
|
7
8
|
Rack::Test::Session.class_eval do
|
@@ -24,6 +25,10 @@ class CorsTest < Test::Unit::TestCase
|
|
24
25
|
|
25
26
|
should('support simple cors request') { cors_request }
|
26
27
|
|
28
|
+
should 'support OPTIONS cors request' do
|
29
|
+
cors_request '/options', :method => :options
|
30
|
+
end
|
31
|
+
|
27
32
|
should 'support regex origins configuration' do
|
28
33
|
cors_request :origin => 'http://192.168.0.1:1234'
|
29
34
|
end
|
@@ -62,6 +67,18 @@ class CorsTest < Test::Unit::TestCase
|
|
62
67
|
assert_nil last_response.headers['Vary'], 'no expecting Vary header'
|
63
68
|
end
|
64
69
|
|
70
|
+
should 'support multi allow configurations for the same resource' do
|
71
|
+
cors_request '/multi-allow-config', :origin => "http://mucho-grande.com"
|
72
|
+
assert_cors_success
|
73
|
+
assert_equal 'http://mucho-grande.com', last_response.headers['Access-Control-Allow-Origin']
|
74
|
+
assert_equal 'Origin', last_response.headers['Vary'], 'expecting Vary header'
|
75
|
+
|
76
|
+
cors_request '/multi-allow-config', :origin => "http://192.168.1.3:8080"
|
77
|
+
assert_cors_success
|
78
|
+
assert_equal '*', last_response.headers['Access-Control-Allow-Origin']
|
79
|
+
assert_nil last_response.headers['Vary'], 'no expecting Vary header'
|
80
|
+
end
|
81
|
+
|
65
82
|
should 'not log debug messages if debug option is false' do
|
66
83
|
app = mock
|
67
84
|
app.stubs(:call).returns(200, {}, [''])
|
@@ -90,11 +107,6 @@ class CorsTest < Test::Unit::TestCase
|
|
90
107
|
assert_cors_failure
|
91
108
|
end
|
92
109
|
|
93
|
-
should 'fail if Access-Control-Request-Method does not exist' do
|
94
|
-
preflight_request('http://localhost:3000', '/', :method => nil)
|
95
|
-
assert_cors_failure
|
96
|
-
end
|
97
|
-
|
98
110
|
should 'fail if Access-Control-Request-Method is not allowed' do
|
99
111
|
preflight_request('http://localhost:3000', '/get-only', :method => :post)
|
100
112
|
assert_cors_failure
|
@@ -154,11 +166,11 @@ class CorsTest < Test::Unit::TestCase
|
|
154
166
|
def cors_request(*args)
|
155
167
|
path = args.first.is_a?(String) ? args.first : '/'
|
156
168
|
|
157
|
-
opts =
|
158
|
-
|
169
|
+
opts = { :method => :get, :origin => 'http://localhost:3000' }
|
170
|
+
opts.merge! args.last if args.last.is_a?(Hash)
|
159
171
|
|
160
|
-
header 'Origin', origin
|
161
|
-
|
172
|
+
header 'Origin', opts[:origin]
|
173
|
+
current_session.__send__ opts[:method], path
|
162
174
|
assert_cors_success
|
163
175
|
end
|
164
176
|
|
data/test/unit/dsl_test.rb
CHANGED
data/test/unit/test.ru
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'rack/cors'
|
2
2
|
|
3
|
+
#use Rack::Cors, :debug => true, :logger => ::Logger.new(STDOUT) do
|
3
4
|
use Rack::Cors do
|
4
5
|
allow do
|
5
6
|
origins 'localhost:3000', '127.0.0.1:3000', /http:\/\/192\.168\.0\.\d{1,3}(:\d+)?/, 'file://'
|
6
7
|
|
7
8
|
resource '/get-only', :methods => :get
|
8
9
|
resource '/', :headers => :any
|
10
|
+
resource '/options', :methods => :options
|
9
11
|
resource '/single_header', :headers => 'x-domain-token'
|
10
12
|
resource '/two_headers', :headers => %w{x-domain-token x-requested-with}
|
11
13
|
resource '/expose_single_header', :expose => 'expose-test'
|
@@ -28,6 +30,16 @@ use Rack::Cors do
|
|
28
30
|
resource '/public'
|
29
31
|
resource '/public_without_credentials', :credentials => false
|
30
32
|
end
|
33
|
+
|
34
|
+
allow do
|
35
|
+
origins 'mucho-grande.com'
|
36
|
+
resource '/multi-allow-config', :max_age => 600
|
37
|
+
end
|
38
|
+
|
39
|
+
allow do
|
40
|
+
origins '*'
|
41
|
+
resource '/multi-allow-config', :max_age => 300, :credentials => false
|
42
|
+
end
|
31
43
|
end
|
32
44
|
|
33
45
|
map '/' do
|
metadata
CHANGED
@@ -1,36 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.9
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Calvin Yu
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
22
|
-
type: :
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
26
|
+
version: '1.3'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -46,7 +41,6 @@ dependencies:
|
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: shoulda
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
45
|
- - ! '>='
|
52
46
|
- !ruby/object:Gem::Version
|
@@ -54,7 +48,6 @@ dependencies:
|
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
52
|
- - ! '>='
|
60
53
|
- !ruby/object:Gem::Version
|
@@ -62,23 +55,20 @@ dependencies:
|
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: mocha
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
59
|
- - ! '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
61
|
+
version: 0.14.0
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
66
|
- - ! '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
68
|
+
version: 0.14.0
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rack-test
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
73
|
- - ! '>='
|
84
74
|
- !ruby/object:Gem::Version
|
@@ -86,89 +76,66 @@ dependencies:
|
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
80
|
- - ! '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: bundler
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 1.1.0
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: 1.1.0
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: jeweler
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ~>
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 1.8.3
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ~>
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: 1.8.3
|
126
83
|
description: ! 'Middleware that will make Rack-based apps CORS compatible. Read more
|
127
84
|
here: http://blog.sourcebender.com/2010/06/09/introducin-rack-cors.html. Fork the
|
128
85
|
project here: http://github.com/cyu/rack-cors'
|
129
|
-
email:
|
86
|
+
email:
|
87
|
+
- me@sourcebender.com
|
130
88
|
executables: []
|
131
89
|
extensions: []
|
132
|
-
extra_rdoc_files:
|
133
|
-
- LICENSE.txt
|
134
|
-
- README.rdoc
|
90
|
+
extra_rdoc_files: []
|
135
91
|
files:
|
136
92
|
- Gemfile
|
137
93
|
- LICENSE.txt
|
138
94
|
- README.rdoc
|
139
95
|
- Rakefile
|
140
|
-
- VERSION
|
141
96
|
- lib/rack/cors.rb
|
97
|
+
- lib/rack/cors/version.rb
|
142
98
|
- rack-cors.gemspec
|
99
|
+
- test/cors/expect.js
|
100
|
+
- test/cors/mocha.css
|
101
|
+
- test/cors/mocha.js
|
102
|
+
- test/cors/runner.html
|
103
|
+
- test/cors/test.cors.coffee
|
104
|
+
- test/cors/test.cors.js
|
143
105
|
- test/unit/cors_test.rb
|
144
106
|
- test/unit/dsl_test.rb
|
145
107
|
- test/unit/test.ru
|
146
108
|
homepage: http://github.com/cyu/rack-cors
|
147
109
|
licenses:
|
148
110
|
- MIT
|
111
|
+
metadata: {}
|
149
112
|
post_install_message:
|
150
113
|
rdoc_options: []
|
151
114
|
require_paths:
|
152
115
|
- lib
|
153
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
117
|
requirements:
|
156
118
|
- - ! '>='
|
157
119
|
- !ruby/object:Gem::Version
|
158
120
|
version: '0'
|
159
|
-
segments:
|
160
|
-
- 0
|
161
|
-
hash: -1437619420423070521
|
162
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
-
none: false
|
164
122
|
requirements:
|
165
123
|
- - ! '>='
|
166
124
|
- !ruby/object:Gem::Version
|
167
125
|
version: '0'
|
168
126
|
requirements: []
|
169
127
|
rubyforge_project:
|
170
|
-
rubygems_version: 1.
|
128
|
+
rubygems_version: 2.1.9
|
171
129
|
signing_key:
|
172
|
-
specification_version:
|
130
|
+
specification_version: 4
|
173
131
|
summary: Middleware for enabling Cross-Origin Resource Sharing in Rack apps
|
174
|
-
test_files:
|
132
|
+
test_files:
|
133
|
+
- test/cors/expect.js
|
134
|
+
- test/cors/mocha.css
|
135
|
+
- test/cors/mocha.js
|
136
|
+
- test/cors/runner.html
|
137
|
+
- test/cors/test.cors.coffee
|
138
|
+
- test/cors/test.cors.js
|
139
|
+
- test/unit/cors_test.rb
|
140
|
+
- test/unit/dsl_test.rb
|
141
|
+
- test/unit/test.ru
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.8
|