Class: GdsApi::Validators::BasePathValidator
- Inherits:
-
Object
- Object
- GdsApi::Validators::BasePathValidator
- Defined in:
- lib/gds_api/validators/base_path_validator.rb
Constant Summary collapse
- MAX_PATH_LENGTH =
512
Instance Attribute Summary collapse
- #base_path ⇒ Object readonly
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(base_path) ⇒ BasePathValidator
constructor
A new instance of BasePathValidator.
- #valid? ⇒ Boolean
Constructor Details
#initialize(base_path) ⇒ BasePathValidator
Returns a new instance of BasePathValidator.
8 9 10 |
# File 'lib/gds_api/validators/base_path_validator.rb', line 8 def initialize(base_path) @base_path = base_path end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
6 7 8 |
# File 'lib/gds_api/validators/base_path_validator.rb', line 6 def base_path @base_path end |
Instance Method Details
#errors ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gds_api/validators/base_path_validator.rb', line 16 def errors return { base_path_invalid: ["must not be nil"] } if base_path.nil? errors = [] errors << [:base_path_invalid, "must start with a /"] if no_leading_slash? errors << [:base_path_too_long, "must not be longer than #{MAX_PATH_LENGTH} bytes"] if too_long? errors << [:base_path_invalid, "must not include runs of . and or / characters, which could be penetration attempts"] if potential_path_traversal? errors << [:base_path_invalid, "must not end with a ."] if ends_with_a_period? errors << [:base_path_invalid, "must not include characters that are not lowercase letters, numbers, -, ., or /"] if invalid_chars? errors.each_with_object({}) do |err, memo| memo[err[0]] ||= [] memo[err[0]] << err[1] end end |
#valid? ⇒ Boolean
12 13 14 |
# File 'lib/gds_api/validators/base_path_validator.rb', line 12 def valid? !(base_path.nil? || no_leading_slash? || too_long? || potential_path_traversal? || ends_with_a_period? || invalid_chars?) end |