Merge ~jslarraz/review-tools:schema-add-layout into review-tools:master
- Git
- lp:~jslarraz/review-tools
- schema-add-layout
- Merge into master
Proposed by
Jorge Sancho Larraz
Status: | Merged |
---|---|
Merged at revision: | 5934f2a041b7e784ab1bd332d7832536dfc1c5ce |
Proposed branch: | ~jslarraz/review-tools:schema-add-layout |
Merge into: | review-tools:master |
Diff against target: |
1025 lines (+180/-747) 6 files modified
check-names.list (+0/-3) reviewtools/schemas/snap.json (+57/-0) reviewtools/sr_lint.py (+0/-206) reviewtools/tests/schemas/test_schema_snap.py (+123/-0) reviewtools/tests/test_sr_lint.py (+0/-346) tests/test.sh.expected (+0/-192) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alex Murray | Approve | ||
Review via email:
|
Commit message
many: validate snap.yaml::layout via schema
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jorge Sancho Larraz (jslarraz) wrote : | # |
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jorge Sancho Larraz (jslarraz) wrote : | # |
See inline comments
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jorge Sancho Larraz (jslarraz) wrote : | # |
Current tests cases have a 100% coverage. Thus, passing all the existent cases indicates that the regular expression is fine
See https:/
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/check-names.list b/check-names.list | |||
2 | index 5725ecf..687f33f 100644 | |||
3 | --- a/check-names.list | |||
4 | +++ b/check-names.list | |||
5 | @@ -90,9 +90,6 @@ lint-snap-v2:icon_theme_size| | |||
6 | 90 | lint-snap-v2:iffy_files| | 90 | lint-snap-v2:iffy_files| |
7 | 91 | lint-snap-v2:install-mode| | 91 | lint-snap-v2:install-mode| |
8 | 92 | lint-snap-v2:invalid_link| | 92 | lint-snap-v2:invalid_link| |
9 | 93 | lint-snap-v2:layout_source| | ||
10 | 94 | lint-snap-v2:layout_target| | ||
11 | 95 | lint-snap-v2:layout| | ||
12 | 96 | lint-snap-v2:meta_gui_desktop| | 93 | lint-snap-v2:meta_gui_desktop| |
13 | 97 | lint-snap-v2:mpris_slot_name| | 94 | lint-snap-v2:mpris_slot_name| |
14 | 98 | lint-snap-v2:personal-files_attrib_valid| | 95 | lint-snap-v2:personal-files_attrib_valid| |
15 | diff --git a/reviewtools/schemas/snap.json b/reviewtools/schemas/snap.json | |||
16 | index e8038b0..d45ddbf 100644 | |||
17 | --- a/reviewtools/schemas/snap.json | |||
18 | +++ b/reviewtools/schemas/snap.json | |||
19 | @@ -89,6 +89,63 @@ | |||
20 | 89 | } | 89 | } |
21 | 90 | }, | 90 | }, |
22 | 91 | "additionalProperties": false | 91 | "additionalProperties": false |
23 | 92 | }, | ||
24 | 93 | "layout": { | ||
25 | 94 | "description": "Modify the execution environment of a strictly-confined snap.", | ||
26 | 95 | "$comment": "See https://forum.snapcraft.io/t/why-are-snap-layouts-limited-to-15-entries/15337/3", | ||
27 | 96 | "type": "object", | ||
28 | 97 | "propertyNames": { | ||
29 | 98 | "not": { | ||
30 | 99 | "anyOf": [ | ||
31 | 100 | {"pattern": "^/boot"}, | ||
32 | 101 | {"pattern": "^/dev"}, | ||
33 | 102 | {"pattern": "^/home"}, | ||
34 | 103 | {"pattern": "^(/usr)?/lib/firmware"}, | ||
35 | 104 | {"pattern": "^(/usr)?/lib/modules"}, | ||
36 | 105 | {"pattern": "^/lost+found"}, | ||
37 | 106 | {"pattern": "^/media"}, | ||
38 | 107 | {"pattern": "^/proc"}, | ||
39 | 108 | {"pattern": "^(/var)?/run"}, | ||
40 | 109 | {"pattern": "^/sys"}, | ||
41 | 110 | {"pattern": "^/tmp"}, | ||
42 | 111 | {"pattern": "^/var/lib/snapd"}, | ||
43 | 112 | {"pattern": "^/var/snap"} | ||
44 | 113 | ] | ||
45 | 114 | } | ||
46 | 115 | }, | ||
47 | 116 | "patternProperties": { | ||
48 | 117 | "^(?:\\$(?:SNAP|SNAP_COMMON|SNAP_DATA))?(\\/(?![\\.]*\\/)[^\\/\\0]*)*[\\/]?$": { | ||
49 | 118 | "$comment": "The core of this regex, (\\/[^\\/\\0]*)*, is intended to match groups of (slash + file name), where file name does not contain slash or NULL characters. The negative lookahead (?![\\.]*\\/) is used to ensure that at least one character other than dots is present between two consecutive slashes, thus avoiding non-normalized paths but still allowing hidden files. Optionally the path may start with $SNAP, $SNAP_COMMON or $SNAP_DATA and may have a tailing slash", | ||
50 | 119 | "type": "object", | ||
51 | 120 | "patternProperties": { | ||
52 | 121 | "^bind|bind-file|symlink$": { | ||
53 | 122 | "type": "string", | ||
54 | 123 | "$comment": "This regex is identical to the previous one with the exception that it always must start with $SNAP, $SNAP_COMMON or $SNAP_DATA", | ||
55 | 124 | "pattern": "^\\$(SNAP|SNAP_COMMON|SNAP_DATA)(\\/(?![\\.]*\\/)[^\\/\\0]*)*[\\/]?$" | ||
56 | 125 | }, | ||
57 | 126 | "^mode$": { | ||
58 | 127 | "type": "integer", | ||
59 | 128 | "minimum": 1, | ||
60 | 129 | "maximum": 511 | ||
61 | 130 | }, | ||
62 | 131 | "^type$": { | ||
63 | 132 | "type": "string", | ||
64 | 133 | "enum": ["tmpfs"] | ||
65 | 134 | }, | ||
66 | 135 | "^user|group$": { | ||
67 | 136 | "type": "string", | ||
68 | 137 | "not": { | ||
69 | 138 | "pattern": "^[0-9]+$" | ||
70 | 139 | } | ||
71 | 140 | } | ||
72 | 141 | }, | ||
73 | 142 | "minProperties": 1, | ||
74 | 143 | "additionalProperties": false | ||
75 | 144 | } | ||
76 | 145 | }, | ||
77 | 146 | "minProperties": 1, | ||
78 | 147 | "maxProperties": 100, | ||
79 | 148 | "additionalProperties": false | ||
80 | 92 | } | 149 | } |
81 | 93 | }, | 150 | }, |
82 | 94 | "required": ["name", "version"] | 151 | "required": ["name", "version"] |
83 | diff --git a/reviewtools/sr_lint.py b/reviewtools/sr_lint.py | |||
84 | index 8cad5e9..72d6691 100644 | |||
85 | --- a/reviewtools/sr_lint.py | |||
86 | +++ b/reviewtools/sr_lint.py | |||
87 | @@ -2360,212 +2360,6 @@ class SnapReviewLint(SnapReview): | |||
88 | 2360 | s = "paths found in both read and write: %s" % ", ".join(both) | 2360 | s = "paths found in both read and write: %s" % ", ".join(both) |
89 | 2361 | self._add_result(t, n, s) | 2361 | self._add_result(t, n, s) |
90 | 2362 | 2362 | ||
91 | 2363 | def check_layout(self): | ||
92 | 2364 | """Check layout""" | ||
93 | 2365 | if "layout" not in self.snap_yaml: | ||
94 | 2366 | return | ||
95 | 2367 | |||
96 | 2368 | # snap/validate.go - ValidateLayout() | ||
97 | 2369 | snap_vars = ["$SNAP", "$SNAP_COMMON", "$SNAP_DATA"] | ||
98 | 2370 | target_bad_prefixes = [ | ||
99 | 2371 | "/boot", | ||
100 | 2372 | "/dev", | ||
101 | 2373 | "/home", | ||
102 | 2374 | "(/usr)?/lib/firmware", | ||
103 | 2375 | "(/usr)?/lib/modules", | ||
104 | 2376 | "/lost+found", | ||
105 | 2377 | "/media", | ||
106 | 2378 | "/proc", | ||
107 | 2379 | "(/var)?/run", | ||
108 | 2380 | "/sys", | ||
109 | 2381 | "/tmp", | ||
110 | 2382 | "/var/lib/snapd", | ||
111 | 2383 | "/var/snap", | ||
112 | 2384 | ] | ||
113 | 2385 | |||
114 | 2386 | def _verify_layout_target(p, disallowed): | ||
115 | 2387 | if "\0" in p or os.path.normpath(p) != p: | ||
116 | 2388 | return False | ||
117 | 2389 | |||
118 | 2390 | # if the normalized path starts with snap_vars, then it is ok | ||
119 | 2391 | for prefix in snap_vars: | ||
120 | 2392 | if p.startswith("%s/" % prefix): | ||
121 | 2393 | return True | ||
122 | 2394 | |||
123 | 2395 | # otherwise it must be an absolute path | ||
124 | 2396 | if not p.startswith("/"): | ||
125 | 2397 | return False | ||
126 | 2398 | |||
127 | 2399 | # p is now guaranteed to start with '/' and not '//...' | ||
128 | 2400 | for dis in disallowed: | ||
129 | 2401 | if re.match(dis, p): | ||
130 | 2402 | return False | ||
131 | 2403 | |||
132 | 2404 | return True | ||
133 | 2405 | |||
134 | 2406 | def _verify_layout_source(p, allowed): | ||
135 | 2407 | if "\0" in p or os.path.normpath(p) != p or not p.startswith("$"): | ||
136 | 2408 | return False | ||
137 | 2409 | |||
138 | 2410 | # p is guaranteed to start with '$' | ||
139 | 2411 | top = p.split("/")[0] | ||
140 | 2412 | if top not in allowed: | ||
141 | 2413 | return False | ||
142 | 2414 | |||
143 | 2415 | return True | ||
144 | 2416 | |||
145 | 2417 | # arbitrary; 10 was agreed upon with snapd team (zyga) but found snaps | ||
146 | 2418 | # with 8, so bumped to 15. Unfortunately, others hit the ceiling, so | ||
147 | 2419 | # bumping to 30, then bumped to 100 since surely 100 layouts is enough | ||
148 | 2420 | # for anyone ;) | ||
149 | 2421 | # https://forum.snapcraft.io/t/why-are-snap-layouts-limited-to-15-entries/15337/3 | ||
150 | 2422 | maximum_layouts = 100 | ||
151 | 2423 | |||
152 | 2424 | key = "layout" | ||
153 | 2425 | t = "info" | ||
154 | 2426 | n = self._get_check_name(key) | ||
155 | 2427 | s = "OK" | ||
156 | 2428 | if not isinstance(self.snap_yaml[key], dict): | ||
157 | 2429 | t = "error" | ||
158 | 2430 | s = "invalid %s entry: %s (not a dict)" % (key, self.snap_yaml[key]) | ||
159 | 2431 | self._add_result(t, n, s) | ||
160 | 2432 | return | ||
161 | 2433 | elif len(self.snap_yaml[key].keys()) < 1: | ||
162 | 2434 | t = "error" | ||
163 | 2435 | s = "invalid %s entry (empty)" % (key) | ||
164 | 2436 | self._add_result(t, n, s) | ||
165 | 2437 | return | ||
166 | 2438 | elif len(self.snap_yaml[key].keys()) > maximum_layouts: | ||
167 | 2439 | t = "error" | ||
168 | 2440 | s = "too many defined layouts (%d > %d)" % ( | ||
169 | 2441 | len(self.snap_yaml[key].keys()), | ||
170 | 2442 | maximum_layouts, | ||
171 | 2443 | ) | ||
172 | 2444 | self._add_result(t, n, s) | ||
173 | 2445 | return | ||
174 | 2446 | self._add_result(t, n, s) | ||
175 | 2447 | |||
176 | 2448 | for target in self.snap_yaml[key]: | ||
177 | 2449 | t = "info" | ||
178 | 2450 | n = self._get_check_name("%s_target" % key, app=target) | ||
179 | 2451 | s = "OK" | ||
180 | 2452 | |||
181 | 2453 | if not isinstance(self.snap_yaml[key][target], dict): | ||
182 | 2454 | t = "error" | ||
183 | 2455 | s = "invalid entry: %s (not a dict)" % (self.snap_yaml[key][target]) | ||
184 | 2456 | self._add_result(t, n, s) | ||
185 | 2457 | continue | ||
186 | 2458 | elif len(self.snap_yaml[key][target].keys()) < 1: | ||
187 | 2459 | t = "error" | ||
188 | 2460 | s = "invalid target '%s' (empty)" % (target) | ||
189 | 2461 | self._add_result(t, n, s) | ||
190 | 2462 | continue | ||
191 | 2463 | elif not _verify_layout_target(target, target_bad_prefixes): | ||
192 | 2464 | t = "error" | ||
193 | 2465 | s = ( | ||
194 | 2466 | "invalid mount target: '%s'" % target | ||
195 | 2467 | + " (should be " | ||
196 | 2468 | + "a legal path (ie, absolute path or one that starts " | ||
197 | 2469 | + "with: %s)" % ", ".join(snap_vars) | ||
198 | 2470 | + ". If absolute, " | ||
199 | 2471 | + "should not start with: %s" % ", ".join(target_bad_prefixes) | ||
200 | 2472 | ) | ||
201 | 2473 | self._add_result(t, n, s) | ||
202 | 2474 | continue | ||
203 | 2475 | self._add_result(t, n, s) | ||
204 | 2476 | |||
205 | 2477 | # from snap/info_snap.go | ||
206 | 2478 | known = ["bind", "bind-file", "symlink", "type", "user", "group", "mode"] | ||
207 | 2479 | for ltype in self.snap_yaml[key][target]: | ||
208 | 2480 | t = "info" | ||
209 | 2481 | n = self._get_check_name("%s" % key, app=target, extra=ltype) | ||
210 | 2482 | s = "OK" | ||
211 | 2483 | |||
212 | 2484 | if ltype not in known: | ||
213 | 2485 | t = "error" | ||
214 | 2486 | s = "invalid layout: '%s' (should be one of %s)" % ( | ||
215 | 2487 | ltype, | ||
216 | 2488 | ", ".join(known), | ||
217 | 2489 | ) | ||
218 | 2490 | self._add_result(t, n, s) | ||
219 | 2491 | continue | ||
220 | 2492 | |||
221 | 2493 | if ltype in ["bind", "bind-file", "symlink"]: | ||
222 | 2494 | target = target | ||
223 | 2495 | source = self.snap_yaml[key][target][ltype] | ||
224 | 2496 | t = "info" | ||
225 | 2497 | n = self._get_check_name( | ||
226 | 2498 | "%s_source" % key, app=target, extra=source | ||
227 | 2499 | ) | ||
228 | 2500 | s = "OK" | ||
229 | 2501 | |||
230 | 2502 | if not isinstance(source, str): | ||
231 | 2503 | t = "error" | ||
232 | 2504 | s = "invalid source: %s (not a str)" % source | ||
233 | 2505 | elif not _verify_layout_source(source, snap_vars): | ||
234 | 2506 | t = "error" | ||
235 | 2507 | s = ( | ||
236 | 2508 | "invalid source mount: '%s' " % source | ||
237 | 2509 | + "(should be a legal path and start with one " | ||
238 | 2510 | + "of: %s" % ", ".join(snap_vars) | ||
239 | 2511 | ) | ||
240 | 2512 | elif ltype == "mode": | ||
241 | 2513 | ltype = "mode" | ||
242 | 2514 | rdata = self.snap_yaml[key][target][ltype] | ||
243 | 2515 | if not isinstance(rdata, int) and not isinstance(rdata, str): | ||
244 | 2516 | t = "error" | ||
245 | 2517 | s = "invalid mode: should be an integer (eg, 0755)" | ||
246 | 2518 | self._add_result(t, n, s) | ||
247 | 2519 | continue | ||
248 | 2520 | |||
249 | 2521 | mode = None | ||
250 | 2522 | if isinstance(rdata, str): | ||
251 | 2523 | try: | ||
252 | 2524 | mode = int(rdata, 8) | ||
253 | 2525 | except Exception: | ||
254 | 2526 | t = "error" | ||
255 | 2527 | s = ( | ||
256 | 2528 | "mode '%s' should be an integer " % rdata | ||
257 | 2529 | + "within 1-777 octal" | ||
258 | 2530 | ) | ||
259 | 2531 | self._add_result(t, n, s) | ||
260 | 2532 | continue | ||
261 | 2533 | else: | ||
262 | 2534 | mode = rdata | ||
263 | 2535 | |||
264 | 2536 | if mode < 0o1 or mode > 0o777: | ||
265 | 2537 | t = "error" | ||
266 | 2538 | s = "mode '%s' must be within 1-777 octal" % format(mode, "o") | ||
267 | 2539 | elif ltype == "type": | ||
268 | 2540 | ltype = "type" | ||
269 | 2541 | rdata = self.snap_yaml[key][target][ltype] | ||
270 | 2542 | if not isinstance(rdata, str): | ||
271 | 2543 | t = "error" | ||
272 | 2544 | s = "invalid %s (not a str)" % ltype | ||
273 | 2545 | self._add_result(t, n, s) | ||
274 | 2546 | continue | ||
275 | 2547 | |||
276 | 2548 | if rdata != "tmpfs": | ||
277 | 2549 | t = "error" | ||
278 | 2550 | s = "invalid type: %s != tmpfs" % rdata | ||
279 | 2551 | elif ltype in ["user", "group"]: | ||
280 | 2552 | rdata = self.snap_yaml[key][target][ltype] | ||
281 | 2553 | if not isinstance(rdata, str): | ||
282 | 2554 | t = "error" | ||
283 | 2555 | s = "invalid %s (not a str)" % ltype | ||
284 | 2556 | self._add_result(t, n, s) | ||
285 | 2557 | continue | ||
286 | 2558 | |||
287 | 2559 | # Don't allow specifying uids | ||
288 | 2560 | try: | ||
289 | 2561 | int(self.snap_yaml[key][target][ltype]) | ||
290 | 2562 | t = "error" | ||
291 | 2563 | s = "invalid %s (should not be a number)" % ltype | ||
292 | 2564 | except Exception: | ||
293 | 2565 | pass | ||
294 | 2566 | |||
295 | 2567 | self._add_result(t, n, s) | ||
296 | 2568 | |||
297 | 2569 | def check_apps_install_mode(self): | 2363 | def check_apps_install_mode(self): |
298 | 2570 | """Check apps - install-mode""" | 2364 | """Check apps - install-mode""" |
299 | 2571 | if "apps" not in self.snap_yaml: | 2365 | if "apps" not in self.snap_yaml: |
300 | diff --git a/reviewtools/tests/schemas/test_schema_snap.py b/reviewtools/tests/schemas/test_schema_snap.py | |||
301 | index beed77e..96484d3 100644 | |||
302 | --- a/reviewtools/tests/schemas/test_schema_snap.py | |||
303 | +++ b/reviewtools/tests/schemas/test_schema_snap.py | |||
304 | @@ -354,3 +354,126 @@ class TestSchemaSnap(TestSchemaBase): | |||
305 | 354 | with self.subTest(value=value): | 354 | with self.subTest(value=value): |
306 | 355 | error = error.replace("{value}", str(value)) if error else error | 355 | error = error.replace("{value}", str(value)) if error else error |
307 | 356 | self._test_value("environment", value, error) | 356 | self._test_value("environment", value, error) |
308 | 357 | |||
309 | 358 | def test_layout(self): | ||
310 | 359 | for value, error in [ | ||
311 | 360 | # test_check_layout | ||
312 | 361 | ( | ||
313 | 362 | { | ||
314 | 363 | "/etc/demo": {"bind": "$SNAP_COMMON/etc/demo"}, | ||
315 | 364 | "/etc/demo.cfg": {"symlink": "$SNAP_COMMON/etc/demo.conf"}, | ||
316 | 365 | "/etc/demo.conf": {"bind-file": "$SNAP_COMMON/etc/demo.conf"}, | ||
317 | 366 | "/opt/demo": {"bind": "$SNAP/opt/demo"}, | ||
318 | 367 | "/usr/share/demo": {"bind": "$SNAP/usr/share/demo"}, | ||
319 | 368 | "/var/cache/demo": {"bind": "$SNAP_DATA/var/cache/demo"}, | ||
320 | 369 | "/var/lib/demo": {"bind": "$SNAP_DATA/var/lib/demo"}, | ||
321 | 370 | "/var/lib/foo": {"type": "tmpfs", "mode": 0o755}, | ||
322 | 371 | "/var/lib/bar": { | ||
323 | 372 | "type": "tmpfs", | ||
324 | 373 | "user": "username", | ||
325 | 374 | "group": "groupname", | ||
326 | 375 | "mode": 0o755, | ||
327 | 376 | }, | ||
328 | 377 | }, | ||
329 | 378 | None, | ||
330 | 379 | ), | ||
331 | 380 | # test_check_layout_bad - list | ||
332 | 381 | ([], "{value} is not of type 'object'"), | ||
333 | 382 | # test_check_layout_empty | ||
334 | 383 | ({}, "{value} does not have enough properties"), | ||
335 | 384 | # test_check_layout_source_target_use_snap_vars - source/target use $SNAP | ||
336 | 385 | ({"$SNAP/db": {"bind": "$SNAP_DATA/db"}}, None), | ||
337 | 386 | # test_check_layout_target_bad_snap_var - bad target (SNAP_USER_COMMON) | ||
338 | 387 | ( | ||
339 | 388 | {"$SNAP_USER_COMMON/db": {"bind": "$SNAP_DATA/db"}}, | ||
340 | 389 | "'$SNAP_USER_COMMON/db' does not match ", | ||
341 | 390 | ), | ||
342 | 391 | # test_check_layout_target_bad_val - bad target (list) | ||
343 | 392 | ({"/etc/demo": []}, "[] is not of type 'object'"), | ||
344 | 393 | # test_check_layout_target_bad_empty | ||
345 | 394 | ({"/etc/demo": {}}, "{} does not have enough properties"), | ||
346 | 395 | # test_check_layout_target_bad_too_many | ||
347 | 396 | ( | ||
348 | 397 | dict.fromkeys(["/a/%s" % i for i in range(101)], {"bind": "$SNAP/db"}), | ||
349 | 398 | "{value} has too many properties", | ||
350 | 399 | ), | ||
351 | 400 | # test_check_layout_target_bad - bad target (normpath) | ||
352 | 401 | ( | ||
353 | 402 | {"/etc/../demo": {"bind": "$SNAP_COMMON/etc/demo"}}, | ||
354 | 403 | "'/etc/../demo' does not match ", | ||
355 | 404 | ), | ||
356 | 405 | # test_check_layout_target_bad_prefix - bad target (prefix) | ||
357 | 406 | ( | ||
358 | 407 | {"/proc/cmdline": {"bind": "$SNAP_COMMON/etc/demo"}}, | ||
359 | 408 | " is not allowed for '/proc/cmdline'", | ||
360 | 409 | ), | ||
361 | 410 | ( | ||
362 | 411 | {"/lib/firmware/foo": {"bind": "$SNAP_COMMON/etc/demo"}}, | ||
363 | 412 | "is not allowed for '/lib/firmware/foo'", | ||
364 | 413 | ), | ||
365 | 414 | ( | ||
366 | 415 | {"/usr/lib/firmware": {"bind": "$SNAP_COMMON/etc/demo"}}, | ||
367 | 416 | "is not allowed for '/usr/lib/firmware'", | ||
368 | 417 | ), | ||
369 | 418 | ( | ||
370 | 419 | {"/run": {"bind": "$SNAP_COMMON/etc/demo"}}, | ||
371 | 420 | "is not allowed for '/run'", | ||
372 | 421 | ), | ||
373 | 422 | ( | ||
374 | 423 | {"/var/run": {"bind": "$SNAP_COMMON/etc/demo"}}, | ||
375 | 424 | "is not allowed for '/var/run'", | ||
376 | 425 | ), | ||
377 | 426 | # test_check_layout_source_bad_prefix - bad source (prefix) | ||
378 | 427 | ( | ||
379 | 428 | {"/etc/demo": {"bind": "/bad/etc/demo"}}, | ||
380 | 429 | "'/bad/etc/demo' does not match ", | ||
381 | 430 | ), | ||
382 | 431 | # test_check_layout_source_bad_prefix_home - bad source (prefix $HOME) | ||
383 | 432 | ( | ||
384 | 433 | {"/var/tmp/other": {"bind": "$HOME/snap/other"}}, | ||
385 | 434 | "'$HOME/snap/other' does not match ", | ||
386 | 435 | ), | ||
387 | 436 | # test_check_layout_source_bad_val - bad source (list) | ||
388 | 437 | ({"/etc/demo": {"bind": []}}, "[] is not of type 'string'"), | ||
389 | 438 | # test_check_layout_source_bad - bad source (normpath) | ||
390 | 439 | ( | ||
391 | 440 | {"/etc/demo": {"bind": "$SNAP_COMMON/etc/../demo"}}, | ||
392 | 441 | "'$SNAP_COMMON/etc/../demo' does not match", | ||
393 | 442 | ), | ||
394 | 443 | # test_check_layout_source_bad_type - bad source (type) | ||
395 | 444 | ( | ||
396 | 445 | {"/etc/demo": {"nonexistent": "$SNAP_COMMON/etc/demo"}}, | ||
397 | 446 | "'nonexistent' does not match any of the regexes: ", | ||
398 | 447 | ), | ||
399 | 448 | # test_check_layout_mode_bad | ||
400 | 449 | ( | ||
401 | 450 | {"/var/lib/foo": {"type": "tmpfs", "mode": []}}, | ||
402 | 451 | "[] is not of type 'integer'", | ||
403 | 452 | ), | ||
404 | 453 | # test_check_layout_mode_range - mode range TODO: can we limit it to integers? why no 0? | ||
405 | 454 | ( | ||
406 | 455 | {"/var/lib/foo": {"type": "tmpfs", "mode": 0}}, | ||
407 | 456 | "0 is less than the minimum of 1", | ||
408 | 457 | ), | ||
409 | 458 | ( | ||
410 | 459 | {"/var/lib/foo": {"type": "tmpfs", "mode": 512}}, | ||
411 | 460 | "512 is greater than the maximum of 511", | ||
412 | 461 | ), | ||
413 | 462 | ( | ||
414 | 463 | {"/var/lib/foo": {"type": "tmpfs", "mode": "778"}}, | ||
415 | 464 | "'778' is not of type 'integer'", | ||
416 | 465 | ), | ||
417 | 466 | # test_check_layout_type_bad | ||
418 | 467 | ({"/var/lib/foo": {"type": []}}, "[] is not of type 'string'"), | ||
419 | 468 | # test_check_layout_type_nonexistent | ||
420 | 469 | ({"/var/lib/foo": {"type": "nonexistent"}}, "'nonexistent' is not one of "), | ||
421 | 470 | # test_check_layout_user_bad | ||
422 | 471 | ({"/var/lib/foo": {"user": []}}, "[] is not of type 'string'"), | ||
423 | 472 | # test_check_layout_user_invalid | ||
424 | 473 | ({"/var/lib/foo": {"user": "0"}}, " is not allowed for '0'"), | ||
425 | 474 | # test_check_layout_group_bad | ||
426 | 475 | ({"/var/lib/foo": {"group": []}}, "[] is not of type 'string'"), | ||
427 | 476 | ]: | ||
428 | 477 | with self.subTest(value=value): | ||
429 | 478 | error = error.replace("{value}", str(value)) if error else error | ||
430 | 479 | self._test_value("layout", value, error) | ||
431 | diff --git a/reviewtools/tests/test_sr_lint.py b/reviewtools/tests/test_sr_lint.py | |||
432 | index 44f88df..14d0a54 100644 | |||
433 | --- a/reviewtools/tests/test_sr_lint.py | |||
434 | +++ b/reviewtools/tests/test_sr_lint.py | |||
435 | @@ -4448,352 +4448,6 @@ class TestSnapReviewLint(sr_tests.TestSnapReview): | |||
436 | 4448 | expected_counts = {"info": None, "warn": 0, "error": 1} | 4448 | expected_counts = {"info": None, "warn": 0, "error": 1} |
437 | 4449 | self.check_results(r, expected_counts) | 4449 | self.check_results(r, expected_counts) |
438 | 4450 | 4450 | ||
439 | 4451 | def test_check_layout(self): | ||
440 | 4452 | """Test check_layout()""" | ||
441 | 4453 | self.set_test_snap_yaml( | ||
442 | 4454 | "layout", | ||
443 | 4455 | { | ||
444 | 4456 | "/etc/demo": {"bind": "$SNAP_COMMON/etc/demo"}, | ||
445 | 4457 | "/etc/demo.cfg": {"symlink": "$SNAP_COMMON/etc/demo.conf"}, | ||
446 | 4458 | "/etc/demo.conf": {"bind-file": "$SNAP_COMMON/etc/demo.conf"}, | ||
447 | 4459 | "/opt/demo": {"bind": "$SNAP/opt/demo"}, | ||
448 | 4460 | "/usr/share/demo": {"bind": "$SNAP/usr/share/demo"}, | ||
449 | 4461 | "/var/cache/demo": {"bind": "$SNAP_DATA/var/cache/demo"}, | ||
450 | 4462 | "/var/lib/demo": {"bind": "$SNAP_DATA/var/lib/demo"}, | ||
451 | 4463 | "/var/lib/foo": {"type": "tmpfs", "mode": "755"}, | ||
452 | 4464 | "/var/lib/bar": { | ||
453 | 4465 | "type": "tmpfs", | ||
454 | 4466 | "user": "username", | ||
455 | 4467 | "group": "groupname", | ||
456 | 4468 | "mode": "0755", | ||
457 | 4469 | }, | ||
458 | 4470 | }, | ||
459 | 4471 | ) | ||
460 | 4472 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
461 | 4473 | c.check_layout() | ||
462 | 4474 | r = c.review_report | ||
463 | 4475 | expected_counts = {"info": 23, "warn": 0, "error": 0} | ||
464 | 4476 | self.check_results(r, expected_counts) | ||
465 | 4477 | |||
466 | 4478 | def test_check_layout_bad(self): | ||
467 | 4479 | """Test check_layout() - bad (list)""" | ||
468 | 4480 | self.set_test_snap_yaml("layout", []) | ||
469 | 4481 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
470 | 4482 | c.check_layout() | ||
471 | 4483 | r = c.review_report | ||
472 | 4484 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
473 | 4485 | self.check_results(r, expected_counts) | ||
474 | 4486 | |||
475 | 4487 | def test_check_layout_empty(self): | ||
476 | 4488 | """Test check_layout() - bad (empty)""" | ||
477 | 4489 | self.set_test_snap_yaml("layout", {}) | ||
478 | 4490 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
479 | 4491 | c.check_layout() | ||
480 | 4492 | r = c.review_report | ||
481 | 4493 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
482 | 4494 | self.check_results(r, expected_counts) | ||
483 | 4495 | |||
484 | 4496 | def test_check_layout_source_target_use_snap_vars(self): | ||
485 | 4497 | """Test check_layout() - source/target use $SNAP...""" | ||
486 | 4498 | self.set_test_snap_yaml("layout", {"$SNAP/db": {"bind": "$SNAP_DATA/db"}}) | ||
487 | 4499 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
488 | 4500 | c.check_layout() | ||
489 | 4501 | r = c.review_report | ||
490 | 4502 | expected_counts = {"info": 3, "warn": 0, "error": 0} | ||
491 | 4503 | self.check_results(r, expected_counts) | ||
492 | 4504 | |||
493 | 4505 | def test_check_layout_target_bad_snap_var(self): | ||
494 | 4506 | """Test check_layout() - bad target (SNAP_USER_COMMON)""" | ||
495 | 4507 | self.set_test_snap_yaml( | ||
496 | 4508 | "layout", {"$SNAP_USER_COMMON/db": {"bind": "$SNAP_DATA/db"}} | ||
497 | 4509 | ) | ||
498 | 4510 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
499 | 4511 | c.check_layout() | ||
500 | 4512 | r = c.review_report | ||
501 | 4513 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
502 | 4514 | self.check_results(r, expected_counts) | ||
503 | 4515 | |||
504 | 4516 | def test_check_layout_target_bad_val(self): | ||
505 | 4517 | """Test check_layout() - bad target (list)""" | ||
506 | 4518 | self.set_test_snap_yaml("layout", {"/etc/demo": []}) | ||
507 | 4519 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
508 | 4520 | c.check_layout() | ||
509 | 4521 | r = c.review_report | ||
510 | 4522 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
511 | 4523 | self.check_results(r, expected_counts) | ||
512 | 4524 | |||
513 | 4525 | def test_check_layout_target_bad_empty(self): | ||
514 | 4526 | """Test check_layout() - bad target (empty)""" | ||
515 | 4527 | self.set_test_snap_yaml("layout", {"/etc/demo": {}}) | ||
516 | 4528 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
517 | 4529 | c.check_layout() | ||
518 | 4530 | r = c.review_report | ||
519 | 4531 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
520 | 4532 | self.check_results(r, expected_counts) | ||
521 | 4533 | |||
522 | 4534 | def test_check_layout_target_bad_too_many(self): | ||
523 | 4535 | """Test check_layout() - bad target (too many)""" | ||
524 | 4536 | self.set_test_snap_yaml( | ||
525 | 4537 | "layout", | ||
526 | 4538 | { | ||
527 | 4539 | "/a/1": {"bind": "$SNAP/1"}, | ||
528 | 4540 | "/a/2": {"bind": "$SNAP/2"}, | ||
529 | 4541 | "/a/3": {"bind": "$SNAP/3"}, | ||
530 | 4542 | "/a/4": {"bind": "$SNAP/4"}, | ||
531 | 4543 | "/a/5": {"bind": "$SNAP/5"}, | ||
532 | 4544 | "/a/6": {"bind": "$SNAP/6"}, | ||
533 | 4545 | "/a/7": {"bind": "$SNAP/7"}, | ||
534 | 4546 | "/a/8": {"bind": "$SNAP/8"}, | ||
535 | 4547 | "/a/9": {"bind": "$SNAP/9"}, | ||
536 | 4548 | "/a/10": {"bind": "$SNAP/10"}, | ||
537 | 4549 | "/a/11": {"bind": "$SNAP/11"}, | ||
538 | 4550 | "/a/12": {"bind": "$SNAP/12"}, | ||
539 | 4551 | "/a/13": {"bind": "$SNAP/13"}, | ||
540 | 4552 | "/a/14": {"bind": "$SNAP/14"}, | ||
541 | 4553 | "/a/15": {"bind": "$SNAP/15"}, | ||
542 | 4554 | "/a/16": {"bind": "$SNAP/16"}, | ||
543 | 4555 | "/a/17": {"bind": "$SNAP/17"}, | ||
544 | 4556 | "/a/18": {"bind": "$SNAP/19"}, | ||
545 | 4557 | "/a/19": {"bind": "$SNAP/19"}, | ||
546 | 4558 | "/a/20": {"bind": "$SNAP/20"}, | ||
547 | 4559 | "/a/21": {"bind": "$SNAP/21"}, | ||
548 | 4560 | "/a/22": {"bind": "$SNAP/22"}, | ||
549 | 4561 | "/a/23": {"bind": "$SNAP/23"}, | ||
550 | 4562 | "/a/24": {"bind": "$SNAP/24"}, | ||
551 | 4563 | "/a/25": {"bind": "$SNAP/25"}, | ||
552 | 4564 | "/a/26": {"bind": "$SNAP/26"}, | ||
553 | 4565 | "/a/27": {"bind": "$SNAP/27"}, | ||
554 | 4566 | "/a/28": {"bind": "$SNAP/28"}, | ||
555 | 4567 | "/a/29": {"bind": "$SNAP/29"}, | ||
556 | 4568 | "/a/30": {"bind": "$SNAP/30"}, | ||
557 | 4569 | "/a/31": {"bind": "$SNAP/31"}, | ||
558 | 4570 | "/a/32": {"bind": "$SNAP/32"}, | ||
559 | 4571 | "/a/33": {"bind": "$SNAP/33"}, | ||
560 | 4572 | "/a/34": {"bind": "$SNAP/34"}, | ||
561 | 4573 | "/a/35": {"bind": "$SNAP/35"}, | ||
562 | 4574 | "/a/36": {"bind": "$SNAP/36"}, | ||
563 | 4575 | "/a/37": {"bind": "$SNAP/37"}, | ||
564 | 4576 | "/a/38": {"bind": "$SNAP/38"}, | ||
565 | 4577 | "/a/39": {"bind": "$SNAP/39"}, | ||
566 | 4578 | "/a/40": {"bind": "$SNAP/40"}, | ||
567 | 4579 | "/a/41": {"bind": "$SNAP/41"}, | ||
568 | 4580 | "/a/42": {"bind": "$SNAP/42"}, | ||
569 | 4581 | "/a/43": {"bind": "$SNAP/43"}, | ||
570 | 4582 | "/a/44": {"bind": "$SNAP/44"}, | ||
571 | 4583 | "/a/45": {"bind": "$SNAP/45"}, | ||
572 | 4584 | "/a/46": {"bind": "$SNAP/46"}, | ||
573 | 4585 | "/a/47": {"bind": "$SNAP/47"}, | ||
574 | 4586 | "/a/48": {"bind": "$SNAP/48"}, | ||
575 | 4587 | "/a/49": {"bind": "$SNAP/49"}, | ||
576 | 4588 | "/a/50": {"bind": "$SNAP/50"}, | ||
577 | 4589 | "/a/51": {"bind": "$SNAP/51"}, | ||
578 | 4590 | "/a/52": {"bind": "$SNAP/52"}, | ||
579 | 4591 | "/a/53": {"bind": "$SNAP/53"}, | ||
580 | 4592 | "/a/54": {"bind": "$SNAP/54"}, | ||
581 | 4593 | "/a/55": {"bind": "$SNAP/55"}, | ||
582 | 4594 | "/a/56": {"bind": "$SNAP/56"}, | ||
583 | 4595 | "/a/57": {"bind": "$SNAP/57"}, | ||
584 | 4596 | "/a/58": {"bind": "$SNAP/58"}, | ||
585 | 4597 | "/a/59": {"bind": "$SNAP/59"}, | ||
586 | 4598 | "/a/60": {"bind": "$SNAP/60"}, | ||
587 | 4599 | "/a/61": {"bind": "$SNAP/61"}, | ||
588 | 4600 | "/a/62": {"bind": "$SNAP/62"}, | ||
589 | 4601 | "/a/63": {"bind": "$SNAP/63"}, | ||
590 | 4602 | "/a/64": {"bind": "$SNAP/64"}, | ||
591 | 4603 | "/a/65": {"bind": "$SNAP/65"}, | ||
592 | 4604 | "/a/66": {"bind": "$SNAP/66"}, | ||
593 | 4605 | "/a/67": {"bind": "$SNAP/67"}, | ||
594 | 4606 | "/a/68": {"bind": "$SNAP/68"}, | ||
595 | 4607 | "/a/69": {"bind": "$SNAP/69"}, | ||
596 | 4608 | "/a/70": {"bind": "$SNAP/70"}, | ||
597 | 4609 | "/a/71": {"bind": "$SNAP/71"}, | ||
598 | 4610 | "/a/72": {"bind": "$SNAP/72"}, | ||
599 | 4611 | "/a/73": {"bind": "$SNAP/73"}, | ||
600 | 4612 | "/a/74": {"bind": "$SNAP/74"}, | ||
601 | 4613 | "/a/75": {"bind": "$SNAP/75"}, | ||
602 | 4614 | "/a/76": {"bind": "$SNAP/76"}, | ||
603 | 4615 | "/a/77": {"bind": "$SNAP/77"}, | ||
604 | 4616 | "/a/78": {"bind": "$SNAP/78"}, | ||
605 | 4617 | "/a/79": {"bind": "$SNAP/79"}, | ||
606 | 4618 | "/a/80": {"bind": "$SNAP/80"}, | ||
607 | 4619 | "/a/81": {"bind": "$SNAP/81"}, | ||
608 | 4620 | "/a/82": {"bind": "$SNAP/82"}, | ||
609 | 4621 | "/a/83": {"bind": "$SNAP/83"}, | ||
610 | 4622 | "/a/84": {"bind": "$SNAP/84"}, | ||
611 | 4623 | "/a/85": {"bind": "$SNAP/85"}, | ||
612 | 4624 | "/a/86": {"bind": "$SNAP/86"}, | ||
613 | 4625 | "/a/87": {"bind": "$SNAP/87"}, | ||
614 | 4626 | "/a/88": {"bind": "$SNAP/88"}, | ||
615 | 4627 | "/a/89": {"bind": "$SNAP/89"}, | ||
616 | 4628 | "/a/90": {"bind": "$SNAP/90"}, | ||
617 | 4629 | "/a/91": {"bind": "$SNAP/91"}, | ||
618 | 4630 | "/a/92": {"bind": "$SNAP/92"}, | ||
619 | 4631 | "/a/93": {"bind": "$SNAP/93"}, | ||
620 | 4632 | "/a/94": {"bind": "$SNAP/94"}, | ||
621 | 4633 | "/a/95": {"bind": "$SNAP/95"}, | ||
622 | 4634 | "/a/96": {"bind": "$SNAP/96"}, | ||
623 | 4635 | "/a/97": {"bind": "$SNAP/97"}, | ||
624 | 4636 | "/a/98": {"bind": "$SNAP/98"}, | ||
625 | 4637 | "/a/99": {"bind": "$SNAP/99"}, | ||
626 | 4638 | "/a/100": {"bind": "$SNAP/100"}, | ||
627 | 4639 | "/a/101": {"bind": "$SNAP/101"}, | ||
628 | 4640 | }, | ||
629 | 4641 | ) | ||
630 | 4642 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
631 | 4643 | c.check_layout() | ||
632 | 4644 | r = c.review_report | ||
633 | 4645 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
634 | 4646 | self.check_results(r, expected_counts) | ||
635 | 4647 | |||
636 | 4648 | def test_check_layout_target_bad(self): | ||
637 | 4649 | """Test check_layout() - bad target (normpath)""" | ||
638 | 4650 | self.set_test_snap_yaml( | ||
639 | 4651 | "layout", {"/etc/../demo": {"bind": "$SNAP_COMMON/etc/demo"}} | ||
640 | 4652 | ) | ||
641 | 4653 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
642 | 4654 | c.check_layout() | ||
643 | 4655 | r = c.review_report | ||
644 | 4656 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
645 | 4657 | self.check_results(r, expected_counts) | ||
646 | 4658 | |||
647 | 4659 | def test_check_layout_target_bad_prefix(self): | ||
648 | 4660 | """Test check_layout() - bad target (prefix)""" | ||
649 | 4661 | for prefix in [ | ||
650 | 4662 | "/proc/cmdline", | ||
651 | 4663 | "/lib/firmware/foo", | ||
652 | 4664 | "/usr/lib/firmware", | ||
653 | 4665 | "/run", | ||
654 | 4666 | "/var/run", | ||
655 | 4667 | ]: | ||
656 | 4668 | self.set_test_snap_yaml("layout", {prefix: {"bind": "$SNAP/etc/demo"}}) | ||
657 | 4669 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
658 | 4670 | c.check_layout() | ||
659 | 4671 | r = c.review_report | ||
660 | 4672 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
661 | 4673 | self.check_results(r, expected_counts) | ||
662 | 4674 | |||
663 | 4675 | def test_check_layout_source_bad_prefix(self): | ||
664 | 4676 | """Test check_layout() - bad source (prefix)""" | ||
665 | 4677 | self.set_test_snap_yaml("layout", {"/etc/demo": {"bind": "/bad/etc/demo"}}) | ||
666 | 4678 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
667 | 4679 | c.check_layout() | ||
668 | 4680 | r = c.review_report | ||
669 | 4681 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
670 | 4682 | self.check_results(r, expected_counts) | ||
671 | 4683 | |||
672 | 4684 | def test_check_layout_source_bad_prefix_home(self): | ||
673 | 4685 | """Test check_layout() - bad source (prefix $HOME)""" | ||
674 | 4686 | self.set_test_snap_yaml( | ||
675 | 4687 | "layout", {"/var/tmp/other": {"bind": "$HOME/snap/other"}} | ||
676 | 4688 | ) | ||
677 | 4689 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
678 | 4690 | c.check_layout() | ||
679 | 4691 | r = c.review_report | ||
680 | 4692 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
681 | 4693 | self.check_results(r, expected_counts) | ||
682 | 4694 | |||
683 | 4695 | def test_check_layout_source_bad_val(self): | ||
684 | 4696 | """Test check_layout() - bad source (list)""" | ||
685 | 4697 | self.set_test_snap_yaml("layout", {"/etc/demo": {"bind": []}}) | ||
686 | 4698 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
687 | 4699 | c.check_layout() | ||
688 | 4700 | r = c.review_report | ||
689 | 4701 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
690 | 4702 | self.check_results(r, expected_counts) | ||
691 | 4703 | |||
692 | 4704 | def test_check_layout_source_bad(self): | ||
693 | 4705 | """Test check_layout() - bad source (normpath)""" | ||
694 | 4706 | self.set_test_snap_yaml( | ||
695 | 4707 | "layout", {"/etc/demo": {"bind": "$SNAP_COMMON/etc/../demo"}} | ||
696 | 4708 | ) | ||
697 | 4709 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
698 | 4710 | c.check_layout() | ||
699 | 4711 | r = c.review_report | ||
700 | 4712 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
701 | 4713 | self.check_results(r, expected_counts) | ||
702 | 4714 | |||
703 | 4715 | def test_check_layout_source_bad_type(self): | ||
704 | 4716 | """Test check_layout() - bad source (type)""" | ||
705 | 4717 | self.set_test_snap_yaml( | ||
706 | 4718 | "layout", {"/etc/demo": {"nonexistent": "$SNAP_COMMON/etc/demo"}} | ||
707 | 4719 | ) | ||
708 | 4720 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
709 | 4721 | c.check_layout() | ||
710 | 4722 | r = c.review_report | ||
711 | 4723 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
712 | 4724 | self.check_results(r, expected_counts) | ||
713 | 4725 | |||
714 | 4726 | def test_check_layout_mode_bad(self): | ||
715 | 4727 | """Test check_layout() - mode bad""" | ||
716 | 4728 | self.set_test_snap_yaml( | ||
717 | 4729 | "layout", {"/var/lib/foo": {"type": "tmpfs", "mode": []}} | ||
718 | 4730 | ) | ||
719 | 4731 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
720 | 4732 | c.check_layout() | ||
721 | 4733 | r = c.review_report | ||
722 | 4734 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
723 | 4735 | self.check_results(r, expected_counts) | ||
724 | 4736 | |||
725 | 4737 | def test_check_layout_mode_range(self): | ||
726 | 4738 | """Test check_layout() - mode range""" | ||
727 | 4739 | self.set_test_snap_yaml( | ||
728 | 4740 | "layout", | ||
729 | 4741 | { | ||
730 | 4742 | "/var/lib/foo": {"type": "tmpfs", "mode": 0}, | ||
731 | 4743 | "/var/lib/bar": {"type": "tmpfs", "mode": "778"}, | ||
732 | 4744 | }, | ||
733 | 4745 | ) | ||
734 | 4746 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
735 | 4747 | c.check_layout() | ||
736 | 4748 | r = c.review_report | ||
737 | 4749 | expected_counts = {"info": None, "warn": 0, "error": 2} | ||
738 | 4750 | self.check_results(r, expected_counts) | ||
739 | 4751 | |||
740 | 4752 | def test_check_layout_type_bad(self): | ||
741 | 4753 | """Test check_layout() - type bad""" | ||
742 | 4754 | self.set_test_snap_yaml("layout", {"/var/lib/foo": {"type": []}}) | ||
743 | 4755 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
744 | 4756 | c.check_layout() | ||
745 | 4757 | r = c.review_report | ||
746 | 4758 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
747 | 4759 | self.check_results(r, expected_counts) | ||
748 | 4760 | |||
749 | 4761 | def test_check_layout_type_nonexistent(self): | ||
750 | 4762 | """Test check_layout() - type nonexistent""" | ||
751 | 4763 | self.set_test_snap_yaml("layout", {"/var/lib/foo": {"type": "nonexistent"}}) | ||
752 | 4764 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
753 | 4765 | c.check_layout() | ||
754 | 4766 | r = c.review_report | ||
755 | 4767 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
756 | 4768 | self.check_results(r, expected_counts) | ||
757 | 4769 | |||
758 | 4770 | def test_check_layout_user_bad(self): | ||
759 | 4771 | """Test check_layout() - user bad""" | ||
760 | 4772 | self.set_test_snap_yaml("layout", {"/var/lib/foo": {"user": []}}) | ||
761 | 4773 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
762 | 4774 | c.check_layout() | ||
763 | 4775 | r = c.review_report | ||
764 | 4776 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
765 | 4777 | self.check_results(r, expected_counts) | ||
766 | 4778 | |||
767 | 4779 | def test_check_layout_user_invalid(self): | ||
768 | 4780 | """Test check_layout() - user invalid""" | ||
769 | 4781 | self.set_test_snap_yaml("layout", {"/var/lib/foo": {"user": "0"}}) | ||
770 | 4782 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
771 | 4783 | c.check_layout() | ||
772 | 4784 | r = c.review_report | ||
773 | 4785 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
774 | 4786 | self.check_results(r, expected_counts) | ||
775 | 4787 | |||
776 | 4788 | def test_check_layout_group_bad(self): | ||
777 | 4789 | """Test check_layout() - group bad""" | ||
778 | 4790 | self.set_test_snap_yaml("layout", {"/var/lib/foo": {"group": []}}) | ||
779 | 4791 | c = SnapReviewLint(SnapContainer(self.test_name)) | ||
780 | 4792 | c.check_layout() | ||
781 | 4793 | r = c.review_report | ||
782 | 4794 | expected_counts = {"info": None, "warn": 0, "error": 1} | ||
783 | 4795 | self.check_results(r, expected_counts) | ||
784 | 4796 | |||
785 | 4797 | def test_check_apps_install_mode(self): | 4451 | def test_check_apps_install_mode(self): |
786 | 4798 | """Test check_apps_install_mode()""" | 4452 | """Test check_apps_install_mode()""" |
787 | 4799 | self.set_test_snap_yaml("apps", {"foo": {"install-mode": "enable"}}) | 4453 | self.set_test_snap_yaml("apps", {"foo": {"install-mode": "enable"}}) |
788 | diff --git a/tests/test.sh.expected b/tests/test.sh.expected | |||
789 | index 7e394ec..e74cc2c 100644 | |||
790 | --- a/tests/test.sh.expected | |||
791 | +++ b/tests/test.sh.expected | |||
792 | @@ -4852,18 +4852,6 @@ nix-example-jormungandr_f7xva0vh9fzv20vhyr121yd6ahplqh9v_amd64.snap: pass | |||
793 | 4852 | "manual_review": false, | 4852 | "manual_review": false, |
794 | 4853 | "text": "OK" | 4853 | "text": "OK" |
795 | 4854 | }, | 4854 | }, |
796 | 4855 | "lint-snap-v2:layout": { | ||
797 | 4856 | "manual_review": false, | ||
798 | 4857 | "text": "OK" | ||
799 | 4858 | }, | ||
800 | 4859 | "lint-snap-v2:layout_source:/nix:$SNAP/nix": { | ||
801 | 4860 | "manual_review": false, | ||
802 | 4861 | "text": "OK" | ||
803 | 4862 | }, | ||
804 | 4863 | "lint-snap-v2:layout_target:/nix": { | ||
805 | 4864 | "manual_review": false, | ||
806 | 4865 | "text": "OK" | ||
807 | 4866 | }, | ||
808 | 4867 | "lint-snap-v2:snap_type_redflag": { | 4855 | "lint-snap-v2:snap_type_redflag": { |
809 | 4868 | "manual_review": false, | 4856 | "manual_review": false, |
810 | 4869 | "text": "OK" | 4857 | "text": "OK" |
811 | @@ -5015,18 +5003,6 @@ nix-example-jormungandr_f7xva0vh9fzv20vhyr121yd6ahplqh9v_amd64.snap: pass | |||
812 | 5015 | "manual_review": false, | 5003 | "manual_review": false, |
813 | 5016 | "text": "OK" | 5004 | "text": "OK" |
814 | 5017 | }, | 5005 | }, |
815 | 5018 | "lint-snap-v2:layout": { | ||
816 | 5019 | "manual_review": false, | ||
817 | 5020 | "text": "OK" | ||
818 | 5021 | }, | ||
819 | 5022 | "lint-snap-v2:layout_source:/nix:$SNAP/nix": { | ||
820 | 5023 | "manual_review": false, | ||
821 | 5024 | "text": "OK" | ||
822 | 5025 | }, | ||
823 | 5026 | "lint-snap-v2:layout_target:/nix": { | ||
824 | 5027 | "manual_review": false, | ||
825 | 5028 | "text": "OK" | ||
826 | 5029 | }, | ||
827 | 5030 | "lint-snap-v2:snap_type_redflag": { | 5006 | "lint-snap-v2:snap_type_redflag": { |
828 | 5031 | "manual_review": false, | 5007 | "manual_review": false, |
829 | 5032 | "text": "OK" | 5008 | "text": "OK" |
830 | @@ -5268,18 +5244,6 @@ nix-example_g7qmi8r4qwws6fhwschfb8aib5wl0x1q_amd64.snap: pass | |||
831 | 5268 | "manual_review": false, | 5244 | "manual_review": false, |
832 | 5269 | "text": "OK" | 5245 | "text": "OK" |
833 | 5270 | }, | 5246 | }, |
834 | 5271 | "lint-snap-v2:layout": { | ||
835 | 5272 | "manual_review": false, | ||
836 | 5273 | "text": "OK" | ||
837 | 5274 | }, | ||
838 | 5275 | "lint-snap-v2:layout_source:/nix:$SNAP/nix": { | ||
839 | 5276 | "manual_review": false, | ||
840 | 5277 | "text": "OK" | ||
841 | 5278 | }, | ||
842 | 5279 | "lint-snap-v2:layout_target:/nix": { | ||
843 | 5280 | "manual_review": false, | ||
844 | 5281 | "text": "OK" | ||
845 | 5282 | }, | ||
846 | 5283 | "lint-snap-v2:meta_gui_desktop": { | 5247 | "lint-snap-v2:meta_gui_desktop": { |
847 | 5284 | "manual_review": false, | 5248 | "manual_review": false, |
848 | 5285 | "text": "desktop interfaces (x11) specified without a corresponding meta/gui/*.desktop file. If your application does not require a desktop file, you may ignore this. Otherwise, if using snapcraft, please see https://snapcraft.io/docs/build-snaps/metadata#fixed-assets or provide a desktop file in meta/gui/*.desktop (it should reference one of the 'apps' from your snapcraft/snap.yaml)." | 5249 | "text": "desktop interfaces (x11) specified without a corresponding meta/gui/*.desktop file. If your application does not require a desktop file, you may ignore this. Otherwise, if using snapcraft, please see https://snapcraft.io/docs/build-snaps/metadata#fixed-assets or provide a desktop file in meta/gui/*.desktop (it should reference one of the 'apps' from your snapcraft/snap.yaml)." |
849 | @@ -5516,18 +5480,6 @@ nix-example_g7qmi8r4qwws6fhwschfb8aib5wl0x1q_amd64.snap: pass | |||
850 | 5516 | "manual_review": false, | 5480 | "manual_review": false, |
851 | 5517 | "text": "OK" | 5481 | "text": "OK" |
852 | 5518 | }, | 5482 | }, |
853 | 5519 | "lint-snap-v2:layout": { | ||
854 | 5520 | "manual_review": false, | ||
855 | 5521 | "text": "OK" | ||
856 | 5522 | }, | ||
857 | 5523 | "lint-snap-v2:layout_source:/nix:$SNAP/nix": { | ||
858 | 5524 | "manual_review": false, | ||
859 | 5525 | "text": "OK" | ||
860 | 5526 | }, | ||
861 | 5527 | "lint-snap-v2:layout_target:/nix": { | ||
862 | 5528 | "manual_review": false, | ||
863 | 5529 | "text": "OK" | ||
864 | 5530 | }, | ||
865 | 5531 | "lint-snap-v2:meta_gui_desktop": { | 5483 | "lint-snap-v2:meta_gui_desktop": { |
866 | 5532 | "manual_review": false, | 5484 | "manual_review": false, |
867 | 5533 | "text": "desktop interfaces (x11) specified without a corresponding meta/gui/*.desktop file. If your application does not require a desktop file, you may ignore this. Otherwise, if using snapcraft, please see https://snapcraft.io/docs/build-snaps/metadata#fixed-assets or provide a desktop file in meta/gui/*.desktop (it should reference one of the 'apps' from your snapcraft/snap.yaml)." | 5485 | "text": "desktop interfaces (x11) specified without a corresponding meta/gui/*.desktop file. If your application does not require a desktop file, you may ignore this. Otherwise, if using snapcraft, please see https://snapcraft.io/docs/build-snaps/metadata#fixed-assets or provide a desktop file in meta/gui/*.desktop (it should reference one of the 'apps' from your snapcraft/snap.yaml)." |
868 | @@ -35331,78 +35283,6 @@ test-snapd-layout_1.0_all.snap: pass | |||
869 | 35331 | "manual_review": false, | 35283 | "manual_review": false, |
870 | 35332 | "text": "OK" | 35284 | "text": "OK" |
871 | 35333 | }, | 35285 | }, |
872 | 35334 | "lint-snap-v2:layout": { | ||
873 | 35335 | "manual_review": false, | ||
874 | 35336 | "text": "OK" | ||
875 | 35337 | }, | ||
876 | 35338 | "lint-snap-v2:layout:/opt/foo:mode": { | ||
877 | 35339 | "manual_review": false, | ||
878 | 35340 | "text": "OK" | ||
879 | 35341 | }, | ||
880 | 35342 | "lint-snap-v2:layout:/opt/foo:type": { | ||
881 | 35343 | "manual_review": false, | ||
882 | 35344 | "text": "OK" | ||
883 | 35345 | }, | ||
884 | 35346 | "lint-snap-v2:layout_source:/etc/demo.cfg:$SNAP_COMMON/etc/demo.conf": { | ||
885 | 35347 | "manual_review": false, | ||
886 | 35348 | "text": "OK" | ||
887 | 35349 | }, | ||
888 | 35350 | "lint-snap-v2:layout_source:/etc/demo.conf:$SNAP_COMMON/etc/demo.conf": { | ||
889 | 35351 | "manual_review": false, | ||
890 | 35352 | "text": "OK" | ||
891 | 35353 | }, | ||
892 | 35354 | "lint-snap-v2:layout_source:/etc/demo:$SNAP_COMMON/etc/demo": { | ||
893 | 35355 | "manual_review": false, | ||
894 | 35356 | "text": "OK" | ||
895 | 35357 | }, | ||
896 | 35358 | "lint-snap-v2:layout_source:/opt/demo:$SNAP/opt/demo": { | ||
897 | 35359 | "manual_review": false, | ||
898 | 35360 | "text": "OK" | ||
899 | 35361 | }, | ||
900 | 35362 | "lint-snap-v2:layout_source:/usr/share/demo:$SNAP/usr/share/demo": { | ||
901 | 35363 | "manual_review": false, | ||
902 | 35364 | "text": "OK" | ||
903 | 35365 | }, | ||
904 | 35366 | "lint-snap-v2:layout_source:/var/cache/demo:$SNAP_DATA/var/cache/demo": { | ||
905 | 35367 | "manual_review": false, | ||
906 | 35368 | "text": "OK" | ||
907 | 35369 | }, | ||
908 | 35370 | "lint-snap-v2:layout_source:/var/lib/demo:$SNAP_DATA/var/lib/demo": { | ||
909 | 35371 | "manual_review": false, | ||
910 | 35372 | "text": "OK" | ||
911 | 35373 | }, | ||
912 | 35374 | "lint-snap-v2:layout_target:/etc/demo": { | ||
913 | 35375 | "manual_review": false, | ||
914 | 35376 | "text": "OK" | ||
915 | 35377 | }, | ||
916 | 35378 | "lint-snap-v2:layout_target:/etc/demo.cfg": { | ||
917 | 35379 | "manual_review": false, | ||
918 | 35380 | "text": "OK" | ||
919 | 35381 | }, | ||
920 | 35382 | "lint-snap-v2:layout_target:/etc/demo.conf": { | ||
921 | 35383 | "manual_review": false, | ||
922 | 35384 | "text": "OK" | ||
923 | 35385 | }, | ||
924 | 35386 | "lint-snap-v2:layout_target:/opt/demo": { | ||
925 | 35387 | "manual_review": false, | ||
926 | 35388 | "text": "OK" | ||
927 | 35389 | }, | ||
928 | 35390 | "lint-snap-v2:layout_target:/opt/foo": { | ||
929 | 35391 | "manual_review": false, | ||
930 | 35392 | "text": "OK" | ||
931 | 35393 | }, | ||
932 | 35394 | "lint-snap-v2:layout_target:/usr/share/demo": { | ||
933 | 35395 | "manual_review": false, | ||
934 | 35396 | "text": "OK" | ||
935 | 35397 | }, | ||
936 | 35398 | "lint-snap-v2:layout_target:/var/cache/demo": { | ||
937 | 35399 | "manual_review": false, | ||
938 | 35400 | "text": "OK" | ||
939 | 35401 | }, | ||
940 | 35402 | "lint-snap-v2:layout_target:/var/lib/demo": { | ||
941 | 35403 | "manual_review": false, | ||
942 | 35404 | "text": "OK" | ||
943 | 35405 | }, | ||
944 | 35406 | "lint-snap-v2:snap_type_redflag": { | 35286 | "lint-snap-v2:snap_type_redflag": { |
945 | 35407 | "manual_review": false, | 35287 | "manual_review": false, |
946 | 35408 | "text": "OK" | 35288 | "text": "OK" |
947 | @@ -35522,78 +35402,6 @@ test-snapd-layout_1.0_all.snap: pass | |||
948 | 35522 | "manual_review": false, | 35402 | "manual_review": false, |
949 | 35523 | "text": "OK" | 35403 | "text": "OK" |
950 | 35524 | }, | 35404 | }, |
951 | 35525 | "lint-snap-v2:layout": { | ||
952 | 35526 | "manual_review": false, | ||
953 | 35527 | "text": "OK" | ||
954 | 35528 | }, | ||
955 | 35529 | "lint-snap-v2:layout:/opt/foo:mode": { | ||
956 | 35530 | "manual_review": false, | ||
957 | 35531 | "text": "OK" | ||
958 | 35532 | }, | ||
959 | 35533 | "lint-snap-v2:layout:/opt/foo:type": { | ||
960 | 35534 | "manual_review": false, | ||
961 | 35535 | "text": "OK" | ||
962 | 35536 | }, | ||
963 | 35537 | "lint-snap-v2:layout_source:/etc/demo.cfg:$SNAP_COMMON/etc/demo.conf": { | ||
964 | 35538 | "manual_review": false, | ||
965 | 35539 | "text": "OK" | ||
966 | 35540 | }, | ||
967 | 35541 | "lint-snap-v2:layout_source:/etc/demo.conf:$SNAP_COMMON/etc/demo.conf": { | ||
968 | 35542 | "manual_review": false, | ||
969 | 35543 | "text": "OK" | ||
970 | 35544 | }, | ||
971 | 35545 | "lint-snap-v2:layout_source:/etc/demo:$SNAP_COMMON/etc/demo": { | ||
972 | 35546 | "manual_review": false, | ||
973 | 35547 | "text": "OK" | ||
974 | 35548 | }, | ||
975 | 35549 | "lint-snap-v2:layout_source:/opt/demo:$SNAP/opt/demo": { | ||
976 | 35550 | "manual_review": false, | ||
977 | 35551 | "text": "OK" | ||
978 | 35552 | }, | ||
979 | 35553 | "lint-snap-v2:layout_source:/usr/share/demo:$SNAP/usr/share/demo": { | ||
980 | 35554 | "manual_review": false, | ||
981 | 35555 | "text": "OK" | ||
982 | 35556 | }, | ||
983 | 35557 | "lint-snap-v2:layout_source:/var/cache/demo:$SNAP_DATA/var/cache/demo": { | ||
984 | 35558 | "manual_review": false, | ||
985 | 35559 | "text": "OK" | ||
986 | 35560 | }, | ||
987 | 35561 | "lint-snap-v2:layout_source:/var/lib/demo:$SNAP_DATA/var/lib/demo": { | ||
988 | 35562 | "manual_review": false, | ||
989 | 35563 | "text": "OK" | ||
990 | 35564 | }, | ||
991 | 35565 | "lint-snap-v2:layout_target:/etc/demo": { | ||
992 | 35566 | "manual_review": false, | ||
993 | 35567 | "text": "OK" | ||
994 | 35568 | }, | ||
995 | 35569 | "lint-snap-v2:layout_target:/etc/demo.cfg": { | ||
996 | 35570 | "manual_review": false, | ||
997 | 35571 | "text": "OK" | ||
998 | 35572 | }, | ||
999 | 35573 | "lint-snap-v2:layout_target:/etc/demo.conf": { | ||
1000 | 35574 | "manual_review": false, | ||
1001 | 35575 | "text": "OK" | ||
1002 | 35576 | }, | ||
1003 | 35577 | "lint-snap-v2:layout_target:/opt/demo": { | ||
1004 | 35578 | "manual_review": false, | ||
1005 | 35579 | "text": "OK" | ||
1006 | 35580 | }, | ||
1007 | 35581 | "lint-snap-v2:layout_target:/opt/foo": { | ||
1008 | 35582 | "manual_review": false, | ||
1009 | 35583 | "text": "OK" | ||
1010 | 35584 | }, | ||
1011 | 35585 | "lint-snap-v2:layout_target:/usr/share/demo": { | ||
1012 | 35586 | "manual_review": false, | ||
1013 | 35587 | "text": "OK" | ||
1014 | 35588 | }, | ||
1015 | 35589 | "lint-snap-v2:layout_target:/var/cache/demo": { | ||
1016 | 35590 | "manual_review": false, | ||
1017 | 35591 | "text": "OK" | ||
1018 | 35592 | }, | ||
1019 | 35593 | "lint-snap-v2:layout_target:/var/lib/demo": { | ||
1020 | 35594 | "manual_review": false, | ||
1021 | 35595 | "text": "OK" | ||
1022 | 35596 | }, | ||
1023 | 35597 | "lint-snap-v2:snap_type_redflag": { | 35405 | "lint-snap-v2:snap_type_redflag": { |
1024 | 35598 | "manual_review": false, | 35406 | "manual_review": false, |
1025 | 35599 | "text": "OK" | 35407 | "text": "OK" |
reviewtools/ tests/schemas/ test_schema_ against_ store.py validates the current snap.yaml schema against all snaps in the store. No additional errors have been found in this version.