kris-kross 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Guardfile +13 -0
- data/LICENSE +22 -0
- data/README.md +144 -0
- data/Rakefile +2 -0
- data/kris-kross.gemspec +21 -0
- data/lib/kris-kross.rb +24 -0
- data/lib/kris-kross/configuration.rb +50 -0
- data/lib/kris-kross/handler.rb +45 -0
- data/lib/kris-kross/railtie.rb +9 -0
- data/lib/kris-kross/version.rb +5 -0
- data/spec/kris-kross/configuration_spec.rb +101 -0
- data/spec/kris-kross/handler_spec.rb +75 -0
- data/spec/kris-kross_spec.rb +33 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/configuration.rb +8 -0
- data/spec/support/singleton.rb +15 -0
- metadata +119 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#^syntax detection
|
3
|
+
|
4
|
+
# A sample Guardfile
|
5
|
+
# More info at https://github.com/guard/guard#readme
|
6
|
+
|
7
|
+
guard 'rspec', cli: '--color' do
|
8
|
+
watch(%r{^kris-kross\.gemspec}) { "spec"}
|
9
|
+
watch(%r{^spec/.+_spec\.rb$})
|
10
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
11
|
+
watch('spec/spec_helper.rb') { "spec" }
|
12
|
+
end
|
13
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Eric Saxby
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
Kris::Kross
|
2
|
+
===========
|
3
|
+
|
4
|
+
Kris Kross will make you jump jump between domains with cross origin requests. Have you read
|
5
|
+
that RFC? It's F-en crazy! What headers do you set where, and who do you tell what to make those
|
6
|
+
requests actually go through?
|
7
|
+
|
8
|
+
This gem will totally kross out your confusion, and you'll be left young, rich and dangerous to
|
9
|
+
certify your gold-plated programming skills.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'kris-kross'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
This gem is built to work with Rails 3 applications.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Including `kris-kross` in a Rails 3 application automatically adds it to the Middleware chain.
|
28
|
+
Configure it in an initializer:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Kris::Kross.configure do |c|
|
32
|
+
c.origins %w{ http://my-domain http://my-other-domain}
|
33
|
+
end
|
34
|
+
```
|
35
|
+
|
36
|
+
The HTTP protocol desired (http/https) should be explicitly set in the configuration block. Kris Kross
|
37
|
+
makes no assumptions about this.
|
38
|
+
|
39
|
+
### Custom Headers
|
40
|
+
|
41
|
+
Cors does some extra checking if you send custom headers in your cross origin requests. You can configure
|
42
|
+
Kris Kross to accept those headers in the following way:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Kris::Kross.configure do |c|
|
46
|
+
c.origins %w{ http://my-domain}
|
47
|
+
c.headers %w{X-Mac-Daddy X-Daddy-Mac}
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
These get mixed into a set of default values and returns to clients as `Access-Control-Allow-Headers`.
|
52
|
+
|
53
|
+
### Wildcard domains (not!)
|
54
|
+
|
55
|
+
Kris Kross can not be configured to open domains to wildcard cross origin requests. Kris Kross is crazy,
|
56
|
+
but not that crazy.
|
57
|
+
|
58
|
+
## Cross Origin Requests explained
|
59
|
+
|
60
|
+
Let's say you have a domain `http://make-my-video.com`, from which you serve an amazing javascript-based
|
61
|
+
video game. With the overwhelming popularity of the site, you are starting to worry that over the weekend
|
62
|
+
the it may go down.
|
63
|
+
|
64
|
+
You move all the logic around saving state to `http://saves.make-my-video.com`, but notice at the last minute
|
65
|
+
that nothing is making it through to those servers. What are you going to do???
|
66
|
+
|
67
|
+
First, you drop `gem kris-kross` into your Gemfile.
|
68
|
+
|
69
|
+
Second, you create the file `#{Rails.root}/config/initializers/kris-kross.rb` in
|
70
|
+
both `make-my-video.com` and `saves.make-my-video.com`:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
Kris::Kross.configure do |c|
|
74
|
+
c.origins %w{ http://make-my-video.com }
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### Client interactions
|
79
|
+
|
80
|
+
When a web browser hits your site, the Kris Kross rack middleware will mix in some response headers. You can see
|
81
|
+
this by hitting your domain with curl:
|
82
|
+
|
83
|
+
```bash
|
84
|
+
> curl http://make-my-video.com -I
|
85
|
+
HTTP/1.1 200 OK
|
86
|
+
Server: nginx/1.2.4
|
87
|
+
Date: Thu, 6 Feb 1992 18:03:07 GMT
|
88
|
+
Content-Type: text/html; charset=utf-8
|
89
|
+
Content-Length: 23497
|
90
|
+
Connection: close
|
91
|
+
Status: 200 OK
|
92
|
+
Access-Control-Allow-Origin: http://make-my-video.com
|
93
|
+
Access-Control-Allow-Credentials: true
|
94
|
+
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
|
95
|
+
Pragma: no-cache
|
96
|
+
Expires: Wed, 09 Sep 1972 09:09:09 GMT
|
97
|
+
X-UA-Compatible: IE=Edge
|
98
|
+
ETag: "7ccdafcac2e2d541fd69823d290126d6"
|
99
|
+
X-Request-Id: f7c0684f1bc06321039b55d3c431d81b
|
100
|
+
X-Runtime: 0.762781
|
101
|
+
```
|
102
|
+
|
103
|
+
The browser now knows that you know you have potential cross origin requests, and from where. This is only half
|
104
|
+
of the picture, though. When the browser tries to do a cross origin request it first tests the crossed domain.
|
105
|
+
It does this with what is called a preflight check.
|
106
|
+
|
107
|
+
Preflight checks hit the cross origin domain with an HTTP call using the OPTIONS verb. Wait, never heard of OPTIONS?
|
108
|
+
Test it out with another bit of curl:
|
109
|
+
|
110
|
+
```bash
|
111
|
+
> curl -X OPTIONS http://saves.make-my-video.com -I
|
112
|
+
HTTP/1.1 200 OK
|
113
|
+
Server: nginx/1.2.4
|
114
|
+
Date: Thu, 6 Feb 1992 18:09:12 GMT
|
115
|
+
Transfer-Encoding: chunked
|
116
|
+
Connection: close
|
117
|
+
Status: 200 OK
|
118
|
+
Access-Control-Allow-Origin: http://make-my-video.com
|
119
|
+
Access-Control-Allow-Methods: POST, GET, OPTIONS
|
120
|
+
Access-Control-Allow-Headers: X-Requested-With, X-Prototype-Version, Authorization, Authentication
|
121
|
+
Access-Control-Max-Age: 172800
|
122
|
+
Access-Control-Allow-Credentials: true
|
123
|
+
X-UA-Compatible: IE=Edge
|
124
|
+
Cache-Control: no-cache
|
125
|
+
X-Request-Id: b287f0b81f5711c659df1caa2d749568
|
126
|
+
X-Runtime: 0.140053
|
127
|
+
```
|
128
|
+
|
129
|
+
Notice that in these examples, the `Access-Control-Allow-Origin` headers all refer to the main domain,
|
130
|
+
`make-my-video.com` and not to the cross origin domain.
|
131
|
+
|
132
|
+
## References
|
133
|
+
|
134
|
+
* http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
|
135
|
+
* http://www.w3.org/TR/cors/
|
136
|
+
* https://developer.mozilla.org/en-US/docs/HTTP_access_control
|
137
|
+
|
138
|
+
## Contributing
|
139
|
+
|
140
|
+
1. Fork it
|
141
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
142
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
143
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
144
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/kris-kross.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/kris-kross/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Eric Saxby"]
|
6
|
+
gem.email = ["sax@wanelo.com"]
|
7
|
+
gem.description = %q{Kris Kross will make you jump jump between domains with cross origin requests}
|
8
|
+
gem.summary = %q{Cross origin requests made easy}
|
9
|
+
gem.homepage = "https://github.com/wanelo/kris-kross"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "kris-kross"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Kris::Kross::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
gem.add_development_dependency 'guard-rspec'
|
20
|
+
gem.add_development_dependency 'rb-fsevent'
|
21
|
+
end
|
data/lib/kris-kross.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "kris-kross/version"
|
2
|
+
require "kris-kross/configuration"
|
3
|
+
require "kris-kross/handler"
|
4
|
+
|
5
|
+
module Kris
|
6
|
+
class Kross
|
7
|
+
# Does Kris live inside Kross, or does Kross live inside Kris?
|
8
|
+
# This is like a crazy X-Files episode!
|
9
|
+
|
10
|
+
def self.configure(&block)
|
11
|
+
Kris::Kross::Configuration.instance.configure(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(app)
|
15
|
+
Kris::Kross::Handler.instance.app = app
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
Kris::Kross::Handler.instance.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "kris-kross/railtie" if defined? Rails
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Kris
|
4
|
+
class Kross
|
5
|
+
class Configuration
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_writer :origins, :headers
|
9
|
+
|
10
|
+
def configure
|
11
|
+
yield self
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def origins(hostnames = nil)
|
16
|
+
if hostnames.nil?
|
17
|
+
[@origins].flatten
|
18
|
+
else
|
19
|
+
@origins = hostnames
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def headers(headers = nil)
|
24
|
+
if headers.nil?
|
25
|
+
(default_headers + [@headers]).flatten.compact.join(' ')
|
26
|
+
else
|
27
|
+
@headers = headers
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.origins
|
32
|
+
@origins ||= self.instance.origins
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.hosts
|
36
|
+
@hosts ||= origins.join(' ')
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.headers
|
40
|
+
@headers ||= self.instance.headers
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def default_headers
|
46
|
+
%w{X-Requested-With X-Prototype-Version Authorization Authentication}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class Kris::Kross::Handler
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
attr_accessor :app
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
@env = env
|
10
|
+
|
11
|
+
if options_request?
|
12
|
+
[200, option_request_headers, [""]]
|
13
|
+
else
|
14
|
+
respond(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def option_request_headers
|
21
|
+
{
|
22
|
+
"Access-Control-Allow-Origin" => Kris::Kross::Configuration.hosts,
|
23
|
+
"Access-Control-Allow-Methods" => "POST, GET, OPTIONS",
|
24
|
+
"Access-Control-Allow-Headers" => Kris::Kross::Configuration.headers,
|
25
|
+
"Access-Control-Max-Age" => "172800",
|
26
|
+
"Access-Control-Allow-Credentials" => 'true'
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def options_request?
|
31
|
+
@env["REQUEST_METHOD"] == "OPTIONS"
|
32
|
+
end
|
33
|
+
|
34
|
+
def respond(env)
|
35
|
+
status, headers, response = app.call(env)
|
36
|
+
[status, headers.merge(cors_headers), response]
|
37
|
+
end
|
38
|
+
|
39
|
+
def cors_headers
|
40
|
+
{
|
41
|
+
"Access-Control-Allow-Origin" => Kris::Kross::Configuration.hosts,
|
42
|
+
"Access-Control-Allow-Credentials" => "true"
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kris::Kross::Configuration, "#configure" do
|
4
|
+
before { Kris::Kross::Configuration.reset }
|
5
|
+
let(:instance) { Kris::Kross::Configuration.instance }
|
6
|
+
|
7
|
+
describe "origins" do
|
8
|
+
it "should allow configuration via method calls" do
|
9
|
+
instance.configure do |c|
|
10
|
+
c.origins %w(http://host-1 http://host-2)
|
11
|
+
end
|
12
|
+
|
13
|
+
instance.origins.should == %w(http://host-1 http://host-2)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should allow configuration via assignment" do
|
17
|
+
instance.configure do |c|
|
18
|
+
c.origins = %w(http://host-3 http://host-4)
|
19
|
+
end
|
20
|
+
|
21
|
+
instance.origins.should == %w(http://host-3 http://host-4)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should accept string origins" do
|
25
|
+
instance.configure do |c|
|
26
|
+
c.origins = "http://blah.blah"
|
27
|
+
end
|
28
|
+
|
29
|
+
instance.origins.should == %w(http://blah.blah)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "headers" do
|
34
|
+
it "should allow configuration via method calls, mixed into defaults" do
|
35
|
+
instance.configure do |c|
|
36
|
+
c.headers %w{X-Blah-Blah X-Blah-Blah-Blah}
|
37
|
+
end
|
38
|
+
|
39
|
+
instance.headers.should == %w{
|
40
|
+
X-Requested-With
|
41
|
+
X-Prototype-Version
|
42
|
+
Authorization
|
43
|
+
Authentication
|
44
|
+
X-Blah-Blah
|
45
|
+
X-Blah-Blah-Blah}.join(' ')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow configuration with assignment, mixed into defaults" do
|
49
|
+
instance.configure do |c|
|
50
|
+
c.headers = %w{X-Blah-Blah X-Blah-Blah-Blah}
|
51
|
+
end
|
52
|
+
|
53
|
+
instance.headers.should == %w{
|
54
|
+
X-Requested-With
|
55
|
+
X-Prototype-Version
|
56
|
+
Authorization
|
57
|
+
Authentication
|
58
|
+
X-Blah-Blah
|
59
|
+
X-Blah-Blah-Blah}.join(' ')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe Kris::Kross::Configuration, ".headers" do
|
65
|
+
before { Kris::Kross::Configuration.reset }
|
66
|
+
let(:instance) { Kris::Kross::Configuration.instance }
|
67
|
+
let(:default_headers) { %w{X-Requested-With X-Prototype-Version Authorization Authentication} }
|
68
|
+
|
69
|
+
context "with only default headers" do
|
70
|
+
it "should return just the defaults" do
|
71
|
+
Kris::Kross::Configuration.headers.should == default_headers.join(' ')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with extra headers" do
|
76
|
+
before do
|
77
|
+
instance.configure do |c|
|
78
|
+
c.headers %w(X-Blah)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return headers as a string" do
|
83
|
+
Kris::Kross::Configuration.headers.should == (default_headers << "X-Blah").join(' ')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe Kris::Kross::Configuration, ".hosts" do
|
89
|
+
before { Kris::Kross::Configuration.reset }
|
90
|
+
let(:instance) { Kris::Kross::Configuration.instance }
|
91
|
+
|
92
|
+
before do
|
93
|
+
instance.configure do |c|
|
94
|
+
c.origins %w(http://host-1 http://host-2)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return origins as a string" do
|
99
|
+
Kris::Kross::Configuration.hosts.should == "http://host-1 http://host-2"
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kris::Kross::Handler do
|
4
|
+
before do
|
5
|
+
Kris::Kross::Handler.reset_instance
|
6
|
+
Kris::Kross::Handler.instance.app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { Kris::Kross::Handler.instance }
|
10
|
+
|
11
|
+
let(:app) { mock() }
|
12
|
+
let(:response) { subject.call(env) }
|
13
|
+
let(:status) { response[0] }
|
14
|
+
let(:headers) { response[1] }
|
15
|
+
let(:body) { response[2] }
|
16
|
+
|
17
|
+
let(:request_method) { 'OPTIONS' }
|
18
|
+
let(:allow_origin) { 'http://my-host https://my-host' }
|
19
|
+
let(:allow_headers) { 'X-Stuff X-Other-Stuff X-What-What' }
|
20
|
+
|
21
|
+
let(:configuration) { mock() }
|
22
|
+
|
23
|
+
before do
|
24
|
+
Kris::Kross::Configuration.stub(:hosts).and_return(allow_origin)
|
25
|
+
Kris::Kross::Configuration.stub(:headers).and_return(allow_headers)
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:env) { {
|
29
|
+
'REQUEST_METHOD' => request_method,
|
30
|
+
'REQUEST_PATH' => '/'
|
31
|
+
} }
|
32
|
+
|
33
|
+
describe "OPTIONS request" do
|
34
|
+
it "should return a 200 status" do
|
35
|
+
status.should == 200
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should include Access-Control headers" do
|
39
|
+
headers['Access-Control-Allow-Origin'].should == allow_origin
|
40
|
+
headers["Access-Control-Allow-Methods"].should == "POST, GET, OPTIONS"
|
41
|
+
headers["Access-Control-Allow-Headers"].should == allow_headers
|
42
|
+
headers["Access-Control-Max-Age"].should == "172800"
|
43
|
+
headers["Access-Control-Allow-Credentials"].should == 'true'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "POST request" do
|
48
|
+
let(:request_method) { 'POST' }
|
49
|
+
let(:application_response_body) { ["some text from the application"] }
|
50
|
+
let(:application_response) {
|
51
|
+
[
|
52
|
+
200,
|
53
|
+
{"header" => 'content'},
|
54
|
+
application_response_body
|
55
|
+
]
|
56
|
+
}
|
57
|
+
|
58
|
+
before do
|
59
|
+
app.should_receive(:call).with(env).and_return(application_response)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should call the Rails dispatcher with the request environment" do
|
63
|
+
subject.call(env)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return the body text from the app" do
|
67
|
+
body.should == application_response_body
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should inject Allow-Origin headers into the response" do
|
71
|
+
headers['Access-Control-Allow-Origin'].should == allow_origin
|
72
|
+
headers["Access-Control-Allow-Credentials"].should == 'true'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Kris::Kross, "#new" do
|
4
|
+
let(:app) { mock() }
|
5
|
+
|
6
|
+
it "should initialize a handler and configure it" do
|
7
|
+
Kris::Kross::Handler.instance.should_receive(:app=).with(app)
|
8
|
+
Kris::Kross.new(app)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe Kris::Kross, "#configure" do
|
13
|
+
let(:proc) { -> { "some proc" } }
|
14
|
+
|
15
|
+
it "passes block on to Configuration" do
|
16
|
+
Kris::Kross::Configuration.instance.should_receive(:configure).with(&proc)
|
17
|
+
Kris::Kross.configure(&proc)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Kris::Kross, "#call" do
|
22
|
+
let(:app) { mock() }
|
23
|
+
let(:env) { mock() }
|
24
|
+
let(:handler) { mock() }
|
25
|
+
|
26
|
+
it "passes arguments on to a handler" do
|
27
|
+
Kris::Kross::Handler.stub(:instance).and_return(handler)
|
28
|
+
handler.should_receive(:app=).with(app)
|
29
|
+
handler.should_receive(:call).with(env)
|
30
|
+
|
31
|
+
Kris::Kross.new(app).call(env)
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
9
|
+
require 'rubygems'
|
10
|
+
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
require 'support/singleton'
|
12
|
+
require 'kris-kross'
|
13
|
+
require 'support/configuration'
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
17
|
+
config.run_all_when_everything_filtered = true
|
18
|
+
config.filter_run :focus
|
19
|
+
|
20
|
+
# Run specs in random order to surface order dependencies. If you find an
|
21
|
+
# order dependency and want to debug it, you can fix the order by providing
|
22
|
+
# the seed, which is printed after each run.
|
23
|
+
# --seed 1234
|
24
|
+
config.order = 'random'
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class <<Singleton
|
4
|
+
def included_with_reset(klass)
|
5
|
+
included_without_reset(klass)
|
6
|
+
class <<klass
|
7
|
+
def reset_instance
|
8
|
+
Singleton.send :__init__, self
|
9
|
+
self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
alias_method :included_without_reset, :included
|
14
|
+
alias_method :included, :included_with_reset
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kris-kross
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Saxby
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: guard-rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rb-fsevent
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Kris Kross will make you jump jump between domains with cross origin
|
63
|
+
requests
|
64
|
+
email:
|
65
|
+
- sax@wanelo.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- Guardfile
|
73
|
+
- LICENSE
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- kris-kross.gemspec
|
77
|
+
- lib/kris-kross.rb
|
78
|
+
- lib/kris-kross/configuration.rb
|
79
|
+
- lib/kris-kross/handler.rb
|
80
|
+
- lib/kris-kross/railtie.rb
|
81
|
+
- lib/kris-kross/version.rb
|
82
|
+
- spec/kris-kross/configuration_spec.rb
|
83
|
+
- spec/kris-kross/handler_spec.rb
|
84
|
+
- spec/kris-kross_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
- spec/support/configuration.rb
|
87
|
+
- spec/support/singleton.rb
|
88
|
+
homepage: https://github.com/wanelo/kris-kross
|
89
|
+
licenses: []
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.24
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Cross origin requests made easy
|
112
|
+
test_files:
|
113
|
+
- spec/kris-kross/configuration_spec.rb
|
114
|
+
- spec/kris-kross/handler_spec.rb
|
115
|
+
- spec/kris-kross_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/support/configuration.rb
|
118
|
+
- spec/support/singleton.rb
|
119
|
+
has_rdoc:
|