input_sanitizer 0.1.10 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yaml +26 -0
  3. data/.github/workflows/gempush.yml +28 -0
  4. data/.gitignore +2 -1
  5. data/CHANGELOG +99 -0
  6. data/LICENSE +201 -22
  7. data/README.md +24 -4
  8. data/input_sanitizer.gemspec +10 -4
  9. data/lib/input_sanitizer.rb +5 -2
  10. data/lib/input_sanitizer/errors.rb +142 -0
  11. data/lib/input_sanitizer/extended_converters.rb +5 -42
  12. data/lib/input_sanitizer/extended_converters/comma_joined_integers_converter.rb +15 -0
  13. data/lib/input_sanitizer/extended_converters/comma_joined_strings_converter.rb +15 -0
  14. data/lib/input_sanitizer/extended_converters/positive_integer_converter.rb +12 -0
  15. data/lib/input_sanitizer/extended_converters/specific_values_converter.rb +19 -0
  16. data/lib/input_sanitizer/restricted_hash.rb +49 -8
  17. data/lib/input_sanitizer/v1.rb +22 -0
  18. data/lib/input_sanitizer/v1/clean_field.rb +38 -0
  19. data/lib/input_sanitizer/{default_converters.rb → v1/default_converters.rb} +20 -13
  20. data/lib/input_sanitizer/v1/sanitizer.rb +166 -0
  21. data/lib/input_sanitizer/v2.rb +13 -0
  22. data/lib/input_sanitizer/v2/clean_field.rb +36 -0
  23. data/lib/input_sanitizer/v2/clean_payload_collection_field.rb +41 -0
  24. data/lib/input_sanitizer/v2/clean_query_collection_field.rb +40 -0
  25. data/lib/input_sanitizer/v2/error_collection.rb +49 -0
  26. data/lib/input_sanitizer/v2/nested_sanitizer_factory.rb +19 -0
  27. data/lib/input_sanitizer/v2/payload_sanitizer.rb +130 -0
  28. data/lib/input_sanitizer/v2/payload_transform.rb +42 -0
  29. data/lib/input_sanitizer/v2/query_sanitizer.rb +33 -0
  30. data/lib/input_sanitizer/v2/types.rb +227 -0
  31. data/lib/input_sanitizer/version.rb +1 -1
  32. data/spec/extended_converters/comma_joined_integers_converter_spec.rb +18 -0
  33. data/spec/extended_converters/comma_joined_strings_converter_spec.rb +18 -0
  34. data/spec/extended_converters/positive_integer_converter_spec.rb +18 -0
  35. data/spec/extended_converters/specific_values_converter_spec.rb +27 -0
  36. data/spec/restricted_hash_spec.rb +37 -7
  37. data/spec/sanitizer_spec.rb +129 -26
  38. data/spec/spec_helper.rb +17 -2
  39. data/spec/v1/default_converters_spec.rb +141 -0
  40. data/spec/v2/converters_spec.rb +174 -0
  41. data/spec/v2/payload_sanitizer_spec.rb +534 -0
  42. data/spec/v2/payload_transform_spec.rb +98 -0
  43. data/spec/v2/query_sanitizer_spec.rb +300 -0
  44. data/v2.md +52 -0
  45. metadata +105 -40
  46. data/.travis.yml +0 -12
  47. data/lib/input_sanitizer/sanitizer.rb +0 -140
  48. data/spec/default_converters_spec.rb +0 -101
  49. 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