redis-session-store 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/redis-session-store.rb +3 -5
- data/spec/redis_session_store_spec.rb +24 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 097d67a7b7dddb2f3b6d560c0dc3ac6c72c1adf2
|
4
|
+
data.tar.gz: 4cf3ce2dc51d8788b6400efa2c48d12c1f932b3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af6359ab62958e1542c55d93d7580343dfca3a00f8eef8c64c106b7213faea3f95341bdf0f8bf67a66682e86a22d897c901fedf53a8b049674a3aa6cef4a08de
|
7
|
+
data.tar.gz: bcd85e2e6d0df1a78fc28cdaab2ff67d0adfbaa3db288d7d0a3d8efe1c948ea852c7943e8623728cee6e39949f15b252da35e8da6e12bd707e749d13ff326f1c
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
redis-session-store history
|
2
2
|
===========================
|
3
3
|
|
4
|
+
## v0.6.5 (2014-04-04)
|
5
|
+
|
6
|
+
* Fix issue #36, use setnx to get a new session id instead of get. This
|
7
|
+
prevents a very rare id collision.
|
8
|
+
|
4
9
|
## v0.6.4 (2014-04-04)
|
5
10
|
|
6
11
|
* Reverting `setnx` usage in v0.6.3 so we can change our sessions.
|
data/lib/redis-session-store.rb
CHANGED
@@ -4,7 +4,7 @@ require 'redis'
|
|
4
4
|
# Redis session storage for Rails, and for Rails only. Derived from
|
5
5
|
# the MemCacheStore code, simply dropping in Redis instead.
|
6
6
|
class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
7
|
-
VERSION = '0.6.
|
7
|
+
VERSION = '0.6.5'
|
8
8
|
|
9
9
|
# ==== Options
|
10
10
|
# * +:key+ - Same as with the other cookie stores, key name
|
@@ -76,8 +76,8 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def sid_collision?(sid)
|
79
|
-
|
80
|
-
on_sid_collision.call(sid) if value && on_sid_collision
|
79
|
+
!redis.setnx(prefixed(sid), nil).tap do |value|
|
80
|
+
on_sid_collision.call(sid) if !value && on_sid_collision
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -177,8 +177,6 @@ class RedisSessionStore < ActionDispatch::Session::AbstractStore
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
180
|
-
private
|
181
|
-
|
182
180
|
def self.needs_migration?(value)
|
183
181
|
value.start_with?(MARSHAL_SIGNATURE)
|
184
182
|
end
|
@@ -249,7 +249,7 @@ describe RedisSessionStore do
|
|
249
249
|
|
250
250
|
context 'when destroyed via #destroy_session' do
|
251
251
|
it 'deletes the prefixed key from redis' do
|
252
|
-
redis = double('redis',
|
252
|
+
redis = double('redis', setnx: true)
|
253
253
|
store.stub(redis: redis)
|
254
254
|
sid = store.send(:generate_sid)
|
255
255
|
expect(redis).to receive(:del).with("#{options[:key_prefix]}#{sid}")
|
@@ -264,18 +264,23 @@ describe RedisSessionStore do
|
|
264
264
|
|
265
265
|
context 'when the generated sid is unique' do
|
266
266
|
before do
|
267
|
-
redis = double('redis',
|
267
|
+
redis = double('redis', setnx: true)
|
268
268
|
store.stub(redis: redis)
|
269
269
|
end
|
270
270
|
|
271
271
|
it 'returns the sid' do
|
272
272
|
expect(store.send(:generate_sid)).to_not be_nil
|
273
273
|
end
|
274
|
+
|
275
|
+
it 'does not pass the unique sid to the collision handler' do
|
276
|
+
store.send(:sid_collision?, 'whatever')
|
277
|
+
expect(@sid).to eql(nil)
|
278
|
+
end
|
274
279
|
end
|
275
280
|
|
276
281
|
context 'when there is a generated sid collision' do
|
277
282
|
before do
|
278
|
-
redis = double('redis',
|
283
|
+
redis = double('redis', setnx: false)
|
279
284
|
store.stub(redis: redis)
|
280
285
|
end
|
281
286
|
|
@@ -284,6 +289,22 @@ describe RedisSessionStore do
|
|
284
289
|
expect(@sid).to eql('whatever')
|
285
290
|
end
|
286
291
|
end
|
292
|
+
|
293
|
+
it 'does not allow two processes to get the same sid' do
|
294
|
+
redis = Redis.new
|
295
|
+
store1 = RedisSessionStore.new(nil, options)
|
296
|
+
store1.stub(redis: redis)
|
297
|
+
store2 = RedisSessionStore.new(nil, options)
|
298
|
+
store2.stub(redis: redis)
|
299
|
+
|
300
|
+
# While this is stubbing out a method defined in spec/support.rb,
|
301
|
+
# Rails does use SecureRandom for the random string
|
302
|
+
store1.stub(:rand).and_return(1000)
|
303
|
+
store2.stub(:rand).and_return(1000, 1001)
|
304
|
+
|
305
|
+
expect(store1.send(:generate_sid)).to eq('3e8')
|
306
|
+
expect(store2.send(:generate_sid)).to eq('3e9')
|
307
|
+
end
|
287
308
|
end
|
288
309
|
|
289
310
|
describe 'session encoding' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-session-store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.2.
|
145
|
+
rubygems_version: 2.2.2
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: A drop-in replacement for e.g. MemCacheStore to store Rails sessions (and
|