rack_session_access 0.1.1 → 0.2.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.
- checksums.yaml +7 -0
- data/.gitignore +2 -2
- data/.travis.yml +15 -0
- data/Gemfile.rails4 +2 -7
- data/Gemfile.rails5 +6 -0
- data/LICENSE +22 -0
- data/README.md +135 -61
- data/apps/test_rails_app.rb +8 -9
- data/lib/rack_session_access/middleware.rb +11 -11
- data/lib/rack_session_access/version.rb +1 -1
- data/rack_session_access.gemspec +8 -1
- data/spec/middleware_spec.rb +62 -64
- data/spec/rack_session_access_spec.rb +16 -12
- data/spec/spec_helper.rb +8 -0
- metadata +98 -20
- data/Gemfile +0 -11
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5cba8d7f8d457d26bb24b88801ce27db30c84898
|
4
|
+
data.tar.gz: 1c04d23242d8cc7bc2619457ae40a3778b154e77
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83a90b878bb5e2e4d8509239e116d3f74f269f51237c0ac1d2df61975fac6151ac2efcc1c76ecbc1479702ad4498cbe25df040ecdbd7b46c6f2f1c20d5acb796
|
7
|
+
data.tar.gz: de84cdeccba91cd96952c9188136feff6c7790a24c1fff31bdcf44d4219560ac5f132a0696b58731a4baed8e2387278589f2e1ef418b6f2e85367e5779e95133
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
sudo: required
|
2
|
+
addons:
|
3
|
+
chrome: stable
|
4
|
+
language: ruby
|
5
|
+
rvm:
|
6
|
+
- 2.4.1
|
7
|
+
gemfile:
|
8
|
+
- Gemfile.rails4
|
9
|
+
- Gemfile.rails5
|
10
|
+
cache: bundler
|
11
|
+
script:
|
12
|
+
- "export DISPLAY=:99.0"
|
13
|
+
- "sh -e /etc/init.d/xvfb start"
|
14
|
+
- sleep 3 # give xvfb some time to start
|
15
|
+
- bundle exec rspec
|
data/Gemfile.rails4
CHANGED
data/Gemfile.rails5
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Railsware (www.railsware.com)
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,38 +1,44 @@
|
|
1
|
-
# rack_session_access
|
1
|
+
# Rack Session Access [](https://travis-ci.org/railsware/rack_session_access)
|
2
2
|
|
3
3
|
RackSessionAccess provides rack middleware for 'rack.session' environment management.
|
4
4
|
|
5
5
|
## Problem
|
6
6
|
|
7
|
-
Acceptance testing assumes that you can't directly access
|
8
|
-
For example if you use capybara with selenium webdriver you can't change some session
|
9
|
-
because your
|
7
|
+
Acceptance testing assumes that you can't directly access an applications session.
|
8
|
+
For example, if you use capybara with selenium webdriver you can't change some session values
|
9
|
+
because your tests use the same browser that accesses the application(via the backend server).
|
10
10
|
|
11
11
|
## Solution
|
12
12
|
|
13
|
-
But if you still want to change session values?
|
14
|
-
|
13
|
+
But what if you still want to change session values?
|
14
|
+
One possible solution is to inject into the application some code that will manage the session independently.
|
15
15
|
If you use rack based framework this gem does it!
|
16
16
|
|
17
17
|
## Installation
|
18
18
|
|
19
|
-
|
19
|
+
```ruby
|
20
|
+
gem install rack_session_access
|
21
|
+
```
|
20
22
|
|
21
|
-
## Using with
|
23
|
+
## Using with Rails
|
22
24
|
|
23
25
|
Add to `Gemfile`:
|
24
26
|
|
25
|
-
|
27
|
+
```ruby
|
28
|
+
gem 'rack_session_access'
|
29
|
+
```
|
26
30
|
|
27
31
|
Add RackSessionAccess middleware to rails middleware stack.
|
28
32
|
Add the following in`config/environments/test.rb`:
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
```ruby
|
35
|
+
[MyRailsApp]::Application.configure do |config|
|
36
|
+
...
|
37
|
+
# Access to rack session
|
38
|
+
config.middleware.use RackSessionAccess::Middleware
|
39
|
+
...
|
40
|
+
end
|
41
|
+
```
|
36
42
|
|
37
43
|
*Note* Ensure you include rack_session_access middleware only for *test* environment
|
38
44
|
otherwise you will have security issue.
|
@@ -42,86 +48,154 @@ otherwise you will have security issue.
|
|
42
48
|
|
43
49
|
Add to your sinatra application:
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
```ruby
|
52
|
+
class MySinatraApplication < Sinatra::Base
|
53
|
+
enable :sessions
|
54
|
+
use RackSessionAccess if environment == :test
|
55
|
+
...
|
56
|
+
end
|
57
|
+
```
|
50
58
|
|
51
59
|
If you use rspec you may prefer to inject middleware only for rspec tests:
|
52
60
|
Put into `spec/spec_helper`:
|
53
61
|
|
54
|
-
|
55
|
-
|
56
|
-
|
62
|
+
```ruby
|
63
|
+
MySinatraApplication.configure do |app|
|
64
|
+
app.use RackSessionAccess::Middleware
|
65
|
+
end
|
66
|
+
```
|
57
67
|
|
58
68
|
## Using with Rack builder
|
59
69
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
```ruby
|
71
|
+
Rack::Builder.new do
|
72
|
+
...
|
73
|
+
use Rack::Session::Cookie
|
74
|
+
use RackSessionAccess::Middleware
|
75
|
+
use MyRackApplication
|
76
|
+
end.to_app
|
77
|
+
```
|
66
78
|
|
67
79
|
## Testing with Capybara
|
68
80
|
|
69
81
|
Add to `spec/spec_helper.rb`
|
70
82
|
|
71
|
-
|
83
|
+
```ruby
|
84
|
+
require "rack_session_access/capybara"
|
85
|
+
```
|
72
86
|
|
73
87
|
Use:
|
74
88
|
|
75
89
|
* `page.set_rack_session` to set your desired session data
|
76
90
|
* `page.get_rack_session` to obtain your application session data
|
77
|
-
* `page.get_rack_session_key` to obtain certain key
|
91
|
+
* `page.get_rack_session_key` to obtain certain key of your application session data
|
78
92
|
|
79
93
|
Example:
|
80
94
|
|
81
|
-
|
95
|
+
```ruby
|
96
|
+
require 'spec_helper'
|
97
|
+
|
98
|
+
feature "My feature" do
|
99
|
+
given!(:user) { create(:user, email: 'jack@daniels.com') }
|
100
|
+
|
101
|
+
scenario "logged in user access profile page" do
|
102
|
+
page.set_rack_session(user_id: user.id)
|
103
|
+
visit "/profile"
|
104
|
+
expect(page).to have_content("Hi, jack@daniels.com")
|
105
|
+
end
|
106
|
+
|
107
|
+
scenario "visit landing page" do
|
108
|
+
visit "/landing?ref=123"
|
109
|
+
expect(page.get_rack_session_key('ref')).to eq("123")
|
110
|
+
end
|
111
|
+
end
|
112
|
+
```
|
113
|
+
|
114
|
+
### Authlogic integration
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
module FeatureHelpers
|
118
|
+
def logged_as(user)
|
119
|
+
page.set_rack_session('user_credentials' => user.persistence_token)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
### Devise integration
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
module FeatureHelpers
|
128
|
+
def logged_as(user)
|
129
|
+
# Devise v3.x.x
|
130
|
+
page.set_rack_session('warden.user.user.key' => User.serialize_into_session(user).unshift('User'))
|
131
|
+
|
132
|
+
# Devise v4.x.x
|
133
|
+
page.set_rack_session('warden.user.user.key' => User.serialize_into_session(user)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
```
|
137
|
+
|
138
|
+
## Authentication helper
|
139
|
+
|
140
|
+
Put corresponding implementation of `logged_as` in `spec/support/feature_helpers.rb` and include module into rspec config:
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
RSpec.configure do |config|
|
144
|
+
...
|
145
|
+
config.include FeatureHelpers, type: :feature
|
146
|
+
...
|
147
|
+
end
|
148
|
+
```
|
149
|
+
Start your scenarios with already logged in user:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
feature 'User dashboard', type: :feature do
|
153
|
+
given(:user) { create(:user) }
|
154
|
+
background do
|
155
|
+
logged_as user
|
156
|
+
end
|
157
|
+
scenario 'User reviews a dashboard' do
|
158
|
+
...
|
159
|
+
end
|
160
|
+
end
|
161
|
+
```
|
82
162
|
|
83
|
-
|
84
|
-
background do
|
85
|
-
@user = Factory(:user, :email => 'jack@daniels.com')
|
86
|
-
end
|
87
|
-
|
88
|
-
scenario "logged in user access profile page" do
|
89
|
-
page.set_rack_session(:user_id => user.id)
|
90
|
-
page.visit "/profile"
|
91
|
-
page.should have_content("Hi, jack@daniels.com")
|
92
|
-
end
|
163
|
+
## Notes
|
93
164
|
|
94
|
-
|
95
|
-
page.visit "/landing?ref=123"
|
96
|
-
page.get_rack_session_key('ref').should == "123"
|
97
|
-
end
|
98
|
-
end
|
165
|
+
Thus we use marshalized data it's possible to set any ruby object into application session hash.
|
99
166
|
|
100
|
-
|
167
|
+
Enjoy!
|
101
168
|
|
102
|
-
|
169
|
+
## Running rack_session_access tests
|
103
170
|
|
104
|
-
## Devise integration
|
105
171
|
|
106
|
-
|
172
|
+
### Against Rails4, Sinatra, rack applications
|
107
173
|
|
108
|
-
|
174
|
+
```sh
|
175
|
+
bundle install
|
176
|
+
bundle exec rspec -fd spec/
|
177
|
+
```
|
109
178
|
|
110
|
-
|
179
|
+
### Against Rails3, Sinatra, rack applications
|
111
180
|
|
112
|
-
|
181
|
+
```sh
|
182
|
+
BUNDLE_GEMFILE=Gemfile.rails4 bundle install
|
183
|
+
BUNDLE_GEMFILE=Gemfile.rails4 bundle exec rspec -fd spec/
|
184
|
+
```
|
113
185
|
|
114
|
-
|
186
|
+
```sh
|
187
|
+
BUNDLE_GEMFILE=Gemfile.rails5 bundle install
|
188
|
+
BUNDLE_GEMFILE=Gemfile.rails5 bundle exec rspec -fd spec/
|
189
|
+
```
|
115
190
|
|
116
|
-
|
191
|
+
## Author
|
117
192
|
|
118
|
-
|
119
|
-
BUNDLE_GEMFILE=Gemfile bundle exec rspec -fs -c spec/
|
193
|
+
[Andriy Yanko](http://ayanko.github.com/)
|
120
194
|
|
121
|
-
|
195
|
+
## License
|
122
196
|
|
123
|
-
|
124
|
-
|
197
|
+
* Copyright (c) 2015 Railsware [www.railsware.com](http://www.railsware.com)
|
198
|
+
* [MIT](www.opensource.org/licenses/MIT)
|
125
199
|
|
126
200
|
|
127
201
|
## References
|
data/apps/test_rails_app.rb
CHANGED
@@ -3,20 +3,19 @@ require 'action_controller/railtie'
|
|
3
3
|
module TestRailsApp
|
4
4
|
class Application < Rails::Application
|
5
5
|
config.secret_token = '572c86f5ede338bd8aba8dae0fd3a326aabababc98d1e6ce34b9f5'
|
6
|
-
|
7
|
-
|
8
|
-
end
|
6
|
+
|
7
|
+
config.secret_key_base = '6dfb795086781f017c63cadcd2653fac40967ac60f621e6299a0d6d811417156d81efcdf1d234c'
|
9
8
|
|
10
9
|
routes.draw do
|
11
|
-
get
|
12
|
-
post '/login'
|
13
|
-
get
|
10
|
+
get '/login' => 'test_rails_app/sessions#new'
|
11
|
+
post '/login' => 'test_rails_app/sessions#create'
|
12
|
+
get '/profile' => 'test_rails_app/profiles#show'
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
16
|
class SessionsController < ActionController::Base
|
18
17
|
def new
|
19
|
-
render :
|
18
|
+
render plain: 'Please log in'
|
20
19
|
end
|
21
20
|
|
22
21
|
def create
|
@@ -28,9 +27,9 @@ module TestRailsApp
|
|
28
27
|
class ProfilesController < ActionController::Base
|
29
28
|
def show
|
30
29
|
if user_email = session[:user_email]
|
31
|
-
render :
|
30
|
+
render plain: "Welcome, #{user_email}!"
|
32
31
|
else
|
33
|
-
redirect_to '/login'
|
32
|
+
redirect_to '/login'
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
@@ -53,13 +53,13 @@ module RackSessionAccess
|
|
53
53
|
else
|
54
54
|
render do |xml|
|
55
55
|
xml.h2 "Rack session data"
|
56
|
-
xml.ul do |
|
56
|
+
xml.ul do |ul|
|
57
57
|
session_hash.each do |k,v|
|
58
|
-
|
58
|
+
ul.li("#{k.inspect} : #{v.inspect}")
|
59
59
|
end
|
60
60
|
end
|
61
|
-
xml.p do |
|
62
|
-
|
61
|
+
xml.p do |p|
|
62
|
+
p.a("Edit", :href => action_path(:edit))
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -74,11 +74,11 @@ module RackSessionAccess
|
|
74
74
|
:action => action_path(:update),
|
75
75
|
:method => 'post',
|
76
76
|
:enctype => 'application/x-www-form-urlencoded'
|
77
|
-
}) do |
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
}) do |form|
|
78
|
+
form.input(:type => 'hidden', :name =>'_method', :value => 'put')
|
79
|
+
form.textarea(:cols => 40, :rows => 10, :name => 'data') {}
|
80
|
+
form.p do |p|
|
81
|
+
p.input(:type => 'submit', :value => "Update")
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
@@ -135,8 +135,8 @@ module RackSessionAccess
|
|
135
135
|
builder = Builder::XmlMarkup.new(:indent => 2)
|
136
136
|
|
137
137
|
builder.html do |xml|
|
138
|
-
xml.body do |
|
139
|
-
yield
|
138
|
+
xml.body do |body|
|
139
|
+
yield body
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
data/rack_session_access.gemspec
CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["andriy.yanko@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/railsware/rack_session_access"
|
11
11
|
s.summary = %q{Rack middleware that provides access to rack.session environment}
|
12
|
+
s.license = 'MIT'
|
12
13
|
|
13
14
|
s.rubyforge_project = "rack_session_access"
|
14
15
|
|
@@ -17,6 +18,12 @@ Gem::Specification.new do |s|
|
|
17
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
19
|
s.require_paths = ["lib"]
|
19
20
|
|
20
|
-
s.add_runtime_dependency "rack",
|
21
|
+
s.add_runtime_dependency "rack", ">=1.0.0"
|
21
22
|
s.add_runtime_dependency "builder", ">=2.0.0"
|
23
|
+
|
24
|
+
s.add_development_dependency 'rspec', '~>3.7.0'
|
25
|
+
s.add_development_dependency 'capybara', '~>3.0.1'
|
26
|
+
s.add_development_dependency 'chromedriver-helper'
|
27
|
+
s.add_development_dependency 'selenium-webdriver', '~>3.11.0'
|
28
|
+
s.add_development_dependency 'rails', '>=4.0.0'
|
22
29
|
end
|
data/spec/middleware_spec.rb
CHANGED
@@ -1,63 +1,55 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
shared_examples "common scenarios" do
|
4
|
-
let(:data) do
|
5
|
-
{
|
6
|
-
'user_email' => 'jack@daniels.com',
|
7
|
-
'user_profile' => { :age => 12 },
|
8
|
-
'role_ids' => [1, 20, 30]
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
4
|
scenario "changing session data" do
|
13
|
-
|
14
|
-
page.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
page.
|
19
|
-
page.
|
20
|
-
page.current_path.
|
5
|
+
visit RackSessionAccess.edit_path
|
6
|
+
expect(page).to have_content("Update rack session")
|
7
|
+
|
8
|
+
fill_in "data", with: RackSessionAccess.encode({'user_id' => 1})
|
9
|
+
click_button "Update"
|
10
|
+
expect(page).to have_content("Rack session data")
|
11
|
+
expect(page).to have_content('"user_id" : 1')
|
12
|
+
expect(page.current_path).to eq(RackSessionAccess.path)
|
21
13
|
end
|
22
14
|
|
23
15
|
scenario "providing no session data" do
|
24
|
-
|
25
|
-
page.
|
16
|
+
visit RackSessionAccess.edit_path
|
17
|
+
expect(page).to have_content("Update rack session")
|
26
18
|
|
27
|
-
|
28
|
-
page.
|
29
|
-
page.current_path.
|
19
|
+
click_button "Update"
|
20
|
+
expect(page).to have_content("Bad data")
|
21
|
+
expect(page.current_path).to eq(RackSessionAccess.path)
|
30
22
|
end
|
31
23
|
|
32
24
|
scenario "providing bad data" do
|
33
|
-
|
34
|
-
page.
|
25
|
+
visit RackSessionAccess.edit_path
|
26
|
+
expect(page).to have_content("Update rack session")
|
35
27
|
|
36
|
-
|
37
|
-
|
38
|
-
page.
|
39
|
-
page.current_path.
|
28
|
+
fill_in "data", :with => "qwertyuiop"
|
29
|
+
click_button "Update"
|
30
|
+
expect(page).to have_content("Bad data")
|
31
|
+
expect(page.current_path).to eq(RackSessionAccess.path)
|
40
32
|
end
|
41
33
|
|
42
34
|
scenario "modify session data with set_rack_session helper" do
|
43
35
|
page.set_rack_session(data)
|
44
36
|
|
45
|
-
|
46
|
-
page.
|
47
|
-
page.
|
48
|
-
page.
|
37
|
+
visit(RackSessionAccess.path)
|
38
|
+
expect(page).to have_content('"user_email" : "jack@daniels.com"')
|
39
|
+
expect(page).to have_content('"user_profile" : {:age=>12}')
|
40
|
+
expect(page).to have_content('"role_ids" : [1, 20, 30]')
|
49
41
|
end
|
50
42
|
|
51
43
|
scenario "accessing raw session data" do
|
52
44
|
page.set_rack_session(data)
|
53
45
|
|
54
|
-
|
55
|
-
raw_data =
|
56
|
-
raw_data.
|
46
|
+
visit(RackSessionAccess.path + '.raw')
|
47
|
+
raw_data = find(:xpath, "//body/pre").text
|
48
|
+
expect(raw_data).to be_present
|
57
49
|
actual_data = RackSessionAccess.decode(raw_data)
|
58
|
-
actual_data.
|
50
|
+
expect(actual_data).to be_kind_of(Hash)
|
59
51
|
data.each do |key, value|
|
60
|
-
actual_data[key].
|
52
|
+
expect(actual_data[key]).to eq(value)
|
61
53
|
end
|
62
54
|
end
|
63
55
|
|
@@ -66,63 +58,63 @@ shared_examples "common scenarios" do
|
|
66
58
|
|
67
59
|
actual_data = page.get_rack_session
|
68
60
|
|
69
|
-
actual_data.
|
61
|
+
expect(actual_data).to be_kind_of(Hash)
|
70
62
|
data.each do |key, value|
|
71
|
-
actual_data[key].
|
63
|
+
expect(actual_data[key]).to eq(value)
|
72
64
|
end
|
73
65
|
end
|
74
66
|
|
75
67
|
scenario "accessing raw session data using get_rack_session_key helper" do
|
76
68
|
page.set_rack_session(data)
|
77
69
|
|
78
|
-
page.get_rack_session_key('role_ids').
|
70
|
+
expect(page.get_rack_session_key('role_ids')).to eq([1, 20, 30])
|
79
71
|
end
|
80
72
|
end
|
81
73
|
|
82
74
|
shared_examples "rack scenarios" do
|
83
75
|
scenario "accessing application" do
|
84
|
-
|
85
|
-
page.text.
|
76
|
+
visit "/welcome"
|
77
|
+
expect(page.text).to eq("DUMMY")
|
86
78
|
end
|
87
79
|
end
|
88
80
|
|
89
81
|
shared_examples "sinatra scenarios" do
|
90
82
|
scenario "test application itself" do
|
91
|
-
|
92
|
-
page.
|
83
|
+
visit "/login"
|
84
|
+
expect(page).to have_content("Please log in")
|
93
85
|
|
94
|
-
|
95
|
-
page.
|
86
|
+
visit "/profile"
|
87
|
+
expect(page).to have_content("Please log in")
|
96
88
|
end
|
97
89
|
|
98
90
|
scenario "accessing application" do
|
99
|
-
|
100
|
-
page.text.
|
91
|
+
visit "/profile"
|
92
|
+
expect(page.text).to eq("Please log in")
|
101
93
|
|
102
|
-
page.set_rack_session(
|
94
|
+
page.set_rack_session(user_email: "jack@daniels.com")
|
103
95
|
|
104
|
-
|
105
|
-
page.text.
|
96
|
+
visit "/profile"
|
97
|
+
expect(page.text).to eq("Welcome, jack@daniels.com!")
|
106
98
|
end
|
107
99
|
end
|
108
100
|
|
109
101
|
shared_examples "rails scenarios" do
|
110
102
|
scenario "test application itself" do
|
111
|
-
|
112
|
-
page.
|
103
|
+
visit "/login"
|
104
|
+
expect(page).to have_content("Please log in")
|
113
105
|
|
114
|
-
|
115
|
-
page.
|
106
|
+
visit "/profile"
|
107
|
+
expect(page).to have_content("Please log in")
|
116
108
|
end
|
117
109
|
|
118
110
|
scenario "accessing application" do
|
119
|
-
|
120
|
-
page.text.
|
111
|
+
visit "/profile"
|
112
|
+
expect(page.text).to eq("Please log in")
|
121
113
|
|
122
|
-
page.set_rack_session(
|
114
|
+
page.set_rack_session(user_email: "jack@daniels.com")
|
123
115
|
|
124
|
-
|
125
|
-
page.text.
|
116
|
+
visit "/profile"
|
117
|
+
expect(page.text).to eq("Welcome, jack@daniels.com!")
|
126
118
|
end
|
127
119
|
end
|
128
120
|
|
@@ -132,11 +124,19 @@ feature "manage rack session", %q(
|
|
132
124
|
So I can write faster tests
|
133
125
|
) do
|
134
126
|
|
135
|
-
|
127
|
+
let(:data) do
|
128
|
+
{
|
129
|
+
'user_email' => 'jack@daniels.com',
|
130
|
+
'user_profile' => {age: 12},
|
131
|
+
'role_ids' => [1, 20, 30]
|
132
|
+
}
|
133
|
+
end
|
134
|
+
|
135
|
+
context ":rack_test driver", driver: :rack_test do
|
136
136
|
context "rack application" do
|
137
137
|
background { Capybara.app = TestRackApp }
|
138
138
|
include_examples "common scenarios"
|
139
|
-
include_examples "rack scenarios"
|
139
|
+
#include_examples "rack scenarios"
|
140
140
|
end
|
141
141
|
|
142
142
|
context "sinatra application" do
|
@@ -152,9 +152,7 @@ feature "manage rack session", %q(
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
155
|
-
|
156
|
-
|
157
|
-
context ":selenium driver", :driver => :selenium do
|
155
|
+
context ":selenium driver", driver: :selenium do
|
158
156
|
context "rack application" do
|
159
157
|
background { Capybara.app = TestRackApp }
|
160
158
|
include_examples "common scenarios"
|
@@ -3,36 +3,40 @@ require 'spec_helper'
|
|
3
3
|
describe RackSessionAccess do
|
4
4
|
subject { described_class }
|
5
5
|
|
6
|
-
|
6
|
+
it 'should have configured default path' do
|
7
|
+
expect(subject.path).to eq('/rack_session')
|
8
|
+
end
|
7
9
|
|
8
|
-
|
10
|
+
it 'should have configured default edit_path' do
|
11
|
+
expect(subject.edit_path).to eq('/rack_session/edit')
|
12
|
+
end
|
9
13
|
|
10
|
-
describe
|
11
|
-
it
|
14
|
+
describe '.encode' do
|
15
|
+
it 'should encode ruby hash to string' do
|
12
16
|
result = subject.encode( { 'a' => 'b' })
|
13
|
-
result.
|
17
|
+
expect(result).to be_kind_of(String)
|
14
18
|
end
|
15
19
|
end
|
16
20
|
|
17
|
-
describe
|
18
|
-
it
|
21
|
+
describe '.decode' do
|
22
|
+
it 'should decode marshalized and base64 encoded string' do
|
19
23
|
# Array(Marshal.dump({ :user_id => 100 })).pack("m")
|
20
24
|
# => "BAh7BjoMdXNlcl9pZGlp\n"
|
21
|
-
subject.decode("BAh7BjoMdXNlcl9pZGlp\n").
|
25
|
+
expect(subject.decode("BAh7BjoMdXNlcl9pZGlp\n")).to eq(user_id: 100)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
it
|
29
|
+
it 'should encode and decode value' do
|
26
30
|
source = { 'klass' => Class, :id => 100, '1' => 2 }
|
27
31
|
data = subject.encode(source)
|
28
32
|
result = subject.decode(data)
|
29
|
-
result.
|
33
|
+
expect(result).to eq(source)
|
30
34
|
end
|
31
35
|
|
32
|
-
it
|
36
|
+
it 'should encode and decode values with line brake characters' do
|
33
37
|
source = { 'line' => "one\ntwo" }
|
34
38
|
data = subject.encode(source)
|
35
39
|
result = subject.decode(data)
|
36
|
-
result.
|
40
|
+
expect(result).to eq(source)
|
37
41
|
end
|
38
42
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,11 +7,19 @@ Dir[File.expand_path('../../apps/*.rb', __FILE__)].each do |f|
|
|
7
7
|
require f
|
8
8
|
end
|
9
9
|
|
10
|
+
Capybara.server = :webrick
|
11
|
+
|
12
|
+
Capybara.register_driver :selenium do |app|
|
13
|
+
Capybara::Selenium::Driver.new app,
|
14
|
+
browser: ENV.fetch('SELENIUM_BROWSER', 'chrome').to_sym
|
15
|
+
end
|
16
|
+
|
10
17
|
TestSinatraApp.configure do |app|
|
11
18
|
app.environment = :test
|
12
19
|
app.use RackSessionAccess::Middleware
|
13
20
|
end
|
14
21
|
|
15
22
|
TestRailsApp::Application.configure do |app|
|
23
|
+
app.middleware.use ActionDispatch::Session::CookieStore
|
16
24
|
app.middleware.use RackSessionAccess::Middleware
|
17
25
|
end
|
metadata
CHANGED
@@ -1,38 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_session_access
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Andriy Yanko
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rack
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.0.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: builder
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 2.0.0
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.7.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: capybara
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: chromedriver-helper
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: selenium-webdriver
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.11.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.11.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rails
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 4.0.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 4.0.0
|
36
111
|
description:
|
37
112
|
email:
|
38
113
|
- andriy.yanko@gmail.com
|
@@ -40,9 +115,11 @@ executables: []
|
|
40
115
|
extensions: []
|
41
116
|
extra_rdoc_files: []
|
42
117
|
files:
|
43
|
-
- .gitignore
|
44
|
-
-
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
45
120
|
- Gemfile.rails4
|
121
|
+
- Gemfile.rails5
|
122
|
+
- LICENSE
|
46
123
|
- README.md
|
47
124
|
- Rakefile
|
48
125
|
- apps/test_rack_app.rb
|
@@ -57,30 +134,31 @@ files:
|
|
57
134
|
- spec/rack_session_access_spec.rb
|
58
135
|
- spec/spec_helper.rb
|
59
136
|
homepage: https://github.com/railsware/rack_session_access
|
60
|
-
licenses:
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
61
140
|
post_install_message:
|
62
141
|
rdoc_options: []
|
63
142
|
require_paths:
|
64
143
|
- lib
|
65
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
145
|
requirements:
|
68
|
-
- -
|
146
|
+
- - ">="
|
69
147
|
- !ruby/object:Gem::Version
|
70
148
|
version: '0'
|
71
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
150
|
requirements:
|
74
|
-
- -
|
151
|
+
- - ">="
|
75
152
|
- !ruby/object:Gem::Version
|
76
153
|
version: '0'
|
77
154
|
requirements: []
|
78
155
|
rubyforge_project: rack_session_access
|
79
|
-
rubygems_version:
|
156
|
+
rubygems_version: 2.6.11
|
80
157
|
signing_key:
|
81
|
-
specification_version:
|
158
|
+
specification_version: 4
|
82
159
|
summary: Rack middleware that provides access to rack.session environment
|
83
160
|
test_files:
|
84
161
|
- spec/middleware_spec.rb
|
85
162
|
- spec/rack_session_access_spec.rb
|
86
163
|
- spec/spec_helper.rb
|
164
|
+
has_rdoc:
|