(self, inner_path, content, content_size, content_size_optional)
| 886 | return False |
| 887 | |
| 888 | def verifyContentInclude(self, inner_path, content, content_size, content_size_optional): |
| 889 | # Load include details |
| 890 | rules = self.getRules(inner_path, content) |
| 891 | if not rules: |
| 892 | raise VerifyError("No rules") |
| 893 | |
| 894 | # Check include size limit |
| 895 | if rules.get("max_size") is not None: # Include size limit |
| 896 | if content_size > rules["max_size"]: |
| 897 | raise VerifyError("Include too large %sB > %sB" % (content_size, rules["max_size"])) |
| 898 | |
| 899 | if rules.get("max_size_optional") is not None: # Include optional files limit |
| 900 | if content_size_optional > rules["max_size_optional"]: |
| 901 | raise VerifyError("Include optional files too large %sB > %sB" % ( |
| 902 | content_size_optional, rules["max_size_optional"]) |
| 903 | ) |
| 904 | |
| 905 | # Filename limit |
| 906 | if rules.get("files_allowed"): |
| 907 | for file_inner_path in list(content["files"].keys()): |
| 908 | if not SafeRe.match(r"^%s$" % rules["files_allowed"], file_inner_path): |
| 909 | raise VerifyError("File not allowed: %s" % file_inner_path) |
| 910 | |
| 911 | if rules.get("files_allowed_optional"): |
| 912 | for file_inner_path in list(content.get("files_optional", {}).keys()): |
| 913 | if not SafeRe.match(r"^%s$" % rules["files_allowed_optional"], file_inner_path): |
| 914 | raise VerifyError("Optional file not allowed: %s" % file_inner_path) |
| 915 | |
| 916 | # Check if content includes allowed |
| 917 | if rules.get("includes_allowed") is False and content.get("includes"): |
| 918 | raise VerifyError("Includes not allowed") |
| 919 | |
| 920 | return True # All good |
| 921 | |
| 922 | # Verify file validity |
| 923 | # Return: None = Same as before, False = Invalid, True = Valid |
no test coverage detected