redis-session-store 0.6.4 → 0.6.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b6b105a9579a8c097a1234c80dc058309866fe6
4
- data.tar.gz: 2c405132ca0f846a51189e8a63d0a02ab3d974b5
3
+ metadata.gz: 097d67a7b7dddb2f3b6d560c0dc3ac6c72c1adf2
4
+ data.tar.gz: 4cf3ce2dc51d8788b6400efa2c48d12c1f932b3a
5
5
  SHA512:
6
- metadata.gz: af87b6104ce6ae3e347a22cc6da952c6aae4fd6ca758e563ebd03e2c966e6546270e152770b25820897e91a5f53d6ceae9c31049efb0105752af3d46798ed644
7
- data.tar.gz: 5d4075ed6b6d493659b39d7feddc68b1cb9d8066659cba7147f9e47de3c7b4d749df56a6412d7c0f43936591288b9edf0b7d500259d1b5242380afec3e1919a1
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.
@@ -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.4'
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
- !!redis.get(prefixed(sid)).tap do |value| # rubocop: disable DoubleNegation
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', get: nil)
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', get: nil)
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', get: 'herp a derp')
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
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-04 00:00:00.000000000 Z
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.1
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