Check an untrusted variable TODO default checks vs more complicated ones (ie for String) The assumption is we get a dictionary from a request. We don't know if the key will be in the dictionary, or if it will be a reasonable input (ie not an empty string) It's annoyin
(spec,
log,
untrusted_input,
string_len_not_zero = True
)
| 7 | |
| 8 | |
| 9 | def input_check(spec, |
| 10 | log, |
| 11 | untrusted_input, |
| 12 | string_len_not_zero = True |
| 13 | ): |
| 14 | """ |
| 15 | Check an untrusted variable |
| 16 | |
| 17 | TODO default checks |
| 18 | vs more complicated ones (ie for String) |
| 19 | |
| 20 | The assumption is we get a dictionary from a request. |
| 21 | We don't know if the key will be in the dictionary, |
| 22 | or if it will be a reasonable input (ie not an empty string) |
| 23 | |
| 24 | It's annoying to have to do a bunch of these checks |
| 25 | if we have many inputs, and we may easily add future checks here. |
| 26 | |
| 27 | Can just be type == None if doesn't matter |
| 28 | |
| 29 | Arguments |
| 30 | spec, dict, variable name : type |
| 31 | log, dict using boilerplate.log |
| 32 | untrusted_input, dict of untrusted input |
| 33 | |
| 34 | Returns |
| 35 | log |
| 36 | Updated, |
| 37 | errors are stored in log["error"][name] |
| 38 | ONE OF: |
| 39 | Success case: |
| 40 | Variable |
| 41 | Failure case: |
| 42 | none |
| 43 | |
| 44 | |
| 45 | A spec dictionary may have a dictionary as a type |
| 46 | If so, then it should have a 'default' and 'kind' key |
| 47 | |
| 48 | CAUTION if any issues with "," or syntax make sure there are the two |
| 49 | closing brackets ie because the second one can be hard to see |
| 50 | and often it quotes WRONG line number. |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | The default value will be filled if None is provided |
| 55 | The kind will be used to type check |
| 56 | |
| 57 | spec_list_example = [{"name": str}, |
| 58 | {"permission": { |
| 59 | 'default': "all_secure_users", |
| 60 | 'kind': str |
| 61 | } |
| 62 | }, |
| 63 | {"label_mode" : { |
| 64 | 'default': "closed_all_available", |
| 65 | 'kind': str, |
| 66 | 'required': True, |
no test coverage detected