File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ require "abstract_unit"
2+ require "action_dispatch"
3+ require "active_record"
4+
5+ class JsonParamsParsingTest < ActionDispatch ::IntegrationTest
6+ test "prevent null query" do
7+ # Make sure we have data to find
8+ klass = Class . new ( ActiveRecord ::Base ) do
9+ def self . name ; 'Foo' ; end
10+ establish_connection adapter : "sqlite3" , database : ":memory:"
11+ connection . create_table "foos" do |t |
12+ t . string :title
13+ t . timestamps null : false
14+ end
15+ end
16+ klass . create
17+ assert klass . first
18+
19+ app = -> ( env ) {
20+ request = ActionDispatch ::Request . new env
21+ params = ActionController ::Parameters . new request . parameters
22+ if params [ :t ]
23+ klass . find_by_title ( params [ :t ] )
24+ else
25+ nil
26+ end
27+ }
28+
29+ assert_nil app . call ( make_env ( { 't' => nil } ) )
30+ assert_nil app . call ( make_env ( { 't' => [ nil ] } ) )
31+
32+ [ [ [ nil ] ] , [ [ [ nil ] ] ] ] . each do |data |
33+ assert_nil app . call ( make_env ( { 't' => data } ) )
34+ end
35+ end
36+
37+ private
38+ def make_env json
39+ data = JSON . dump json
40+ content_length = data . length
41+ {
42+ 'CONTENT_LENGTH' => content_length ,
43+ 'CONTENT_TYPE' => 'application/json' ,
44+ 'rack.input' => StringIO . new ( data )
45+ }
46+ end
47+ end
You can’t perform that action at this time.
0 commit comments