strong_parameters 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/action_controller/parameters.rb +13 -7
- data/lib/strong_parameters/version.rb +1 -1
- data/test/action_controller_required_params_test.rb +1 -1
- data/test/dummy/log/test.log +134 -3
- data/test/parameters_require_test.rb +1 -1
- data/test/parameters_taint_test.rb +16 -0
- metadata +9 -9
data/README.rdoc
CHANGED
@@ -25,7 +25,7 @@ In addition, parameters can be marked as required and flow through a predefined
|
|
25
25
|
# since you'll be able to reuse the same permit list between create and update. Also, you
|
26
26
|
# can specialize this method with per-user checking of permissible attributes.
|
27
27
|
def person_params
|
28
|
-
params.
|
28
|
+
params.require(:person).permit(:name, :age)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -26,9 +26,11 @@ module ActionController
|
|
26
26
|
self
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def require(key)
|
30
30
|
self[key].presence || raise(ActionController::ParameterMissing.new(key))
|
31
31
|
end
|
32
|
+
|
33
|
+
alias :required :require
|
32
34
|
|
33
35
|
def permit(*filters)
|
34
36
|
params = self.class.new
|
@@ -36,7 +38,7 @@ module ActionController
|
|
36
38
|
filters.each do |filter|
|
37
39
|
case filter
|
38
40
|
when Symbol then
|
39
|
-
params[filter] = self[filter]
|
41
|
+
params[filter] = self[filter] if has_key?(filter)
|
40
42
|
when Hash then
|
41
43
|
self.slice(*filter.keys).each do |key, value|
|
42
44
|
return unless value
|
@@ -62,18 +64,22 @@ module ActionController
|
|
62
64
|
convert_hashes_to_parameters(key, super)
|
63
65
|
end
|
64
66
|
|
65
|
-
def fetch(key)
|
66
|
-
unless block_given? || key?(key)
|
67
|
-
raise ActionController::ParameterMissing.new(key)
|
68
|
-
end
|
69
|
-
|
67
|
+
def fetch(key, *args)
|
70
68
|
convert_hashes_to_parameters(key, super)
|
69
|
+
rescue KeyError
|
70
|
+
raise ActionController::ParameterMissing.new(key)
|
71
71
|
end
|
72
72
|
|
73
73
|
def slice(*keys)
|
74
74
|
self.class.new(super)
|
75
75
|
end
|
76
76
|
|
77
|
+
def dup
|
78
|
+
super.tap do |duplicate|
|
79
|
+
duplicate.instance_variable_set :@permitted, @permitted
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
77
83
|
private
|
78
84
|
def convert_hashes_to_parameters(key, value)
|
79
85
|
if value.is_a?(Parameters) || !value.is_a?(Hash)
|
data/test/dummy/log/test.log
CHANGED
@@ -1,13 +1,102 @@
|
|
1
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
2
|
+
Processing by PeopleController#create as HTML
|
3
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
4
|
+
Rendered text template (0.0ms)
|
5
|
+
Completed 200 OK in 7ms (Views: 6.4ms | ActiveRecord: 0.0ms)
|
6
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
7
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
8
|
+
Processing by PeopleController#create as HTML
|
9
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
10
|
+
Rendered text template (0.0ms)
|
11
|
+
Completed 200 OK in 7ms (Views: 6.4ms | ActiveRecord: 0.0ms)
|
12
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
13
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
14
|
+
Processing by PeopleController#create_with_permit as HTML
|
15
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
16
|
+
Completed 200 OK in 0ms (Views: 0.2ms | ActiveRecord: 0.0ms)
|
17
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
18
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
19
|
+
Processing by PeopleController#create as HTML
|
20
|
+
Parameters: {"user"=>{"name"=>"Mjallo!"}}
|
21
|
+
Completed 500 Internal Server Error in 0ms
|
22
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
23
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
24
|
+
Processing by PeopleController#create as HTML
|
25
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
26
|
+
Completed 500 Internal Server Error in 8ms
|
27
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
1
28
|
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
29
|
+
Processing by PeopleController#create as HTML
|
30
|
+
Parameters: {"user"=>{"name"=>"Mjallo!"}}
|
31
|
+
Completed 500 Internal Server Error in 0ms
|
32
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
33
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
34
|
+
Processing by PeopleController#create as HTML
|
35
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
36
|
+
Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
|
2
37
|
[1m[35m (0.0ms)[0m rollback transaction
|
38
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
39
|
+
Processing by PeopleController#create as HTML
|
40
|
+
Parameters: {"user"=>{"name"=>"Mjallo!"}}
|
41
|
+
Completed 400 Bad Request in 0ms (ActiveRecord: 0.0ms)
|
42
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
43
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
44
|
+
Processing by PeopleController#create as HTML
|
45
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
46
|
+
Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
|
47
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
48
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
49
|
+
Processing by PeopleController#create as HTML
|
50
|
+
Parameters: {"user"=>{"name"=>"Mjallo!"}}
|
51
|
+
Completed 400 Bad Request in 0ms (ActiveRecord: 0.0ms)
|
52
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
3
53
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
54
|
+
Processing by PeopleController#create as HTML
|
55
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
56
|
+
Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
|
57
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
58
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
59
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
60
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
61
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
62
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
63
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
64
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
65
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
66
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
67
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
68
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
69
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
70
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
71
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
72
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
73
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
74
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
75
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
76
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
77
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
78
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
79
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
80
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
81
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
82
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
83
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
84
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
85
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
86
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
4
87
|
[1m[35m (0.0ms)[0m rollback transaction
|
5
88
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
6
89
|
[1m[35m (0.0ms)[0m rollback transaction
|
90
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
91
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
7
92
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
8
93
|
[1m[35m (0.0ms)[0m rollback transaction
|
9
94
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
10
95
|
[1m[35m (0.0ms)[0m rollback transaction
|
96
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
97
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
98
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
99
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
11
100
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
12
101
|
[1m[35m (0.0ms)[0m rollback transaction
|
13
102
|
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
@@ -16,10 +105,16 @@
|
|
16
105
|
[1m[35m (0.0ms)[0m rollback transaction
|
17
106
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
18
107
|
[1m[35m (0.0ms)[0m rollback transaction
|
108
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
109
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
19
110
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
20
111
|
[1m[35m (0.0ms)[0m rollback transaction
|
21
112
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
22
113
|
[1m[35m (0.0ms)[0m rollback transaction
|
114
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
115
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
116
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
117
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
23
118
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
24
119
|
[1m[35m (0.0ms)[0m rollback transaction
|
25
120
|
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
@@ -28,10 +123,16 @@
|
|
28
123
|
[1m[35m (0.0ms)[0m rollback transaction
|
29
124
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
30
125
|
[1m[35m (0.0ms)[0m rollback transaction
|
126
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
127
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
31
128
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
32
129
|
[1m[35m (0.0ms)[0m rollback transaction
|
33
130
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
34
131
|
[1m[35m (0.0ms)[0m rollback transaction
|
132
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
133
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
134
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
135
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
35
136
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
36
137
|
[1m[35m (0.0ms)[0m rollback transaction
|
37
138
|
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
@@ -40,7 +141,7 @@
|
|
40
141
|
[1m[35m (0.0ms)[0m rollback transaction
|
41
142
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
42
143
|
[1m[35m (0.0ms)[0m rollback transaction
|
43
|
-
[1m[36m (0.
|
144
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
44
145
|
[1m[35m (0.0ms)[0m rollback transaction
|
45
146
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
46
147
|
[1m[35m (0.0ms)[0m rollback transaction
|
@@ -52,18 +153,22 @@
|
|
52
153
|
[1m[35m (0.0ms)[0m rollback transaction
|
53
154
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
54
155
|
[1m[35m (0.0ms)[0m rollback transaction
|
55
|
-
[1m[36m (0.
|
156
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
56
157
|
[1m[35m (0.0ms)[0m rollback transaction
|
57
158
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
58
159
|
[1m[35m (0.0ms)[0m rollback transaction
|
59
160
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
60
161
|
[1m[35m (0.0ms)[0m rollback transaction
|
61
|
-
[1m[36m (0.
|
162
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
163
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
164
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
62
165
|
[1m[35m (0.0ms)[0m rollback transaction
|
63
166
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
64
167
|
[1m[35m (0.0ms)[0m rollback transaction
|
65
168
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
66
169
|
[1m[35m (0.0ms)[0m rollback transaction
|
170
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
171
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
67
172
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
68
173
|
[1m[35m (0.0ms)[0m rollback transaction
|
69
174
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
@@ -78,11 +183,37 @@
|
|
78
183
|
[1m[35m (0.0ms)[0m rollback transaction
|
79
184
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
80
185
|
[1m[35m (0.0ms)[0m rollback transaction
|
186
|
+
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
187
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
188
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
189
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
81
190
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
82
191
|
[1m[35m (0.0ms)[0m rollback transaction
|
83
192
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
84
193
|
[1m[35m (0.0ms)[0m rollback transaction
|
85
194
|
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
195
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
196
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
197
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
198
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
199
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
200
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
201
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
202
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
203
|
+
Processing by PeopleController#create as HTML
|
204
|
+
Parameters: {"user"=>{"name"=>"Mjallo!"}}
|
205
|
+
Completed 400 Bad Request in 0ms (ActiveRecord: 0.0ms)
|
206
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
207
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
208
|
+
Processing by PeopleController#create as HTML
|
209
|
+
Parameters: {"person"=>{"name"=>"Mjallo!"}}
|
210
|
+
Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
|
86
211
|
[1m[35m (0.0ms)[0m rollback transaction
|
87
212
|
[1m[36m (0.3ms)[0m [1mbegin transaction[0m
|
88
213
|
[1m[35m (0.0ms)[0m rollback transaction
|
214
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
215
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
216
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
217
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
218
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
219
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
@@ -4,7 +4,7 @@ require 'action_controller/parameters'
|
|
4
4
|
class ParametersRequireTest < ActiveSupport::TestCase
|
5
5
|
test "required parameters must be present not merely not nil" do
|
6
6
|
assert_raises(ActionController::ParameterMissing) do
|
7
|
-
ActionController::Parameters.new(person: {}).
|
7
|
+
ActionController::Parameters.new(person: {}).require(:person)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -15,6 +15,13 @@ class ParametersTaintTest < ActiveSupport::TestCase
|
|
15
15
|
assert_equal :foo, e.param
|
16
16
|
end
|
17
17
|
|
18
|
+
test "fetch doesnt raise ParameterMissing exception if there is a default" do
|
19
|
+
assert_nothing_raised do
|
20
|
+
assert_equal "monkey", @params.fetch(:foo, "monkey")
|
21
|
+
assert_equal "monkey", @params.fetch(:foo) { "monkey" }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
18
25
|
test "permitted is sticky on accessors" do
|
19
26
|
assert !@params.slice(:person).permitted?
|
20
27
|
assert !@params[:person][:name].permitted?
|
@@ -42,4 +49,13 @@ class ParametersTaintTest < ActiveSupport::TestCase
|
|
42
49
|
assert_equal "Chicago", @params[:person][:hometown]
|
43
50
|
assert_equal "Jonas", @params[:person][:family][:brother]
|
44
51
|
end
|
52
|
+
|
53
|
+
test "permitting parameters that are not there should not include the keys" do
|
54
|
+
assert !@params.permit(:person, :funky).has_key?(:funky)
|
55
|
+
end
|
56
|
+
|
57
|
+
test "permit state is kept on a dup" do
|
58
|
+
@params.permit!
|
59
|
+
assert_equal @params.permitted?, @params.dup.permitted?
|
60
|
+
end
|
45
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70325350860480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.2.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70325350860480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activemodel
|
27
|
-
requirement: &
|
27
|
+
requirement: &70325350858180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70325350858180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70325350848320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70325350848320
|
47
47
|
description:
|
48
48
|
email:
|
49
49
|
- david@heinemeierhansson.com
|
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
89
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.8.
|
90
|
+
rubygems_version: 1.8.11
|
91
91
|
signing_key:
|
92
92
|
specification_version: 3
|
93
93
|
summary: Permitted and required parameters for Action Pack
|