rack-cookie-monster 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +5 -8
- data/Rakefile +47 -0
- data/features/support/celerity_startup.rb +1 -1
- data/lib/rack/cookie_monster.rb +9 -8
- data/spec/rack/cookie_monster_config_spec.rb +55 -0
- data/spec/rack/cookie_monster_spec.rb +19 -1
- data/spec/spec_helper.rb +1 -5
- metadata +8 -4
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Justin DeWind
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.rdoc
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
= Rack Cookie Monster
|
2
2
|
|
3
|
-
A rack middleware library that allows for cookies to be passed through form parameters. Specifically, it merges the specified
|
4
|
-
form parameters into the Cookie header of an http request. It gets around the problem of having a flash application which interacts with a web application that uses cookie based sessions.
|
3
|
+
A rack middleware library that allows for cookies to be passed through form parameters. Specifically, it merges the specified form parameters into the Cookie header of an http request. It gets around the problem of having a flash application which interacts with a web application that uses cookie based sessions.
|
5
4
|
|
6
5
|
= Contributing
|
7
6
|
The environment can be configured by using bundler.
|
@@ -52,10 +51,8 @@ The environment can be configured by using bundler.
|
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
Rack::CookieMonster
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
use Rack::CookieMonster
|
54
|
+
use Rack::CookieMonster, {
|
55
|
+
:cookies => [:cookie_1, :cookie_2],
|
56
|
+
:share_with => /firefox/i
|
57
|
+
}
|
61
58
|
run CookieMonsterApplication.new
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
$:<< "vendor/gems/gems/rspec-1.2.9/lib"
|
2
|
+
$:<< "vendor/gems/gems/cucumber-0.4.4/lib"
|
3
|
+
|
4
|
+
require 'spec/rake/spectask'
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
|
7
|
+
task :default => [:spec, :features]
|
8
|
+
|
9
|
+
desc "Executes bundler and grabs necessary dependencies to run tests"
|
10
|
+
task "setup:contrib" do
|
11
|
+
system("gem bundle")
|
12
|
+
end
|
13
|
+
|
14
|
+
Spec::Rake::SpecTask.new do |t|
|
15
|
+
t.spec_files = "spec/**/*_spec.rb"
|
16
|
+
t.spec_opts = ["-f s -c"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup_common_cucumber_settings(task)
|
20
|
+
task.cucumber_opts = "--require features"
|
21
|
+
task.binary = 'vendor/gems/bin/cucumber'
|
22
|
+
end
|
23
|
+
|
24
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
25
|
+
setup_common_cucumber_settings(t)
|
26
|
+
t.cucumber_opts << "--color --format pretty"
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'jeweler'
|
31
|
+
Jeweler::Tasks.new do |s|
|
32
|
+
s.name = "rack-cookie-monster"
|
33
|
+
s.summary = "A rack middleware library that allows cookies to be passed through forms parameters."
|
34
|
+
s.description = "A rack middleware library that allows for cookies to be passed through form parameters. Specifically, it merges the specified form parameters into the Cookie header of an http request. It gets around the problem of having a flash application which interacts with a web application that uses cookie based sessions."
|
35
|
+
s.email = "dewind@atomicobject.com"
|
36
|
+
s.homepage = "http://github.com/dewind/rack-cookie-monster"
|
37
|
+
s.authors = ["Justin DeWind"]
|
38
|
+
s.executables = []
|
39
|
+
s.files = FileList["lib/**/*.rb", "LICENSE", "Rakefile"]
|
40
|
+
s.test_files = FileList["spec/**/*.rb", "features/**/*"]
|
41
|
+
s.add_dependency "rack", ">=1.0.0"
|
42
|
+
end
|
43
|
+
|
44
|
+
Jeweler::GemcutterTasks.new
|
45
|
+
rescue LoadError
|
46
|
+
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
47
|
+
end
|
@@ -45,7 +45,7 @@ if host_listening_on_port? "localhost", $port
|
|
45
45
|
kill_test_server
|
46
46
|
end
|
47
47
|
|
48
|
-
%x(bin/rackup --require lib/rack/cookie_monster --require vendor/gems/environment --daemon --pid #{SERVER_PID} --server webrick features/monster.ru)
|
48
|
+
%x(vendor/gems/bin/rackup --require lib/rack/cookie_monster --require vendor/gems/environment --daemon --pid #{SERVER_PID} --server webrick features/monster.ru)
|
49
49
|
raise "Couldn't start server" unless host_listening_on_port? "localhost", $port, 10
|
50
50
|
|
51
51
|
$server ||= Culerity::run_server
|
data/lib/rack/cookie_monster.rb
CHANGED
@@ -3,7 +3,7 @@ module Rack
|
|
3
3
|
|
4
4
|
class Hungry < StandardError; end
|
5
5
|
|
6
|
-
class<<self
|
6
|
+
class<<self
|
7
7
|
def configure
|
8
8
|
@config ||= CookieMonsterConfig.new
|
9
9
|
yield(@config)
|
@@ -36,8 +36,9 @@ module Rack
|
|
36
36
|
|
37
37
|
end
|
38
38
|
|
39
|
-
def initialize(app)
|
39
|
+
def initialize(app, opts=nil)
|
40
40
|
@app = app
|
41
|
+
@config = opts.nil? ? self.class : CookieMonsterConfig.new(opts)
|
41
42
|
end
|
42
43
|
|
43
44
|
def call(env)
|
@@ -51,9 +52,9 @@ module Rack
|
|
51
52
|
private
|
52
53
|
|
53
54
|
def shares_with(agent)
|
54
|
-
yield if
|
55
|
+
yield if @config.snackers.empty?
|
55
56
|
|
56
|
-
any_matches =
|
57
|
+
any_matches = @config.snackers.any? do |snacker|
|
57
58
|
case snacker
|
58
59
|
when String
|
59
60
|
snacker == agent
|
@@ -69,7 +70,7 @@ module Rack
|
|
69
70
|
cookies = request.cookies
|
70
71
|
new_cookies = {}
|
71
72
|
|
72
|
-
|
73
|
+
@config.cookies.each do |cookie_name|
|
73
74
|
value = request.params[cookie_name.to_s]
|
74
75
|
if value
|
75
76
|
cookies.delete(cookie_name.to_s)
|
@@ -88,9 +89,9 @@ module Rack
|
|
88
89
|
class CookieMonsterConfig
|
89
90
|
attr_reader :cookies, :snackers
|
90
91
|
|
91
|
-
def initialize
|
92
|
-
@cookies = []
|
93
|
-
@snackers = []
|
92
|
+
def initialize(opts={})
|
93
|
+
@cookies = [opts[:cookies]].compact.flatten.map { |x| x.to_sym }
|
94
|
+
@snackers = [opts[:share_with]].compact.flatten
|
94
95
|
end
|
95
96
|
|
96
97
|
def eat(cookie)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rack/cookie_monster'
|
3
|
+
require 'action_controller'
|
4
|
+
|
5
|
+
describe Rack::CookieMonsterConfig do
|
6
|
+
subject { described_class }
|
7
|
+
|
8
|
+
describe "#initialize" do
|
9
|
+
it "does not require any options by default" do
|
10
|
+
instance = subject.new
|
11
|
+
instance.cookies.should be_empty
|
12
|
+
instance.snackers.should be_empty
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can be initialized with cookies and snackers" do
|
16
|
+
instance = subject.new(
|
17
|
+
:cookies => ["oatmeal", "raisen"],
|
18
|
+
:share_with => ["Firefox", /flash/]
|
19
|
+
)
|
20
|
+
|
21
|
+
instance.cookies.should == [:oatmeal, :raisen]
|
22
|
+
instance.snackers.should == ["Firefox", /flash/]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "a cookie and snacker can be provided optionally outside of an array" do
|
26
|
+
instance = subject.new(
|
27
|
+
:cookies => "oatmeal",
|
28
|
+
:share_with => "MSIE"
|
29
|
+
)
|
30
|
+
|
31
|
+
instance.cookies.should == [:oatmeal]
|
32
|
+
instance.snackers.should == ["MSIE"]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#eat" do
|
37
|
+
it "collects param names" do
|
38
|
+
instance = subject.new
|
39
|
+
[:mojo, :phoebe, :moudgie].each do |x|
|
40
|
+
instance.eat x
|
41
|
+
end
|
42
|
+
instance.cookies.should == [:mojo, :phoebe, :moudgie]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#share_with" do
|
47
|
+
it "collects snackers" do
|
48
|
+
instance = subject.new
|
49
|
+
["Flash", "MSIE"].each do |x|
|
50
|
+
instance.share_with x
|
51
|
+
end
|
52
|
+
instance.snackers.should == ["Flash", "MSIE"]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -6,7 +6,6 @@ describe Rack::CookieMonster do
|
|
6
6
|
subject { Class.new(described_class) }
|
7
7
|
|
8
8
|
describe ".configure" do
|
9
|
-
|
10
9
|
it "specifies what cookies are to be eaten" do
|
11
10
|
subject.configure do |c|
|
12
11
|
c.eat :_session_id
|
@@ -127,5 +126,24 @@ describe Rack::CookieMonster do
|
|
127
126
|
@target.call(@environment.dup)
|
128
127
|
end
|
129
128
|
end
|
129
|
+
|
130
|
+
describe "configured through constructor" do
|
131
|
+
before do
|
132
|
+
@target = subject.new(@app, {
|
133
|
+
:cookies => [:oatmeal_cookie],
|
134
|
+
:share_with => ["Opera"]
|
135
|
+
})
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should overtake declarative configuration" do
|
139
|
+
@app.expects(:call).with(has_entry("HTTP_COOKIE", "oatmeal_cookie=delicious")).once
|
140
|
+
@app.expects(:call).with(has_entry("HTTP_COOKIE", "")).once
|
141
|
+
|
142
|
+
@environment["HTTP_USER_AGENT"] = "Opera"
|
143
|
+
@target.call(@environment.dup)
|
144
|
+
@environment["HTTP_USER_AGENT"] = "Boom"
|
145
|
+
@target.call(@environment.dup)
|
146
|
+
end
|
147
|
+
end
|
130
148
|
end
|
131
149
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
here = File.expand_path(File.dirname(__FILE__))
|
2
2
|
require File.join(here, "..", "vendor/gems/environment")
|
3
3
|
require File.join(here, "..", "init")
|
4
|
-
|
5
|
-
require 'spec/autorun'
|
6
|
-
require 'mocha'
|
7
|
-
require 'active_support'
|
8
|
-
require 'rack'
|
4
|
+
Bundler.require_env :test
|
9
5
|
|
10
6
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
11
7
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-cookie-monster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin DeWind
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-23 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,15 +22,18 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.0.0
|
24
24
|
version:
|
25
|
-
description: A rack middleware library that allows cookies to be passed through
|
25
|
+
description: A rack middleware library that allows for cookies to be passed through form parameters. Specifically, it merges the specified form parameters into the Cookie header of an http request. It gets around the problem of having a flash application which interacts with a web application that uses cookie based sessions.
|
26
26
|
email: dewind@atomicobject.com
|
27
27
|
executables: []
|
28
28
|
|
29
29
|
extensions: []
|
30
30
|
|
31
31
|
extra_rdoc_files:
|
32
|
+
- LICENSE
|
32
33
|
- README.rdoc
|
33
34
|
files:
|
35
|
+
- LICENSE
|
36
|
+
- Rakefile
|
34
37
|
- lib/rack/cookie_monster.rb
|
35
38
|
- README.rdoc
|
36
39
|
has_rdoc: true
|
@@ -60,8 +63,9 @@ rubyforge_project:
|
|
60
63
|
rubygems_version: 1.3.5
|
61
64
|
signing_key:
|
62
65
|
specification_version: 3
|
63
|
-
summary: A rack middleware library that allows cookies to be passed through forms
|
66
|
+
summary: A rack middleware library that allows cookies to be passed through forms parameters.
|
64
67
|
test_files:
|
68
|
+
- spec/rack/cookie_monster_config_spec.rb
|
65
69
|
- spec/rack/cookie_monster_spec.rb
|
66
70
|
- spec/spec_helper.rb
|
67
71
|
- spec/support/stub_helpers.rb
|