input_sanitizer 0.1.9 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/gempush.yml +28 -0
- data/.gitignore +2 -1
- data/.travis.yml +4 -8
- data/CHANGELOG +96 -0
- data/LICENSE +201 -22
- data/README.md +22 -3
- data/input_sanitizer.gemspec +10 -4
- data/lib/input_sanitizer.rb +5 -2
- data/lib/input_sanitizer/errors.rb +142 -0
- data/lib/input_sanitizer/extended_converters.rb +5 -52
- data/lib/input_sanitizer/extended_converters/comma_joined_integers_converter.rb +15 -0
- data/lib/input_sanitizer/extended_converters/comma_joined_strings_converter.rb +15 -0
- data/lib/input_sanitizer/extended_converters/positive_integer_converter.rb +12 -0
- data/lib/input_sanitizer/extended_converters/specific_values_converter.rb +19 -0
- data/lib/input_sanitizer/restricted_hash.rb +49 -8
- data/lib/input_sanitizer/v1.rb +22 -0
- data/lib/input_sanitizer/v1/clean_field.rb +38 -0
- data/lib/input_sanitizer/{default_converters.rb → v1/default_converters.rb} +30 -13
- data/lib/input_sanitizer/v1/sanitizer.rb +166 -0
- data/lib/input_sanitizer/v2.rb +13 -0
- data/lib/input_sanitizer/v2/clean_field.rb +36 -0
- data/lib/input_sanitizer/v2/clean_payload_collection_field.rb +41 -0
- data/lib/input_sanitizer/v2/clean_query_collection_field.rb +40 -0
- data/lib/input_sanitizer/v2/error_collection.rb +49 -0
- data/lib/input_sanitizer/v2/nested_sanitizer_factory.rb +19 -0
- data/lib/input_sanitizer/v2/payload_sanitizer.rb +130 -0
- data/lib/input_sanitizer/v2/payload_transform.rb +42 -0
- data/lib/input_sanitizer/v2/query_sanitizer.rb +33 -0
- data/lib/input_sanitizer/v2/types.rb +213 -0
- data/lib/input_sanitizer/version.rb +1 -1
- data/spec/extended_converters/comma_joined_integers_converter_spec.rb +18 -0
- data/spec/extended_converters/comma_joined_strings_converter_spec.rb +18 -0
- data/spec/extended_converters/positive_integer_converter_spec.rb +18 -0
- data/spec/extended_converters/specific_values_converter_spec.rb +27 -0
- data/spec/restricted_hash_spec.rb +37 -7
- data/spec/sanitizer_spec.rb +129 -26
- data/spec/spec_helper.rb +17 -2
- data/spec/v1/default_converters_spec.rb +141 -0
- data/spec/v2/converters_spec.rb +174 -0
- data/spec/v2/payload_sanitizer_spec.rb +460 -0
- data/spec/v2/payload_transform_spec.rb +98 -0
- data/spec/v2/query_sanitizer_spec.rb +300 -0
- data/v2.md +52 -0
- metadata +105 -40
- data/lib/input_sanitizer/sanitizer.rb +0 -152
- data/spec/default_converters_spec.rb +0 -101
- data/spec/extended_converters_spec.rb +0 -62
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'input_sanitizer/extended_converters'
|
3
|
-
|
4
|
-
describe InputSanitizer::AllowNil do
|
5
|
-
it "passes blanks" do
|
6
|
-
lambda { |_| 1 }.extend(InputSanitizer::AllowNil).call("").should be_nil
|
7
|
-
end
|
8
|
-
|
9
|
-
it "passes things the extended sanitizer passes" do
|
10
|
-
lambda { |_| :something }.extend(InputSanitizer::AllowNil).call(:stuff).
|
11
|
-
should eq(:something)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "raises error if the extended sanitizer raises error" do
|
15
|
-
action = lambda do
|
16
|
-
lambda { |_| raise "Some error" }.extend(InputSanitizer::AllowNil).call(:stuff)
|
17
|
-
end
|
18
|
-
|
19
|
-
action.should raise_error
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe InputSanitizer::PositiveIntegerConverter do
|
24
|
-
let(:converter) { InputSanitizer::PositiveIntegerConverter.new }
|
25
|
-
|
26
|
-
it "raises error if integer less than zero" do
|
27
|
-
lambda { converter.call("-3") }.should raise_error(InputSanitizer::ConversionError)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "raises error if integer equals zero" do
|
31
|
-
lambda { converter.call("0") }.should raise_error(InputSanitizer::ConversionError)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe InputSanitizer::CommaJoinedIntegersConverter do
|
36
|
-
let(:converter) { InputSanitizer::CommaJoinedIntegersConverter.new }
|
37
|
-
|
38
|
-
it "parses to array of ids" do
|
39
|
-
converter.call("1,2,3,5").should == [1, 2, 3, 5]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "raises on invalid character" do
|
43
|
-
lambda { converter.call(":") }.should raise_error(InputSanitizer::ConversionError)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe InputSanitizer::SpecificValuesConverter do
|
48
|
-
let(:converter) { InputSanitizer::SpecificValuesConverter.new([:a, :b]) }
|
49
|
-
|
50
|
-
it "converts valid value to symbol" do
|
51
|
-
converter.call("b").should == :b
|
52
|
-
end
|
53
|
-
|
54
|
-
it "raises on invalid value" do
|
55
|
-
lambda { converter.call("c") }.should raise_error(InputSanitizer::ConversionError)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "converts valid value to string" do
|
59
|
-
converter = InputSanitizer::SpecificValuesConverter.new(["a", "b"])
|
60
|
-
converter.call("a").should == "a"
|
61
|
-
end
|
62
|
-
end
|