simple_workflow 1.0.11 → 1.1.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 +4 -4
- data/Gemfile.lock +78 -64
- data/History.rdoc +13 -0
- data/README.md +19 -17
- data/Rakefile +1 -1
- data/lib/simple_workflow.rb +3 -3
- data/lib/simple_workflow/controller.rb +7 -46
- data/lib/simple_workflow/detour.rb +11 -0
- data/lib/simple_workflow/middleware.rb +83 -0
- data/lib/simple_workflow/railtie.rb +8 -0
- data/lib/simple_workflow/version.rb +1 -1
- data/test/controller_test.rb +11 -1
- data/test/helper_test.rb +1 -1
- data/test/middleware_test.rb +75 -0
- data/test/test_app.rb +15 -0
- data/test/test_helper.rb +12 -1
- metadata +38 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b0aaefffccf2f6cae0b554c08bdfdd59535a2a2
|
|
4
|
+
data.tar.gz: 8be9945fb088a813a4e79c83378137957f99c924
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b82cee1cbdfe7841ca5f22dc0bb885e321c287d1da1e12d727d66a76dabd5e84dcbb32f1d5adf56d02879b090f961d679a90401b15737f39687837b35bd5f55
|
|
7
|
+
data.tar.gz: 89fcca43ee312be2d4e188b8bddc5c60996eaba10778eb0d07da7d4e9e7460169a2dac1d1c022b0735b8805cd5d935afe532c38b97c335f5cbdc67e0c3a66e9a
|
data/Gemfile.lock
CHANGED
|
@@ -1,108 +1,117 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
simple_workflow (1.0
|
|
4
|
+
simple_workflow (1.1.0)
|
|
5
5
|
rails (~> 4.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionmailer (4.2.
|
|
11
|
-
actionpack (= 4.2.
|
|
12
|
-
actionview (= 4.2.
|
|
13
|
-
activejob (= 4.2.
|
|
10
|
+
actionmailer (4.2.6)
|
|
11
|
+
actionpack (= 4.2.6)
|
|
12
|
+
actionview (= 4.2.6)
|
|
13
|
+
activejob (= 4.2.6)
|
|
14
14
|
mail (~> 2.5, >= 2.5.4)
|
|
15
15
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
16
|
-
actionpack (4.2.
|
|
17
|
-
actionview (= 4.2.
|
|
18
|
-
activesupport (= 4.2.
|
|
19
|
-
rack (~> 1.6
|
|
16
|
+
actionpack (4.2.6)
|
|
17
|
+
actionview (= 4.2.6)
|
|
18
|
+
activesupport (= 4.2.6)
|
|
19
|
+
rack (~> 1.6)
|
|
20
20
|
rack-test (~> 0.6.2)
|
|
21
21
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
22
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.
|
|
23
|
-
actionview (4.2.
|
|
24
|
-
activesupport (= 4.2.
|
|
22
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
23
|
+
actionview (4.2.6)
|
|
24
|
+
activesupport (= 4.2.6)
|
|
25
25
|
builder (~> 3.1)
|
|
26
26
|
erubis (~> 2.7.0)
|
|
27
27
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
28
|
-
rails-html-sanitizer (~> 1.0, >= 1.0.
|
|
29
|
-
activejob (4.2.
|
|
30
|
-
activesupport (= 4.2.
|
|
28
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
29
|
+
activejob (4.2.6)
|
|
30
|
+
activesupport (= 4.2.6)
|
|
31
31
|
globalid (>= 0.3.0)
|
|
32
|
-
activemodel (4.2.
|
|
33
|
-
activesupport (= 4.2.
|
|
32
|
+
activemodel (4.2.6)
|
|
33
|
+
activesupport (= 4.2.6)
|
|
34
34
|
builder (~> 3.1)
|
|
35
|
-
activerecord (4.2.
|
|
36
|
-
activemodel (= 4.2.
|
|
37
|
-
activesupport (= 4.2.
|
|
35
|
+
activerecord (4.2.6)
|
|
36
|
+
activemodel (= 4.2.6)
|
|
37
|
+
activesupport (= 4.2.6)
|
|
38
38
|
arel (~> 6.0)
|
|
39
|
-
activesupport (4.2.
|
|
39
|
+
activesupport (4.2.6)
|
|
40
40
|
i18n (~> 0.7)
|
|
41
41
|
json (~> 1.7, >= 1.7.7)
|
|
42
42
|
minitest (~> 5.1)
|
|
43
43
|
thread_safe (~> 0.3, >= 0.3.4)
|
|
44
44
|
tzinfo (~> 1.1)
|
|
45
|
-
|
|
45
|
+
ansi (1.5.0)
|
|
46
|
+
arel (6.0.3)
|
|
46
47
|
builder (3.2.2)
|
|
48
|
+
concurrent-ruby (1.0.1)
|
|
49
|
+
docile (1.1.5)
|
|
47
50
|
erubis (2.7.0)
|
|
48
|
-
globalid (0.3.
|
|
51
|
+
globalid (0.3.6)
|
|
49
52
|
activesupport (>= 4.1.0)
|
|
50
|
-
hike (1.2.3)
|
|
51
53
|
i18n (0.7.0)
|
|
52
|
-
json (1.8.
|
|
53
|
-
json (1.8.
|
|
54
|
-
loofah (2.0.
|
|
54
|
+
json (1.8.3)
|
|
55
|
+
json (1.8.3-java)
|
|
56
|
+
loofah (2.0.3)
|
|
55
57
|
nokogiri (>= 1.5.9)
|
|
56
|
-
mail (2.6.
|
|
57
|
-
mime-types (>= 1.16, <
|
|
58
|
-
mime-types (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
mail (2.6.4)
|
|
59
|
+
mime-types (>= 1.16, < 4)
|
|
60
|
+
mime-types (3.0)
|
|
61
|
+
mime-types-data (~> 3.2015)
|
|
62
|
+
mime-types-data (3.2016.0221)
|
|
63
|
+
mini_portile2 (2.0.0)
|
|
64
|
+
minitest (5.8.4)
|
|
65
|
+
minitest-reporters (1.1.8)
|
|
66
|
+
ansi
|
|
67
|
+
builder
|
|
68
|
+
minitest (>= 5.0)
|
|
69
|
+
ruby-progressbar
|
|
70
|
+
nokogiri (1.6.7.2)
|
|
71
|
+
mini_portile2 (~> 2.0.0.rc2)
|
|
72
|
+
rack (1.6.4)
|
|
66
73
|
rack-test (0.6.3)
|
|
67
74
|
rack (>= 1.0)
|
|
68
|
-
rails (4.2.
|
|
69
|
-
actionmailer (= 4.2.
|
|
70
|
-
actionpack (= 4.2.
|
|
71
|
-
actionview (= 4.2.
|
|
72
|
-
activejob (= 4.2.
|
|
73
|
-
activemodel (= 4.2.
|
|
74
|
-
activerecord (= 4.2.
|
|
75
|
-
activesupport (= 4.2.
|
|
75
|
+
rails (4.2.6)
|
|
76
|
+
actionmailer (= 4.2.6)
|
|
77
|
+
actionpack (= 4.2.6)
|
|
78
|
+
actionview (= 4.2.6)
|
|
79
|
+
activejob (= 4.2.6)
|
|
80
|
+
activemodel (= 4.2.6)
|
|
81
|
+
activerecord (= 4.2.6)
|
|
82
|
+
activesupport (= 4.2.6)
|
|
76
83
|
bundler (>= 1.3.0, < 2.0)
|
|
77
|
-
railties (= 4.2.
|
|
84
|
+
railties (= 4.2.6)
|
|
78
85
|
sprockets-rails
|
|
79
86
|
rails-deprecated_sanitizer (1.0.3)
|
|
80
87
|
activesupport (>= 4.2.0.alpha)
|
|
81
|
-
rails-dom-testing (1.0.
|
|
88
|
+
rails-dom-testing (1.0.7)
|
|
82
89
|
activesupport (>= 4.2.0.beta, < 5.0)
|
|
83
90
|
nokogiri (~> 1.6.0)
|
|
84
91
|
rails-deprecated_sanitizer (>= 1.0.1)
|
|
85
|
-
rails-html-sanitizer (1.0.
|
|
92
|
+
rails-html-sanitizer (1.0.3)
|
|
86
93
|
loofah (~> 2.0)
|
|
87
|
-
railties (4.2.
|
|
88
|
-
actionpack (= 4.2.
|
|
89
|
-
activesupport (= 4.2.
|
|
94
|
+
railties (4.2.6)
|
|
95
|
+
actionpack (= 4.2.6)
|
|
96
|
+
activesupport (= 4.2.6)
|
|
90
97
|
rake (>= 0.8.7)
|
|
91
98
|
thor (>= 0.18.1, < 2.0)
|
|
92
|
-
rake (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
rake (11.1.2)
|
|
100
|
+
ruby-progressbar (1.7.5)
|
|
101
|
+
simplecov (0.11.2)
|
|
102
|
+
docile (~> 1.1.0)
|
|
103
|
+
json (~> 1.8)
|
|
104
|
+
simplecov-html (~> 0.10.0)
|
|
105
|
+
simplecov-html (0.10.0)
|
|
106
|
+
sprockets (3.6.0)
|
|
107
|
+
concurrent-ruby (~> 1.0)
|
|
108
|
+
rack (> 1, < 3)
|
|
109
|
+
sprockets-rails (3.0.4)
|
|
110
|
+
actionpack (>= 4.0)
|
|
111
|
+
activesupport (>= 4.0)
|
|
112
|
+
sprockets (>= 3.0.0)
|
|
102
113
|
thor (0.19.1)
|
|
103
|
-
thread_safe (0.3.
|
|
104
|
-
thread_safe (0.3.4-java)
|
|
105
|
-
tilt (1.4.1)
|
|
114
|
+
thread_safe (0.3.5)
|
|
106
115
|
tzinfo (1.2.2)
|
|
107
116
|
thread_safe (~> 0.1)
|
|
108
117
|
|
|
@@ -111,4 +120,9 @@ PLATFORMS
|
|
|
111
120
|
ruby
|
|
112
121
|
|
|
113
122
|
DEPENDENCIES
|
|
123
|
+
minitest-reporters (~> 1.0)
|
|
114
124
|
simple_workflow!
|
|
125
|
+
simplecov (~> 0.9)
|
|
126
|
+
|
|
127
|
+
BUNDLED WITH
|
|
128
|
+
1.11.2
|
data/History.rdoc
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
== 1.1.0 2016-04-17
|
|
2
|
+
|
|
3
|
+
=== Feature
|
|
4
|
+
|
|
5
|
+
* Rewrite as Rails Engine middleware
|
|
6
|
+
* Add support for Ruby 2.3 and JRuby 9000
|
|
7
|
+
* Require Ruby 2.1 or later
|
|
8
|
+
|
|
9
|
+
=== Fixes
|
|
10
|
+
|
|
11
|
+
* Better session cookie overflow protection
|
|
12
|
+
|
|
13
|
+
|
|
1
14
|
== 1.0.11 2015-01-22
|
|
2
15
|
|
|
3
16
|
=== Fixes
|
data/README.md
CHANGED
|
@@ -7,32 +7,33 @@ simple_workflow
|
|
|
7
7
|
* http://rubydoc.info/gems/simple_workflow
|
|
8
8
|
* https://rubygems.org/gems/simple_workflow
|
|
9
9
|
|
|
10
|
-
## DESCRIPTION
|
|
10
|
+
## DESCRIPTION
|
|
11
11
|
|
|
12
|
-
Extension to Rails to allow
|
|
12
|
+
Extension to Rails to allow simple workflow browser navigation using detours
|
|
13
|
+
with returns.
|
|
13
14
|
|
|
14
|
-
## FEATURES
|
|
15
|
+
## FEATURES
|
|
15
16
|
|
|
16
|
-
* switch your "link_to" lines to "detour_to" and your controller "redirect_to"
|
|
17
|
-
to return from whence they came.
|
|
17
|
+
* switch your "link_to" lines to "detour_to" and your controller "redirect_to"
|
|
18
|
+
to "back_or_redirect_to" to allow users to return from whence they came.
|
|
18
19
|
|
|
19
20
|
## SYNOPSIS:
|
|
20
21
|
|
|
21
22
|
In views:
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
detour_to :controller => :my_models, :action => :create
|
|
25
|
+
back_or_link_to :controller => :welcome, :action => :index
|
|
26
|
+
image_button_to :controller => :my_models, :action => :create
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
link_to 'Link with custom origin', with_detour(destination_path, origin_path)
|
|
28
29
|
|
|
29
30
|
In controllers:
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
back_or_redirect_to :controller => :my_models, :action => :index
|
|
32
33
|
|
|
33
34
|
In your tests:
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
def test_valid_login_redirects_as_specified
|
|
36
37
|
add_stored_detour "/bogus/location"
|
|
37
38
|
post :login, :user => { :login => "tesla", :password => "atest" }
|
|
38
39
|
assert_logged_in users(:tesla)
|
|
@@ -40,19 +41,20 @@ In your tests:
|
|
|
40
41
|
assert_redirected_to "http://#{request.host}/bogus/location"
|
|
41
42
|
end
|
|
42
43
|
|
|
43
|
-
## REQUIREMENTS
|
|
44
|
+
## REQUIREMENTS
|
|
44
45
|
|
|
45
|
-
*
|
|
46
|
+
* Ruby 2.1 or newer. JRuby supported!
|
|
47
|
+
* Rails 4.x
|
|
46
48
|
|
|
47
|
-
## INSTALL
|
|
49
|
+
## INSTALL
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
gem install simple_workflow
|
|
50
52
|
|
|
51
53
|
or in Gemfile
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
gem 'simple_workflow'
|
|
54
56
|
|
|
55
|
-
## LICENSE
|
|
57
|
+
## LICENSE
|
|
56
58
|
|
|
57
59
|
(The MIT License)
|
|
58
60
|
|
data/Rakefile
CHANGED
data/lib/simple_workflow.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
|
2
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
|
3
2
|
|
|
4
3
|
require 'action_controller'
|
|
5
4
|
|
|
@@ -7,6 +6,8 @@ require 'simple_workflow/version'
|
|
|
7
6
|
require 'simple_workflow/helper'
|
|
8
7
|
require 'simple_workflow/controller'
|
|
9
8
|
require 'simple_workflow/test_helper'
|
|
9
|
+
require 'simple_workflow/middleware'
|
|
10
|
+
require 'simple_workflow/railtie'
|
|
10
11
|
|
|
11
12
|
module ApplicationHelper
|
|
12
13
|
include SimpleWorkflow::Helper
|
|
@@ -15,7 +16,6 @@ end
|
|
|
15
16
|
class ActionController::Base
|
|
16
17
|
include SimpleWorkflow::Helper
|
|
17
18
|
include SimpleWorkflow::Controller
|
|
18
|
-
before_filter :store_detour_from_params
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
class ActiveSupport::TestCase
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
require 'simple_workflow/detour'
|
|
2
|
+
|
|
1
3
|
module SimpleWorkflow::Controller
|
|
4
|
+
include SimpleWorkflow::Detour
|
|
5
|
+
|
|
2
6
|
# Like ActionController::Base#redirect_to, but stores the location we come from, enabling returning here later.
|
|
3
7
|
def detour_to(options)
|
|
4
8
|
store_detour(params)
|
|
@@ -18,56 +22,13 @@ module SimpleWorkflow::Controller
|
|
|
18
22
|
def store_detour(options, post = false)
|
|
19
23
|
options = options.dup.permit!.to_h if options.is_a?(ActionController::Parameters)
|
|
20
24
|
options[:request_method] = :post if post
|
|
21
|
-
|
|
22
|
-
logger.debug "Ignored duplicate detour: #{options.inspect}"
|
|
23
|
-
return
|
|
24
|
-
end
|
|
25
|
-
session[:detours] ||= []
|
|
26
|
-
session[:detours] << options
|
|
27
|
-
remove_old_detours
|
|
28
|
-
logger.debug "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def remove_old_detours
|
|
32
|
-
if Rails.application.config.session_store == ActionDispatch::Session::CookieStore
|
|
33
|
-
ss = ws = nil
|
|
34
|
-
loop do
|
|
35
|
-
ser_val = cookies.signed_or_encrypted.send(:serialize, nil, session.to_hash)
|
|
36
|
-
ss = encryptor.encrypt_and_sign(ser_val).size
|
|
37
|
-
wf_ser_val = cookies.signed_or_encrypted.send(:serialize, nil, session[:detours])
|
|
38
|
-
ws = encryptor.encrypt_and_sign(wf_ser_val).size
|
|
39
|
-
break unless ws >= 2048 || (ss >= 3072 && session[:detours] && session[:detours].size > 0)
|
|
40
|
-
logger.warn "Workflow too large (#{ws}/#{ss}). Dropping oldest detour."
|
|
41
|
-
session[:detours].shift
|
|
42
|
-
reset_workflow if session[:detours].empty?
|
|
43
|
-
end
|
|
44
|
-
logger.debug "session: #{ss} bytes, workflow(#{session[:detours].try(:size) || 0}): #{ws} bytes"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def encryptor
|
|
49
|
-
return @simple_workflow_encryptor if @simple_workflow_encryptor
|
|
50
|
-
@simple_workflow_encryptor = cookies.signed_or_encrypted.instance_variable_get(:@encryptor)
|
|
51
|
-
return @simple_workflow_encryptor if @simple_workflow_encryptor
|
|
52
|
-
secret_key_base = Rails.application.config.secret_key_base ||
|
|
53
|
-
Rails.application.config.secret_token ||
|
|
54
|
-
SecureRandom.hex(64)
|
|
55
|
-
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
|
|
56
|
-
key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator)
|
|
57
|
-
secret = key_generator.generate_key('encrypted cookie')
|
|
58
|
-
sign_secret = key_generator.generate_key('signed encrypted cookie')
|
|
59
|
-
@simple_workflow_encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret)
|
|
25
|
+
store_detour_in_session(session, options)
|
|
60
26
|
end
|
|
61
|
-
private :encryptor
|
|
62
27
|
|
|
63
28
|
def store_detour_from_params
|
|
64
|
-
if params[:detour]
|
|
65
|
-
store_detour(params[:detour])
|
|
66
|
-
end
|
|
67
|
-
if params[:return_from_detour] && session[:detours]
|
|
68
|
-
pop_detour
|
|
69
|
-
end
|
|
70
29
|
end
|
|
30
|
+
deprecate :store_detour_from_params,
|
|
31
|
+
deprecator: ActiveSupport::Deprecation.new('1.2', 'SimpleWorkflow') # TODO(uwe)
|
|
71
32
|
|
|
72
33
|
def back(response_status_and_flash)
|
|
73
34
|
return false if session[:detours].nil?
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module SimpleWorkflow::Detour
|
|
2
|
+
def store_detour_in_session(session, options)
|
|
3
|
+
if session[:detours] && session[:detours].last == options
|
|
4
|
+
Rails.logger.try(:debug, "Ignored duplicate detour: #{options.inspect}")
|
|
5
|
+
return
|
|
6
|
+
end
|
|
7
|
+
session[:detours] ||= []
|
|
8
|
+
session[:detours] << options
|
|
9
|
+
Rails.logger.try(:debug, "Added detour (#{session[:detours].try(:size) || 0}): #{options.inspect}")
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'simple_workflow/detour'
|
|
2
|
+
|
|
3
|
+
class SimpleWorkflow::Middleware
|
|
4
|
+
include SimpleWorkflow::Detour
|
|
5
|
+
|
|
6
|
+
def initialize(app)
|
|
7
|
+
@app = app
|
|
8
|
+
@simple_workflow_encryptor = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def call(env)
|
|
12
|
+
store_detour_from_params(env)
|
|
13
|
+
status, headers, response = @app.call(env)
|
|
14
|
+
remove_old_detours(env)
|
|
15
|
+
[status, headers, response]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def request(env)
|
|
21
|
+
ActionDispatch::Request.new(env)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cookie_jar(env)
|
|
25
|
+
request(env).cookie_jar.signed_or_encrypted
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def params(env)
|
|
29
|
+
request(env).params
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def cookies(env)
|
|
33
|
+
request(env).cookies
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def session(env)
|
|
37
|
+
env['rack.session']
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def remove_old_detours(env)
|
|
41
|
+
if (cookie_store = session(env).instance_variable_get('@by'))
|
|
42
|
+
.is_a? ActionDispatch::Session::CookieStore
|
|
43
|
+
ss = ws = nil
|
|
44
|
+
session = session(env)
|
|
45
|
+
loop do
|
|
46
|
+
# env[ActionDispatch::Cookies::COOKIES_SERIALIZER]
|
|
47
|
+
ser_val = cookie_jar(env).send(:serialize, nil, session.to_hash)
|
|
48
|
+
ss = encryptor(env).encrypt_and_sign(ser_val).size
|
|
49
|
+
wf_ser_val = cookie_jar(env).send(:serialize, nil, session[:detours])
|
|
50
|
+
ws = encryptor(env).encrypt_and_sign(wf_ser_val).size
|
|
51
|
+
break unless ws >= 2048 || (ss >= 3072 && session[:detours] && session[:detours].size > 0)
|
|
52
|
+
Rails.logger.warn "Workflow too large (#{ws}/#{ss}). Dropping oldest detour."
|
|
53
|
+
session[:detours].shift
|
|
54
|
+
reset_workflow if session[:detours].empty?
|
|
55
|
+
end
|
|
56
|
+
Rails.logger.debug "session: #{ss} bytes, workflow(#{session[:detours].try(:size) || 0}): #{ws} bytes"
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def encryptor(env)
|
|
61
|
+
return @simple_workflow_encryptor if @simple_workflow_encryptor
|
|
62
|
+
@simple_workflow_encryptor = cookie_jar(env).instance_variable_get(:@encryptor)
|
|
63
|
+
return @simple_workflow_encryptor if @simple_workflow_encryptor
|
|
64
|
+
secret_key_base = Rails.application.config.secret_key_base ||
|
|
65
|
+
Rails.application.config.secret_token ||
|
|
66
|
+
SecureRandom.hex(64)
|
|
67
|
+
key_generator = ActiveSupport::KeyGenerator.new(secret_key_base, iterations: 1000)
|
|
68
|
+
key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator)
|
|
69
|
+
secret = key_generator.generate_key('encrypted cookie')
|
|
70
|
+
sign_secret = key_generator.generate_key('signed encrypted cookie')
|
|
71
|
+
@simple_workflow_encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def store_detour_from_params(env)
|
|
75
|
+
if params(env)[:detour]
|
|
76
|
+
store_detour_in_session(session(env), params(env)[:detour])
|
|
77
|
+
end
|
|
78
|
+
if params(env)[:return_from_detour] && session[:detours]
|
|
79
|
+
pop_detour
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
data/test/controller_test.rb
CHANGED
|
@@ -10,7 +10,11 @@ class ControllerTest < MiniTest::Test
|
|
|
10
10
|
@cookies = ActionDispatch::Cookies::CookieJar.new(ActiveSupport::KeyGenerator.new('secret'), nil, false, options)
|
|
11
11
|
@logger = Rails.logger
|
|
12
12
|
@session = {}
|
|
13
|
-
Rails.
|
|
13
|
+
# TODO(uwe): Remove when we stop testing Rails 4.1
|
|
14
|
+
if Rails.version !~ /^4\.1\./
|
|
15
|
+
Rails.app_class = TestApp
|
|
16
|
+
end
|
|
17
|
+
# ODOT
|
|
14
18
|
end
|
|
15
19
|
|
|
16
20
|
def test_store_detour
|
|
@@ -21,6 +25,12 @@ class ControllerTest < MiniTest::Test
|
|
|
21
25
|
assert_equal({detours: [location]}, session)
|
|
22
26
|
end
|
|
23
27
|
|
|
28
|
+
# TODO(uwe): Remove. The method does nothing. Just a stub for compatability.
|
|
29
|
+
def test_deprecated_store_detour_from_params
|
|
30
|
+
store_detour_from_params
|
|
31
|
+
assert_equal({}, session)
|
|
32
|
+
end
|
|
33
|
+
# ODOT
|
|
24
34
|
end
|
|
25
35
|
|
|
26
36
|
class TestApp < Rails::Application
|
data/test/helper_test.rb
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require_relative 'test_helper'
|
|
2
|
+
require 'simple_workflow/middleware'
|
|
3
|
+
require_relative 'test_app'
|
|
4
|
+
|
|
5
|
+
class MiddlewareTest < MiniTest::Test
|
|
6
|
+
def setup
|
|
7
|
+
@app = TestApp.instance
|
|
8
|
+
# @app = ->(env) { [200, env, 'app response'] }
|
|
9
|
+
@stack = Rack::Builder.new @app do
|
|
10
|
+
use ActionDispatch::Cookies
|
|
11
|
+
use ActionDispatch::Session::CookieStore
|
|
12
|
+
use SimpleWorkflow::Middleware
|
|
13
|
+
use ActionDispatch::Flash
|
|
14
|
+
end
|
|
15
|
+
@request = Rack::MockRequest.new(@stack)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_get_without_detour
|
|
19
|
+
env = env_for('/')
|
|
20
|
+
|
|
21
|
+
status, headers, response = @stack.call env
|
|
22
|
+
|
|
23
|
+
assert_equal 200, status
|
|
24
|
+
assert_equal(env, headers)
|
|
25
|
+
assert_equal 'app response', response
|
|
26
|
+
assert_equal([], headers['rack.session'].to_hash.keys)
|
|
27
|
+
assert_equal(nil, headers['rack.session'].to_hash['detours'])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_detour
|
|
31
|
+
env = env_for('/?detour[controller]=test')
|
|
32
|
+
|
|
33
|
+
status, headers, response = @stack.call env
|
|
34
|
+
|
|
35
|
+
assert_equal 200, status
|
|
36
|
+
assert_equal(env, headers)
|
|
37
|
+
assert_equal 'app response', response
|
|
38
|
+
assert_equal(%w(session_id detours), headers['rack.session'].to_hash.keys)
|
|
39
|
+
assert_equal([{'controller' => 'test'}], headers['rack.session'].to_hash['detours'])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_detour_cleanup
|
|
43
|
+
_, env, _ = @stack.call env_for('/?detour[controller]=test_first')
|
|
44
|
+
(50..99).each do |i|
|
|
45
|
+
_, env, _ = @stack.call env_for("/?detour[controller]=test_#{i}",
|
|
46
|
+
'rack.session' => env['rack.session'],
|
|
47
|
+
'rack.session.options' => env['rack.session.options']
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
status, env, response = @stack.call env_for('/?detour[controller]=test_last',
|
|
51
|
+
'rack.session' => env['rack.session'],
|
|
52
|
+
'rack.session.options' => env['rack.session.options']
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
assert_equal 200, status
|
|
56
|
+
assert_equal 'app response', response
|
|
57
|
+
assert_equal(%w(session_id detours), env['rack.session'].to_hash.keys)
|
|
58
|
+
|
|
59
|
+
assert_equal([{'controller' => 'test_57'}, {'controller' => 'test_58'}, {'controller' => 'test_59'}, {'controller' => 'test_60'}, {'controller' => 'test_61'}, {'controller' => 'test_62'}, {'controller' => 'test_63'}, {'controller' => 'test_64'}, {'controller' => 'test_65'}, {'controller' => 'test_66'}, {'controller' => 'test_67'}, {'controller' => 'test_68'}, {'controller' => 'test_69'}, {'controller' => 'test_70'}, {'controller' => 'test_71'}, {'controller' => 'test_72'}, {'controller' => 'test_73'}, {'controller' => 'test_74'}, {'controller' => 'test_75'}, {'controller' => 'test_76'}, {'controller' => 'test_77'}, {'controller' => 'test_78'}, {'controller' => 'test_79'}, {'controller' => 'test_80'}, {'controller' => 'test_81'}, {'controller' => 'test_82'}, {'controller' => 'test_83'}, {'controller' => 'test_84'}, {'controller' => 'test_85'}, {'controller' => 'test_86'}, {'controller' => 'test_87'}, {'controller' => 'test_88'}, {'controller' => 'test_89'}, {'controller' => "test_90"}, {"controller" => "test_91"}, {"controller" => "test_92"}, {"controller" => "test_93"}, {"controller" => "test_94"}, {"controller" => "test_95"}, {"controller" => "test_96"}, {"controller" => "test_97"}, {"controller" => "test_98"}, {"controller" => "test_99"}, {"controller" => "test_last"}],
|
|
60
|
+
env['rack.session'].to_hash['detours'])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def env_for(url, opts={})
|
|
66
|
+
default_opts = {
|
|
67
|
+
ActionDispatch::Cookies::COOKIES_SERIALIZER => :json,
|
|
68
|
+
ActionDispatch::Cookies::GENERATOR_KEY => ActiveSupport::KeyGenerator.new('secret'),
|
|
69
|
+
ActionDispatch::Cookies::SECRET_KEY_BASE => 'secret',
|
|
70
|
+
# ActionDispatch::Cookies::SECRET_TOKEN => 'secret',
|
|
71
|
+
}
|
|
72
|
+
Rack::MockRequest.env_for(url, default_opts.update(opts))
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
data/test/test_app.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'rails'
|
|
2
|
+
|
|
3
|
+
class TestApp < Rails::Application
|
|
4
|
+
config.action_dispatch.cookies_serializer = :json
|
|
5
|
+
config.action_dispatch.key_generator = ActiveSupport::KeyGenerator.new('secret')
|
|
6
|
+
config.logger = Logger.new('log/test.log')
|
|
7
|
+
config.secret_key_base = 'secret key base'
|
|
8
|
+
# config.secret_token = 'secret token'
|
|
9
|
+
|
|
10
|
+
Rails.logger = config.logger
|
|
11
|
+
|
|
12
|
+
def call(env)
|
|
13
|
+
[200, env, 'app response']
|
|
14
|
+
end
|
|
15
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require 'bundler/setup'
|
|
3
|
+
require 'simplecov'
|
|
4
|
+
SimpleCov.start { coverage_dir File.expand_path('../coverage', File.dirname(__FILE__)) }
|
|
3
5
|
require 'minitest/autorun'
|
|
4
|
-
require
|
|
6
|
+
require 'minitest/reporters'
|
|
7
|
+
MiniTest::Reporters.use!
|
|
8
|
+
require 'rails'
|
|
9
|
+
require 'simple_workflow'
|
|
10
|
+
|
|
11
|
+
if Gem::Requirement.new('~>4.2') =~ Gem::Version.new(Rails.version)
|
|
12
|
+
ActiveSupport::TestCase.test_order = :random
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
FileUtils.mkdir_p File.expand_path '../log', __dir__
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: simple_workflow
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Uwe Kubosch
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-04-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -24,6 +24,34 @@ dependencies:
|
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '4.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: simplecov
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0.9'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0.9'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest-reporters
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.0'
|
|
27
55
|
description: Expands Ruby On Rails to allow simple breadcrumb detour workflows.
|
|
28
56
|
email: uwe@kubosch.no
|
|
29
57
|
executables: []
|
|
@@ -37,11 +65,16 @@ files:
|
|
|
37
65
|
- Rakefile
|
|
38
66
|
- lib/simple_workflow.rb
|
|
39
67
|
- lib/simple_workflow/controller.rb
|
|
68
|
+
- lib/simple_workflow/detour.rb
|
|
40
69
|
- lib/simple_workflow/helper.rb
|
|
70
|
+
- lib/simple_workflow/middleware.rb
|
|
71
|
+
- lib/simple_workflow/railtie.rb
|
|
41
72
|
- lib/simple_workflow/test_helper.rb
|
|
42
73
|
- lib/simple_workflow/version.rb
|
|
43
74
|
- test/controller_test.rb
|
|
44
75
|
- test/helper_test.rb
|
|
76
|
+
- test/middleware_test.rb
|
|
77
|
+
- test/test_app.rb
|
|
45
78
|
- test/test_helper.rb
|
|
46
79
|
homepage: https://github.com/donv/simple_workflow
|
|
47
80
|
licenses:
|
|
@@ -53,9 +86,9 @@ require_paths:
|
|
|
53
86
|
- lib
|
|
54
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
88
|
requirements:
|
|
56
|
-
- - "
|
|
89
|
+
- - "~>"
|
|
57
90
|
- !ruby/object:Gem::Version
|
|
58
|
-
version: '
|
|
91
|
+
version: '2.1'
|
|
59
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
93
|
requirements:
|
|
61
94
|
- - ">="
|
|
@@ -63,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
63
96
|
version: '0'
|
|
64
97
|
requirements: []
|
|
65
98
|
rubyforge_project: donv/simple_workflow
|
|
66
|
-
rubygems_version: 2.
|
|
99
|
+
rubygems_version: 2.5.1
|
|
67
100
|
signing_key:
|
|
68
101
|
specification_version: 4
|
|
69
102
|
summary: Add simple breadcrumbs "detour" workflow to Ruby On Rails.
|