OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The LUCI Authors. All rights reserved. | 2 # Copyright 2015 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 """Tests that recipes are on their best behavior. | 6 """Tests that recipes are on their best behavior. |
7 | 7 |
8 Checks that recipes only import modules from a whitelist. Imports are | 8 Checks that recipes only import modules from a whitelist. Imports are |
9 generally not safe in recipes if they depend on the platform, since | 9 generally not safe in recipes if they depend on the platform, since |
10 e.g. you can run a recipe simulation for a Windows recipe on Linux. | 10 e.g. you can run a recipe simulation for a Windows recipe on Linux. |
11 """ | 11 """ |
12 | 12 |
13 # TODO(luqui): Implement lint for recipe modules also. | 13 # TODO(luqui): Implement lint for recipe modules also. |
14 | 14 |
15 from __future__ import absolute_import | 15 from __future__ import absolute_import |
16 import re | 16 import re |
17 import os | |
18 import sys | |
19 import types | 17 import types |
20 | 18 |
21 | 19 |
22 MODULES_WHITELIST = [ | 20 MODULES_WHITELIST = [ |
23 r'base64', | 21 r'base64', |
24 r'collections', | 22 r'collections', |
25 r'contextlib', | 23 r'contextlib', |
26 r'copy', | 24 r'copy', |
27 r'datetime', | 25 r'datetime', |
28 r'functools', | 26 r'functools', |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 whitelist = map(re.compile, MODULES_WHITELIST + whitelist) | 67 whitelist = map(re.compile, MODULES_WHITELIST + whitelist) |
70 | 68 |
71 errors = [] | 69 errors = [] |
72 for recipe_path, recipe_name in universe_view.loop_over_recipes(): | 70 for recipe_path, recipe_name in universe_view.loop_over_recipes(): |
73 errors.extend( | 71 errors.extend( |
74 ImportsTest(recipe_path, recipe_name, whitelist, universe_view)) | 72 ImportsTest(recipe_path, recipe_name, whitelist, universe_view)) |
75 | 73 |
76 if errors: | 74 if errors: |
77 raise TestFailure('\n'.join(map(str, errors))) | 75 raise TestFailure('\n'.join(map(str, errors))) |
78 | 76 |
OLD | NEW |