rack-session-file 0.3.0 → 0.4.0

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/README.md CHANGED
@@ -2,26 +2,36 @@
2
2
 
3
3
  Rack session store on plain file system.
4
4
 
5
- ## Installation
5
+ ## Usage in Rack Applications
6
6
 
7
- Add this line to your application's Gemfile:
7
+ On Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'rack-session-file', :git =>
11
- 'git://github.com/dayflower/rack-session-file.git'
10
+ gem 'rack-session-file'
12
11
  ```
13
12
 
14
- And then execute:
15
-
16
- $ bundle install
17
-
18
- ## Usage
13
+ And use `Rack::Session::File` as Rack Middleware:
19
14
 
20
15
  ```ruby
21
16
  use Rack::Session::File, :storage => ENV['TEMP'],
22
17
  :expire_after => 1800
23
18
  ```
24
19
 
20
+ ## Usage in Rails 3 Applications
21
+
22
+ On Gemfile:
23
+
24
+ ```ruby
25
+ gem 'rack-session-file', :require => 'rails-session-file'
26
+ ```
27
+
28
+ And modify your config/initializers/session_store.rb to something like:
29
+
30
+ ```ruby
31
+ FooBar::Application.config.session_store :file_store,
32
+ :key => '_foobar_session', :driver => 'YAML'
33
+ ```
34
+
25
35
  ### Options
26
36
 
27
37
  #### File storage directory (`:storage`)
@@ -3,7 +3,7 @@
3
3
  module Rack
4
4
  module Session
5
5
  module File
6
- VERSION = '0.3.0'
6
+ VERSION = '0.4.0'
7
7
 
8
8
  autoload :Marshal, 'rack/session/file/marshal'
9
9
  autoload :PStore, 'rack/session/file/pstore'
@@ -25,7 +25,9 @@ module Rack
25
25
  end
26
26
  rescue Errno::ENOENT
27
27
  return nil
28
- end
28
+ rescue TypeError
29
+ return nil
30
+ end
29
31
  end
30
32
 
31
33
  def delete_session(sid)
@@ -27,10 +27,14 @@ module Rack
27
27
  ensure_storage_accessible()
28
28
 
29
29
  data = {}
30
- store_for_sid(sid).transaction(true) do |db|
31
- db.roots.each do |key|
32
- data[key] = db[key]
30
+ begin
31
+ store_for_sid(sid).transaction(true) do |db|
32
+ db.roots.each do |key|
33
+ data[key] = db[key]
34
+ end
33
35
  end
36
+ rescue TypeError
37
+ return nil
34
38
  end
35
39
  return data
36
40
  end
@@ -37,10 +37,14 @@ module Rack
37
37
  ensure_storage_accessible()
38
38
 
39
39
  data = {}
40
- store_for_sid(sid).transaction(true) do |db|
41
- db.roots.each do |key|
42
- data[key] = db[key]
40
+ begin
41
+ store_for_sid(sid).transaction(true) do |db|
42
+ db.roots.each do |key|
43
+ data[key] = db[key]
44
+ end
43
45
  end
46
+ rescue Psych::SyntaxError, Syck::Error, Syck::TypeError
47
+ return nil
44
48
  end
45
49
  return data
46
50
  end
@@ -0,0 +1,19 @@
1
+ require 'action_dispatch/middleware/session/abstract_store'
2
+ require File.expand_path(File.dirname(__FILE__) + '/rack/session/file')
3
+ require File.expand_path(File.dirname(__FILE__) + '/rack/session/file/abstract')
4
+
5
+ class Rack::Session::File::Abstract
6
+ include ActionDispatch::Session::Compatibility
7
+ include ActionDispatch::Session::StaleSessionCheck
8
+ end
9
+
10
+ module ActionDispatch
11
+ module Session
12
+ class FileStore
13
+ def self.new(app, options={})
14
+ options[:expire_after] ||= options[:expires]
15
+ return Rack::Session::File.new(app, options)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
  "README.md",
15
15
  "Rakefile",
16
16
  "lib/rack-session-file.rb",
17
+ "lib/rails-session-file.rb",
17
18
  "lib/rack/session/file.rb",
18
19
  "lib/rack/session/file/abstract.rb",
19
20
  "lib/rack/session/file/marshal.rb",
@@ -31,7 +32,7 @@ Gem::Specification.new do |gem|
31
32
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
32
33
  gem.name = "rack-session-file"
33
34
  gem.require_paths = ["lib"]
34
- gem.version = '0.3.0'
35
+ gem.version = '0.4.0'
35
36
 
36
37
  if gem.respond_to? :specification_version then
37
38
  gem.specification_version = 3
data/spec/common.rb CHANGED
@@ -74,6 +74,19 @@ shared_examples_for Rack::Session::File do
74
74
  cookie.should_not match(/#{bad_cookie}/)
75
75
  end
76
76
 
77
+ it 'survives broken session data' do
78
+ open(::File.join(@storage, 'broken'), 'w') do |f|
79
+ f.write "\x1\x1o" # broken data for Marshal, YAML
80
+ end
81
+ cookie = 'rack.session=broken'
82
+ res = Rack::MockRequest.new(pool) \
83
+ .get('/', 'HTTP_COOKIE' => cookie)
84
+
85
+ res.body.should == '{"counter"=>1}'
86
+ cookie = res['Set-Cookie'][@session_match]
87
+ cookie.should_not match(/broken/)
88
+ end
89
+
77
90
  it 'should maintain freshness' do
78
91
  pool2 = described_class.new(@increment_mockapp, :storage => @storage, :expire_after => 2)
79
92
  expired_time = Time.now + 5
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-session-file
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-11 00:00:00.000000000 Z
12
+ date: 2012-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -56,6 +56,7 @@ files:
56
56
  - README.md
57
57
  - Rakefile
58
58
  - lib/rack-session-file.rb
59
+ - lib/rails-session-file.rb
59
60
  - lib/rack/session/file.rb
60
61
  - lib/rack/session/file/abstract.rb
61
62
  - lib/rack/session/file/marshal.rb
@@ -81,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
82
  version: '0'
82
83
  segments:
83
84
  - 0
84
- hash: 3561167824695945220
85
+ hash: -4049294331236196458
85
86
  required_rubygems_version: !ruby/object:Gem::Requirement
86
87
  none: false
87
88
  requirements:
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  version: '0'
91
92
  segments:
92
93
  - 0
93
- hash: 3561167824695945220
94
+ hash: -4049294331236196458
94
95
  requirements: []
95
96
  rubyforge_project:
96
97
  rubygems_version: 1.8.23