Changeset 249200 in webkit
- Timestamp:
- Aug 28, 2019, 8:45:20 AM (7 years ago)
- Location:
- trunk/Tools
- Files:
-
- 4 edited
-
ChangeLog (modified) (1 diff)
-
resultsdbpy/resultsdbpy/controller/commit.py (modified) (3 diffs)
-
resultsdbpy/resultsdbpy/controller/commit_controller.py (modified) (1 diff)
-
resultsdbpy/resultsdbpy/controller/commit_unittest.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r249192 r249200 1 2019-08-28 Jonathan Bedard <jbedard@apple.com> 2 3 results.webkit.org: Sanitize all commit arguments on upload 4 https://bugs.webkit.org/show_bug.cgi?id=201189 5 <rdar://problem/54564837> 6 7 Reviewed by Aakash Jain. 8 9 * resultsdbpy/resultsdbpy/controller/commit.py: 10 (Commit.__init__): Only allow commits to be constructed with valid values. 11 * resultsdbpy/resultsdbpy/controller/commit_controller.py: 12 (CommitController.register): Strip potential API key. 13 * resultsdbpy/resultsdbpy/controller/commit_unittest.py: 14 (CommitUnittest.test_invalid): Test that commits which contain html inside the 15 repository_id, branch or commit id are rejected. 16 1 17 2019-08-02 Claudio Saavedra <csaavedra@igalia.com> 2 18 -
trunk/Tools/resultsdbpy/resultsdbpy/controller/commit.py
r247628 r249200 23 23 import calendar 24 24 import json 25 import re 25 26 26 27 from datetime import datetime … … 30 31 class Commit(object): 31 32 TIMESTAMP_TO_UUID_MULTIPLIER = 100 33 MAX_KEY_LENGTH = 128 32 34 33 35 @classmethod … … 50 52 51 53 self.repository_id = str(repository_id) 54 if not re.match(r'^[a-zA-Z?]+$', self.repository_id) or len(self.repository_id) > self.MAX_KEY_LENGTH: 55 raise ValueError(f"'{self.repository_id}' is an invalid repository id") 56 52 57 self.branch = str(branch) 58 if not re.match(r'^[a-zA-Z0-9-.?/]+$', self.branch) or len(self.branch) > self.MAX_KEY_LENGTH: 59 raise ValueError(f"'{self.branch}' is an invalid branch name") 53 60 54 61 # An id is either a git commit or SVN revision. 55 62 self.id = str(id) 63 if not re.match(r'^[a-fA-F0-9?]+$', self.id) or len(self.id) > 40: 64 raise ValueError(f"'{self.id}' is an invalid commit id") 56 65 57 66 if isinstance(timestamp, datetime): -
trunk/Tools/resultsdbpy/resultsdbpy/controller/commit_controller.py
r247628 r249200 268 268 try: 269 269 commit = request.form or json.loads(request.get_data()) 270 if 'api_key' in commit: 271 del commit['api_key'] 270 272 except ValueError: 271 273 abort(400, description='Expected uploaded data to be json') -
trunk/Tools/resultsdbpy/resultsdbpy/controller/commit_unittest.py
r247628 r249200 101 101 102 102 def test_invalid(self): 103 with self.assertRaises(ValueError) :103 with self.assertRaises(ValueError) as error: 104 104 Commit( 105 105 repository_id='safari', branch='master', … … 107 107 timestamp=None, 108 108 ) 109 self.assertEqual(str(error.exception), 'timestamp is not defined for commit') 110 111 with self.assertRaises(ValueError) as error: 112 Commit( 113 repository_id='invalid-repo', branch='master', 114 id='7be4084258a452e8fe22f36287c5b321e9c8249b', 115 timestamp=1537550685, 116 ) 117 self.assertEqual(str(error.exception), "'invalid-repo' is an invalid repository id") 118 119 with self.assertRaises(ValueError) as error: 120 Commit( 121 repository_id='i' * 129, branch='master', 122 id='7be4084258a452e8fe22f36287c5b321e9c8249b', 123 timestamp=1537550685, 124 ) 125 self.assertEqual(str(error.exception), f"'{'i' * 129}' is an invalid repository id") 126 127 with self.assertRaises(ValueError) as error: 128 Commit( 129 repository_id='safari', branch='<html>invalid-branch</html>', 130 id='7be4084258a452e8fe22f36287c5b321e9c8249b', 131 timestamp=1537550685, 132 ) 133 self.assertEqual(str(error.exception), "'<html>invalid-branch</html>' is an invalid branch name") 134 135 with self.assertRaises(ValueError) as error: 136 Commit( 137 repository_id='safari', branch='i' * 129, 138 id='7be4084258a452e8fe22f36287c5b321e9c8249b', 139 timestamp=1537550685, 140 ) 141 self.assertEqual(str(error.exception), f"'{'i' * 129}' is an invalid branch name") 142 143 with self.assertRaises(ValueError) as error: 144 Commit( 145 repository_id='safari', branch='master', 146 id='<html>1234</html>', 147 timestamp=1537550685, 148 ) 149 self.assertEqual(str(error.exception), "'<html>1234</html>' is an invalid commit id") 150 151 with self.assertRaises(ValueError) as error: 152 Commit( 153 repository_id='safari', branch='master', 154 id='0' * 41, 155 timestamp=1537550685, 156 ) 157 self.assertEqual(str(error.exception), f"'{'0' * 41}' is an invalid commit id")
Note:
See TracChangeset
for help on using the changeset viewer.