rack_global_session 0.2 → 0.3
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/lib/rack_global_session.rb +17 -4
- data/lib/rack_global_session/version.rb +1 -1
- data/spec/rack_global_session_spec.rb +10 -11
- metadata +4 -4
data/lib/rack_global_session.rb
CHANGED
@@ -135,17 +135,30 @@ module Rack
|
|
135
135
|
begin
|
136
136
|
read_cookie(env)
|
137
137
|
renew_ticket(env)
|
138
|
-
tuple = @app.call(env)
|
139
138
|
rescue Exception => e
|
140
139
|
wipe_cookie(env)
|
141
140
|
$stderr.puts "Error while reading cookies: #{e.class} #{e} #{e.backtrace}"
|
142
141
|
if env['rack.logger']
|
143
142
|
env['rack.logger'].error("Error while reading cookies: #{e.class} #{e} #{e.backtrace}")
|
144
143
|
end
|
145
|
-
return [
|
144
|
+
return [403, {'Content-Type' => 'text/plain'}, "Invalid cookie"]
|
146
145
|
else
|
147
|
-
|
148
|
-
|
146
|
+
begin
|
147
|
+
tuple = @app.call(env)
|
148
|
+
rescue HasGlobalSession::NoAuthority => e
|
149
|
+
wipe_cookie(env)
|
150
|
+
$stderr.puts "Error during request: #{e.class} #{e} #{e.backtrace}"
|
151
|
+
if env['rack.logger']
|
152
|
+
env['rack.logger'].error("Error during request: #{e.class} #{e} #{e.backtrace}")
|
153
|
+
end
|
154
|
+
return [500, {'Content-Type' => 'text/plain'}, "Error"]
|
155
|
+
rescue Exception => e
|
156
|
+
wipe_cookie(env)
|
157
|
+
raise e
|
158
|
+
else
|
159
|
+
update_cookie(env)
|
160
|
+
return tuple
|
161
|
+
end
|
149
162
|
end
|
150
163
|
end
|
151
164
|
end
|
@@ -71,7 +71,7 @@ module Rack
|
|
71
71
|
"aCookie" => "foo"
|
72
72
|
}}
|
73
73
|
key, hash, value = Rack::GlobalSession.new(lambda {}, @configuration).call(environment)
|
74
|
-
key.should ==
|
74
|
+
key.should == 403
|
75
75
|
hash.should == {'Content-Type' => 'text/plain'}
|
76
76
|
value.should == "Invalid cookie"
|
77
77
|
$stderr.string.should =~ /HasGlobalSession::MalformedCookie/
|
@@ -91,7 +91,7 @@ module Rack
|
|
91
91
|
base64 = HasGlobalSession::Encoding::Base64Cookie.dump(compressed)
|
92
92
|
environment = {"rack.cookies" => {"aCookie" => base64}}
|
93
93
|
key, hash, value = Rack::GlobalSession.new(lambda {}, @configuration).call(environment)
|
94
|
-
key.should ==
|
94
|
+
key.should == 403
|
95
95
|
hash.should == {'Content-Type' => 'text/plain'}
|
96
96
|
value.should == "Invalid cookie"
|
97
97
|
$stderr.string.should =~ /OpenSSL::PKey::RSAError/
|
@@ -146,18 +146,18 @@ module Rack
|
|
146
146
|
it 'should not renew expired cookies' do
|
147
147
|
key, hash, value = Rack::GlobalSession.new(lambda {|e| e['global_session'].renew!},
|
148
148
|
@configuration).call(@environment)
|
149
|
-
key.should ==
|
149
|
+
key.should == 500
|
150
150
|
hash.should == {'Content-Type' => 'text/plain'}
|
151
|
-
value.should == "
|
151
|
+
value.should == "Error"
|
152
152
|
$stderr.string.should =~ /HasGlobalSession::NoAuthority/
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'should not attempt to update the cookie when it is not an authority' do
|
156
156
|
key, hash, value = Rack::GlobalSession.new(lambda {|e| e['global_session']['first'] = 4},
|
157
157
|
@configuration).call(@environment)
|
158
|
-
key.should ==
|
158
|
+
key.should == 500
|
159
159
|
hash.should == {'Content-Type' => 'text/plain'}
|
160
|
-
value.should == "
|
160
|
+
value.should == "Error"
|
161
161
|
$stderr.string.should =~ /HasGlobalSession::NoAuthority/
|
162
162
|
end
|
163
163
|
end
|
@@ -179,10 +179,9 @@ module Rack
|
|
179
179
|
|
180
180
|
it 'should unconditionally wipe the cookie if an error occurs' do
|
181
181
|
@environment['rack.cookies']['aCookie'].should_not be_nil
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
value.should == "Invalid cookie"
|
182
|
+
lambda {
|
183
|
+
Rack::GlobalSession.new(lambda {raise "foo"}, @configuration).call(@environment)
|
184
|
+
}.should raise_exception(/foo/)
|
186
185
|
@environment['rack.cookies']['aCookie'][:value].should be_nil
|
187
186
|
end
|
188
187
|
|
@@ -190,7 +189,7 @@ module Rack
|
|
190
189
|
@config_hash["common"]["trust"] = "second"
|
191
190
|
dump_config(@config_hash)
|
192
191
|
key, hash, value = Rack::GlobalSession.new(lambda {}, @configuration).call(@environment)
|
193
|
-
key.should ==
|
192
|
+
key.should == 403
|
194
193
|
hash.should == {'Content-Type' => 'text/plain'}
|
195
194
|
value.should == "Invalid cookie"
|
196
195
|
$stderr.string.should =~ /SecurityError/
|
metadata
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_global_session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: "0.
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Graham Hughes
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-12-01 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|