Merge lp:~jdstrand/click-reviewers-tools/lp1346481 into lp:click-reviewers-tools

Proposed by Jamie Strandboge
Status: Merged
Merged at revision: 213
Proposed branch: lp:~jdstrand/click-reviewers-tools/lp1346481
Merge into: lp:click-reviewers-tools
Diff against target: 790 lines (+539/-17)
13 files modified
bin/click-check-push-helper (+31/-0)
bin/click-run-checks (+4/-0)
bin/click-show-files (+13/-0)
clickreviews/cr_common.py (+2/-1)
clickreviews/cr_desktop.py (+5/-1)
clickreviews/cr_lint.py (+15/-5)
clickreviews/cr_push_helper.py (+132/-0)
clickreviews/cr_security.py (+44/-4)
clickreviews/cr_tests.py (+43/-1)
clickreviews/tests/test_cr_lint.py (+26/-4)
clickreviews/tests/test_cr_push_helper.py (+138/-0)
clickreviews/tests/test_cr_security.py (+84/-0)
debian/changelog (+2/-1)
To merge this branch: bzr merge lp:~jdstrand/click-reviewers-tools/lp1346481
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Martin Albisetti (community) Approve
Review via email: mp+228187@code.launchpad.net

Description of the change

add push-helper checks:
  - add bin/click-check-push-helper
  - add clickreviews/cr_push_helper.py
  - add clickreviews/tests/test_cr_push_helper.py
  - update bin/click-show-files
  - update bin/click-run-checks
  - update clickreviews/cr_tests.py

  clickreviews/cr_desktop.py:
  - skip missing desktop hook with push-helper
  - comment out noisy msg()

  clickreviews/cr_lint.py:
  - add push-helper as known hook
  - allow multiple apps in click, but not multiple desktop apps
  - clarify check_hooks() error

  clickreviews/tests/test_cr_lint.py: adjust for above

  clickreviews/cr_security.py:
  - add template tests for push-helper
  - add policy_groups tests for push-helper
  - clarify check_policy_groups() output

  clickreviews/tests/test_cr_security.py: adjust for above

  clickreviews/cr_common.py: fix pep8 error from merge from trunk

To post a comment you must log in.
226. By Jamie Strandboge

merge with trunk:
[ Daniel Holbach ]
refer to documentation about click in case we encounter .deb packages.

227. By Jamie Strandboge

clickreviews/cr_common.py: fix pep8 error

Revision history for this message
John Lenton (chipaca) wrote :

I haven't been able to go through the tests' tests yet, but have some nitpicks inline below.

Revision history for this message
Martin Albisetti (beuno) wrote :

312 + if 'push-helper' not in self.manifest['hooks'][app]:
313 + # self._add_result(t, n, s)
314 + continue

Why the commenting out?
(the same a few lines lower)

LGTM otherwise.

review: Approve
228. By Jamie Strandboge

clickreviews/cr_security.py: remove confusing comment from
check_template_push_helpers()

229. By Jamie Strandboge

clickreviews/cr_security.py: remove confusing comment from
 check_policy_groups_push_helpers()

Revision history for this message
Jamie Strandboge (jdstrand) wrote :

> 312 + if 'push-helper' not in self.manifest['hooks'][app]:
> 313 + # self._add_result(t, n, s)
> 314 + continue
>
> Why the commenting out?
> (the same a few lines lower)
>
Ah, these should have been omitted from the commit. Fixed. (There is no reason to run this test if the app doesn't specify a push-helper hook).

>
> LGTM otherwise.

Thanks!

Revision history for this message
John Lenton (chipaca) :
review: Approve
Revision history for this message
Jamie Strandboge (jdstrand) wrote :

Thanks for the reviews! :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'bin/click-check-push-helper'
--- bin/click-check-push-helper 1970-01-01 00:00:00 +0000
+++ bin/click-check-push-helper 2014-07-24 21:41:48 +0000
@@ -0,0 +1,31 @@
1#!/usr/bin/python3
2'''click-check-push-helper: perform click push-helper checks'''
3#
4# Copyright (C) 2014 Canonical Ltd.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; version 3 of the License.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18from __future__ import print_function
19import sys
20
21import clickreviews.cr_common as cr_common
22import clickreviews.cr_push_helper as cr_push_helper
23
24if __name__ == "__main__":
25 if len(sys.argv) < 2:
26 cr_common.error("Must give path to click package")
27
28 review = cr_push_helper.ClickReviewPushHelper(sys.argv[1])
29 review.do_checks()
30 rc = review.do_report()
31 sys.exit(rc)
032
=== modified file 'bin/click-run-checks'
--- bin/click-run-checks 2014-07-16 17:56:05 +0000
+++ bin/click-run-checks 2014-07-24 21:41:48 +0000
@@ -56,6 +56,10 @@
56prefer_local click-check-online-accounts "$c"56prefer_local click-check-online-accounts "$c"
5757
58echo ""58echo ""
59echo "= click-check-push-helper ="
60prefer_local click-check-push-helper "$c"
61
62echo ""
59echo "= click-check-scope ="63echo "= click-check-scope ="
60prefer_local click-check-scope "$c"64prefer_local click-check-scope "$c"
6165
6266
=== modified file 'bin/click-show-files'
--- bin/click-show-files 2014-07-18 14:18:06 +0000
+++ bin/click-show-files 2014-07-24 21:41:48 +0000
@@ -27,6 +27,7 @@
27from clickreviews import cr_scope27from clickreviews import cr_scope
28from clickreviews import cr_content_hub28from clickreviews import cr_content_hub
29from clickreviews import cr_online_accounts29from clickreviews import cr_online_accounts
30from clickreviews import cr_push_helper
3031
31# This script just dumps important files to stdout32# This script just dumps important files to stdout
3233
@@ -86,6 +87,18 @@
86 print("")87 print("")
87 cr_common.cleanup_unpack()88 cr_common.cleanup_unpack()
8889
90 review_push_helper = cr_push_helper.ClickReviewPushHelper(sys.argv[1])
91 for app in sorted(review_push_helper.push_helper_files):
92 f = review_push_helper.push_helper_files[app]
93 fh = cr_common.open_file_read(os.path.join(
94 review_push_helper.unpack_dir, f))
95 print("== push_helper: %s ==" % os.path.basename(f))
96 for line in fh.readlines():
97 print(line, end="")
98 fh.close()
99 print("")
100 cr_common.cleanup_unpack()
101
89 review_scope = cr_scope.ClickReviewScope(sys.argv[1])102 review_scope = cr_scope.ClickReviewScope(sys.argv[1])
90 for app in sorted(review_scope.scopes):103 for app in sorted(review_scope.scopes):
91 f = review_scope.scopes[app]["ini_file"]104 f = review_scope.scopes[app]["ini_file"]
92105
=== modified file 'clickreviews/cr_common.py'
--- clickreviews/cr_common.py 2014-06-24 13:51:19 +0000
+++ clickreviews/cr_common.py 2014-07-24 21:41:48 +0000
@@ -62,7 +62,8 @@
62 if not self.click_package.endswith(".click"):62 if not self.click_package.endswith(".click"):
63 if self.click_package.endswith(".deb"):63 if self.click_package.endswith(".deb"):
64 error("filename does not end with '.click', but '.deb' "64 error("filename does not end with '.click', but '.deb' "
65 "instead. See http://askubuntu.com/a/485544/94326 for how click packages are different.")65 "instead. See http://askubuntu.com/a/485544/94326 for "
66 "how click packages are different.")
66 error("filename does not end with '.click'")67 error("filename does not end with '.click'")
6768
68 self.review_type = review_type69 self.review_type = review_type
6970
=== modified file 'clickreviews/cr_desktop.py'
--- clickreviews/cr_desktop.py 2014-05-30 08:33:09 +0000
+++ clickreviews/cr_desktop.py 2014-07-24 21:41:48 +0000
@@ -37,7 +37,11 @@
37 for app in self.manifest['hooks']:37 for app in self.manifest['hooks']:
38 if 'desktop' not in self.manifest['hooks'][app]:38 if 'desktop' not in self.manifest['hooks'][app]:
39 if 'scope' in self.manifest['hooks'][app]:39 if 'scope' in self.manifest['hooks'][app]:
40 msg("Skipped missing desktop hook for scope '%s'" % app)40 # msg("Skipped missing desktop hook for scope '%s'" % app)
41 continue
42 if 'push-helper' in self.manifest['hooks'][app]:
43 # msg("Skipped missing desktop hook for push-helper '%s'" %
44 # app)
41 continue45 continue
42 else:46 else:
43 error("could not find desktop hook for '%s'" % app)47 error("could not find desktop hook for '%s'" % app)
4448
=== modified file 'clickreviews/cr_lint.py'
--- clickreviews/cr_lint.py 2014-07-16 19:07:21 +0000
+++ clickreviews/cr_lint.py 2014-07-24 21:41:48 +0000
@@ -69,6 +69,7 @@
69 'content-hub',69 'content-hub',
70 'desktop',70 'desktop',
71 'pay-ui',71 'pay-ui',
72 'push-helper',
72 'scope',73 'scope',
73 'urls']74 'urls']
7475
@@ -281,11 +282,20 @@
281 # Some checks are already handled in282 # Some checks are already handled in
282 # cr_common.py:_verify_manifest_structure()283 # cr_common.py:_verify_manifest_structure()
283284
284 # We don't support multiple apps in 13.10285 # While we support multiple apps in the hooks db, we don't support
285 if len(self.manifest['hooks'].keys()) != 1:286 # multiple apps specifying desktop hooks. Eg, it is ok to specify a
286 self._add_result('error', 'hooks',287 # scope, an app and a push-helper, but it isn't ok to specify two apps
287 "more than one app key specified in hooks")288 t = 'info'
288 return289 n = 'hooks_multiple_apps'
290 s = 'OK'
291 count = 0
292 for app in self.manifest['hooks']:
293 if "desktop" in self.manifest['hooks'][app]:
294 count += 1
295 if count > 1:
296 t = 'error'
297 s = 'more than one desktop app specified in hooks'
298 self._add_result(t, n, s)
289299
290 # Verify keys are well-formatted300 # Verify keys are well-formatted
291 for app in self.manifest['hooks']:301 for app in self.manifest['hooks']:
292302
=== added file 'clickreviews/cr_push_helper.py'
--- clickreviews/cr_push_helper.py 1970-01-01 00:00:00 +0000
+++ clickreviews/cr_push_helper.py 2014-07-24 21:41:48 +0000
@@ -0,0 +1,132 @@
1'''cr_push_helper.py: click push-helper checks'''
2#
3# Copyright (C) 2014 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; version 3 of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from __future__ import print_function
18
19from clickreviews.cr_common import ClickReview, error, open_file_read, msg
20import json
21import os
22
23
24class ClickReviewPushHelper(ClickReview):
25 '''This class represents click lint reviews'''
26 def __init__(self, fn):
27 ClickReview.__init__(self, fn, "push_helper")
28
29 self.required_keys = ['exec']
30 self.optional_keys = ['app_id']
31
32 self.push_helper_files = dict() # click-show-files and tests
33 self.push_helper = dict()
34 for app in self.manifest['hooks']:
35 if 'push-helper' not in self.manifest['hooks'][app]:
36 # msg("Skipped missing push-helper hook for '%s'" % app)
37 continue
38 if not isinstance(self.manifest['hooks'][app]['push-helper'], str):
39 error("manifest malformed: hooks/%s/urls is not str" % app)
40 (full_fn, jd) = self._extract_push_helper(app)
41 self.push_helper_files[app] = full_fn
42 self.push_helper[app] = jd
43
44 def _extract_push_helper(self, app):
45 '''Get push-helper hook content'''
46 c = self.manifest['hooks'][app]['push-helper']
47 fn = os.path.join(self.unpack_dir, c)
48
49 bn = os.path.basename(fn)
50 if not os.path.exists(fn):
51 error("Could not find '%s'" % bn)
52
53 fh = open_file_read(fn)
54 contents = ""
55 for line in fh.readlines():
56 contents += line
57 fh.close()
58
59 try:
60 jd = json.loads(contents)
61 except Exception as e:
62 error("push-helper json unparseable: %s (%s):\n%s" % (bn,
63 str(e), contents))
64
65 if not isinstance(jd, dict):
66 error("push-helper json is malformed: %s:\n%s" % (bn, contents))
67
68 return (fn, jd)
69
70 def check_valid(self):
71 '''Check validity of push-helper entries'''
72 for app in sorted(self.push_helper):
73 for k in self.push_helper[app].keys():
74 t = "info"
75 n = "valid_%s_%s" % (app, k)
76 s = "OK"
77
78 if not isinstance(self.push_helper[app][k], str):
79 t = "error"
80 s = "'%s' is not a string" % k
81 elif self.push_helper[app][k] == "":
82 t = "error"
83 s = "'%s' is empty" % k
84 self._add_result(t, n, s)
85
86 for k in self.required_keys:
87 t = "info"
88 n = "valid_%s_required_%s" % (app, k)
89 s = "OK"
90 if k not in self.push_helper[app]:
91 t = "error"
92 s = "'%s' is missing" % k
93 self._add_result(t, n, s)
94
95 def check_unknown_keys(self):
96 '''Check unknown'''
97 for app in sorted(self.push_helper):
98 unknown = []
99 t = "info"
100 n = "unknown_%s" % app
101 s = "OK"
102 for key in self.push_helper[app].keys():
103 if key not in self.required_keys and \
104 key not in self.optional_keys:
105 unknown.append(key)
106 if len(unknown) == 1:
107 t = "warn"
108 s = "Unknown field '%s'" % unknown[0]
109 elif len(unknown) > 1:
110 t = "warn"
111 s = "Unknown fields '%s'" % ", ".join(unknown)
112 self._add_result(t, n, s)
113
114 def check_hooks(self):
115 '''Verify combinations of click hooks with the push-helper hook'''
116 for app in sorted(self.manifest['hooks']):
117 if app not in self.push_helper:
118 continue
119
120 t = "info"
121 n = "other_hooks_%s" % app
122 s = "OK"
123
124 bad = []
125 for hook in self.manifest['hooks'][app]:
126 # Only the apparmor hook can be used with the push-helper
127 if hook not in ['push-helper', 'apparmor']:
128 bad.append(hook)
129 if len(bad) > 0:
130 t = 'error'
131 s = "Found unusual hooks with push-helper: %s" % ", ".join(bad)
132 self._add_result(t, n, s)
0133
=== modified file 'clickreviews/cr_security.py'
--- clickreviews/cr_security.py 2014-07-18 19:47:48 +0000
+++ clickreviews/cr_security.py 2014-07-24 21:41:48 +0000
@@ -66,6 +66,8 @@
66 'video',66 'video',
67 'webview']67 'webview']
6868
69 self.allowed_push_helper_policy_groups = ['push-notification-client']
70
69 self.redflag_templates = ['unconfined']71 self.redflag_templates = ['unconfined']
70 self.extraneous_templates = ['ubuntu-sdk',72 self.extraneous_templates = ['ubuntu-sdk',
71 'default']73 'default']
@@ -357,6 +359,44 @@
357359
358 self._add_result(t, n, s)360 self._add_result(t, n, s)
359361
362 def check_template_push_helpers(self):
363 '''Check template for push-helpers'''
364 for app in sorted(self.manifest['hooks']):
365 (f, m) = self._get_security_manifest(app)
366 t = 'info'
367 n = 'template_push_helper(%s)' % f
368 s = "OK"
369 if 'push-helper' not in self.manifest['hooks'][app]:
370 continue
371 if 'template' in m and m['template'] != "ubuntu-sdk":
372 t = 'error'
373 s = "template is not 'ubuntu-sdk'"
374 self._add_result(t, n, s)
375
376 def check_policy_groups_push_helpers(self):
377 '''Check policy_groups for push-helpers'''
378 for app in sorted(self.manifest['hooks']):
379 (f, m) = self._get_security_manifest(app)
380 t = 'info'
381 n = 'policy_groups_push_helper(%s)' % f
382 s = "OK"
383 if 'push-helper' not in self.manifest['hooks'][app]:
384 continue
385 if 'policy_groups' not in m or \
386 'push-notification-client' not in m['policy_groups']:
387 self._add_result('error', n,
388 "required group 'push-notification-client' "
389 "not found")
390 continue
391 bad = []
392 for p in m['policy_groups']:
393 if p not in self.allowed_push_helper_policy_groups:
394 bad.append(p)
395 if len(bad) > 0:
396 t = 'error'
397 s = "found unusual policy groups: %s" % ", ".join(bad)
398 self._add_result(t, n, s)
399
360 def check_policy_groups_scopes(self):400 def check_policy_groups_scopes(self):
361 '''Check policy_groups for scopes'''401 '''Check policy_groups for scopes'''
362 for app in sorted(self.manifest['hooks']):402 for app in sorted(self.manifest['hooks']):
@@ -397,7 +437,7 @@
397 (f, m) = self._get_security_manifest(app)437 (f, m) = self._get_security_manifest(app)
398438
399 t = 'info'439 t = 'info'
400 n = 'policy_groups_exists (%s)' % f440 n = 'policy_groups_exists_%s (%s)' % (app, f)
401 if 'policy_groups' not in m:441 if 'policy_groups' not in m:
402 # If template not specified, we just use the default442 # If template not specified, we just use the default
403 self._add_result('warn', n, 'no policy groups specified')443 self._add_result('warn', n, 'no policy groups specified')
@@ -423,7 +463,7 @@
423463
424 # Check for duplicates464 # Check for duplicates
425 t = 'info'465 t = 'info'
426 n = 'policy_groups_duplicates (%s)' % f466 n = 'policy_groups_duplicates_%s (%s)' % (app, f)
427 s = 'OK'467 s = 'OK'
428 tmp = []468 tmp = []
429 for p in m['policy_groups']:469 for p in m['policy_groups']:
@@ -438,7 +478,7 @@
438 # If we got here, we can see if valid policy groups were specified478 # If we got here, we can see if valid policy groups were specified
439 for i in m['policy_groups']:479 for i in m['policy_groups']:
440 t = 'info'480 t = 'info'
441 n = 'policy_groups_valid (%s)' % i481 n = 'policy_groups_valid_%s (%s)' % (app, i)
442 s = 'OK'482 s = 'OK'
443483
444 # SDK will leave and empty policy group, report but don't484 # SDK will leave and empty policy group, report but don't
@@ -461,7 +501,7 @@
461501
462 if found:502 if found:
463 t = 'info'503 t = 'info'
464 n = 'policy_groups_safe (%s)' % i504 n = 'policy_groups_safe_%s (%s)' % (app, i)
465 s = 'OK'505 s = 'OK'
466506
467 aa_type = self._get_policy_group_type(vendor, version, i)507 aa_type = self._get_policy_group_type(vendor, version, i)
468508
=== modified file 'clickreviews/cr_tests.py'
--- clickreviews/cr_tests.py 2014-07-16 18:13:22 +0000
+++ clickreviews/cr_tests.py 2014-07-24 21:41:48 +0000
@@ -39,6 +39,7 @@
39TEST_ACCOUNTS_PROVIDER = dict()39TEST_ACCOUNTS_PROVIDER = dict()
40TEST_ACCOUNTS_QML_PLUGIN = dict()40TEST_ACCOUNTS_QML_PLUGIN = dict()
41TEST_ACCOUNTS_SERVICE = dict()41TEST_ACCOUNTS_SERVICE = dict()
42TEST_PUSH_HELPER = dict()
4243
4344
44#45#
@@ -148,6 +149,11 @@
148 return (f, val)149 return (f, val)
149150
150151
152def _extract_push_helper(self, app):
153 '''Pretend we read the push-helper file'''
154 return ("%s.push-helper.json" % app, TEST_PUSH_HELPER[app])
155
156
151# http://docs.python.org/3.4/library/unittest.mock-examples.html157# http://docs.python.org/3.4/library/unittest.mock-examples.html
152# Mock patching. Don't use decorators but instead patch in setUp() of the158# Mock patching. Don't use decorators but instead patch in setUp() of the
153# child. Set up a list of patches, but don't start them. Create the helper159# child. Set up a list of patches, but don't start them. Create the helper
@@ -228,6 +234,11 @@
228 'clickreviews.cr_online_accounts.ClickReviewAccounts._extract_account',234 'clickreviews.cr_online_accounts.ClickReviewAccounts._extract_account',
229 _extract_account))235 _extract_account))
230236
237# push-helper overrides
238patches.append(patch(
239 'clickreviews.cr_push_helper.ClickReviewPushHelper._extract_push_helper',
240 _extract_push_helper))
241
231242
232def mock_patch():243def mock_patch():
233 '''Call in setup of child'''244 '''Call in setup of child'''
@@ -295,6 +306,7 @@
295 self.test_accounts_provider = dict()306 self.test_accounts_provider = dict()
296 self.test_accounts_qml_plugin = dict()307 self.test_accounts_qml_plugin = dict()
297 self.test_accounts_service = dict()308 self.test_accounts_service = dict()
309 self.test_push_helper = dict()
298 for app in self.test_manifest["hooks"].keys():310 for app in self.test_manifest["hooks"].keys():
299 # setup security manifest for each app311 # setup security manifest for each app
300 self.set_test_security_manifest(app, 'policy_groups',312 self.set_test_security_manifest(app, 'policy_groups',
@@ -330,6 +342,9 @@
330 self.set_test_account(app, "account-qml-plugin", None)342 self.set_test_account(app, "account-qml-plugin", None)
331 self.set_test_account(app, "account-service", None)343 self.set_test_account(app, "account-service", None)
332344
345 # Reset to no content-hub entries in manifest
346 self.set_test_push_helper(app, None, None)
347
333 self._update_test_security_manifests()348 self._update_test_security_manifests()
334 self._update_test_desktop_files()349 self._update_test_desktop_files()
335 self._update_test_url_dispatcher()350 self._update_test_url_dispatcher()
@@ -339,6 +354,7 @@
339 self._update_test_accounts_provider()354 self._update_test_accounts_provider()
340 self._update_test_accounts_qml_plugin()355 self._update_test_accounts_qml_plugin()
341 self._update_test_accounts_service()356 self._update_test_accounts_service()
357 self._update_test_push_helper()
342358
343 # webapps manifests (leave empty for now)359 # webapps manifests (leave empty for now)
344 self.test_webapp_manifests = dict()360 self.test_webapp_manifests = dict()
@@ -444,6 +460,15 @@
444 "%s.service" % app460 "%s.service" % app
445 self._update_test_manifest()461 self._update_test_manifest()
446462
463 def _update_test_push_helper(self):
464 global TEST_PUSH_HELPER
465 TEST_PUSH_HELPER = dict()
466 for app in self.test_push_helper.keys():
467 TEST_PUSH_HELPER[app] = self.test_push_helper[app]
468 self.test_manifest["hooks"][app]["push-helper"] = \
469 "%s.push-helper.json" % app
470 self._update_test_manifest()
471
447 def _update_test_name(self):472 def _update_test_name(self):
448 self.test_name = "%s_%s_%s.click" % (self.test_control['Package'],473 self.test_name = "%s_%s_%s.click" % (self.test_control['Package'],
449 self.test_control['Version'],474 self.test_control['Version'],
@@ -618,6 +643,21 @@
618 elif account_type == "account-service":643 elif account_type == "account-service":
619 self._update_test_accounts_service()644 self._update_test_accounts_service()
620645
646 def set_test_push_helper(self, app, key, value):
647 '''Set push-helper entries. If value is None, remove key, if key is
648 None, remove content-hub from manifest'''
649 if key is None:
650 if app in self.test_push_helper:
651 self.test_push_helper.pop(app)
652 elif value is None:
653 if key in self.test_push_helper[app]:
654 self.test_push_helper[app].pop(key)
655 else:
656 if app not in self.test_push_helper:
657 self.test_push_helper[app] = dict()
658 self.test_push_helper[app][key] = value
659 self._update_test_push_helper()
660
621 def setUp(self):661 def setUp(self):
622 '''Make sure our patches are applied everywhere'''662 '''Make sure our patches are applied everywhere'''
623 global patches663 global patches
@@ -647,7 +687,9 @@
647 global TEST_ACCOUNTS_QML_PLUGIN687 global TEST_ACCOUNTS_QML_PLUGIN
648 TEST_ACCOUNTS_QML_PLUGIN = dict()688 TEST_ACCOUNTS_QML_PLUGIN = dict()
649 global TEST_ACCOUNTS_SERVICE689 global TEST_ACCOUNTS_SERVICE
650 TEST_ACCOUNTS_APPLICTION = dict()690 TEST_ACCOUNTS_APPLICATION = dict()
691 global TEST_PUSH_HELPER
692 TEST_PUSH_HELPER = dict()
651693
652 self._reset_test_data()694 self._reset_test_data()
653 cr_common.recursive_rm(self.desktop_tmpdir)695 cr_common.recursive_rm(self.desktop_tmpdir)
654696
=== modified file 'clickreviews/tests/test_cr_lint.py'
--- clickreviews/tests/test_cr_lint.py 2014-07-16 14:48:39 +0000
+++ clickreviews/tests/test_cr_lint.py 2014-07-24 21:41:48 +0000
@@ -644,15 +644,37 @@
644 expected_counts = {'info': None, 'warn': 0, 'error': 0}644 expected_counts = {'info': None, 'warn': 0, 'error': 0}
645 self.check_results(r, expected_counts)645 self.check_results(r, expected_counts)
646646
647 def test_check_hooks_multiple_desktop_apps(self):
648 '''Test check_hooks() - multiple desktop apps'''
649 self.set_test_manifest("framework", "ubuntu-sdk-13.10")
650 c = ClickReviewLint(self.test_name)
651 tmp = c.manifest['hooks'][self.default_appname]
652 c.manifest['hooks']["another-app"] = tmp
653 c.check_hooks()
654 r = c.click_report
655 expected_counts = {'info': None, 'warn': 0, 'error': 1}
656 self.check_results(r, expected_counts)
657
647 def test_check_hooks_multiple_apps(self):658 def test_check_hooks_multiple_apps(self):
648 '''Test check_hooks() - multiple apps'''659 '''Test check_hooks() - multiple non-desktop apps'''
649 self.set_test_manifest("framework", "ubuntu-sdk-13.10")660 self.set_test_manifest("framework", "ubuntu-sdk-13.10")
650 c = ClickReviewLint(self.test_name)661 c = ClickReviewLint(self.test_name)
651 tmp = c.manifest['hooks'][self.default_appname]662 tmp = dict()
652 c.manifest['hooks']["another-app"] = tmp663 for k in c.manifest['hooks'][self.default_appname].keys():
664 tmp[k] = c.manifest['hooks'][self.default_appname][k]
665 tmp.pop('desktop')
666 tmp['scope'] = "some-scope-exec"
667 c.manifest['hooks']["some-scope"] = tmp
668 tmp = dict()
669 for k in c.manifest['hooks'][self.default_appname].keys():
670 tmp[k] = c.manifest['hooks'][self.default_appname][k]
671 tmp.pop('desktop')
672 tmp['push-helper'] = "push.json"
673 c.manifest['hooks']["some-push-helper"] = tmp
674
653 c.check_hooks()675 c.check_hooks()
654 r = c.click_report676 r = c.click_report
655 expected_counts = {'info': None, 'warn': 0, 'error': 1}677 expected_counts = {'info': 7, 'warn': 0, 'error': 0}
656 self.check_results(r, expected_counts)678 self.check_results(r, expected_counts)
657679
658 def test_check_hooks_bad_appname(self):680 def test_check_hooks_bad_appname(self):
659681
=== added file 'clickreviews/tests/test_cr_push_helper.py'
--- clickreviews/tests/test_cr_push_helper.py 1970-01-01 00:00:00 +0000
+++ clickreviews/tests/test_cr_push_helper.py 2014-07-24 21:41:48 +0000
@@ -0,0 +1,138 @@
1'''test_cr_push_helper.py: tests for the cr_push_helper module'''
2#
3# Copyright (C) 2013 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; version 3 of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17from clickreviews.cr_push_helper import ClickReviewPushHelper
18import clickreviews.cr_tests as cr_tests
19
20
21class TestClickReviewPushHelper(cr_tests.TestClickReview):
22 """Tests for the lint review tool."""
23 def setUp(self):
24 # Monkey patch various file access classes. stop() is handled with
25 # addCleanup in super()
26 cr_tests.mock_patch()
27 super()
28
29 def test_check_unknown_keys_none(self):
30 '''Test check_unknown() - no unknown'''
31 self.set_test_push_helper(self.default_appname, "exec", "foo")
32 c = ClickReviewPushHelper(self.test_name)
33 c.check_unknown_keys()
34 r = c.click_report
35 expected_counts = {'info': 1, 'warn': 0, 'error': 0}
36 self.check_results(r, expected_counts)
37
38 def test_check_unknown_keys1(self):
39 '''Test check_unknown() - one unknown'''
40 self.set_test_push_helper(self.default_appname, "nonexistent", "foo")
41 c = ClickReviewPushHelper(self.test_name)
42 c.check_unknown_keys()
43 r = c.click_report
44 expected_counts = {'info': 0, 'warn': 1, 'error': 0}
45 self.check_results(r, expected_counts)
46
47 def test_check_unknown_keys2(self):
48 '''Test check_unknown() - good with one unknown'''
49 self.set_test_push_helper(self.default_appname, "exec", "foo")
50 self.set_test_push_helper(self.default_appname, "nonexistent", "foo")
51 c = ClickReviewPushHelper(self.test_name)
52 c.check_unknown_keys()
53 r = c.click_report
54 expected_counts = {'info': 0, 'warn': 1, 'error': 0}
55 self.check_results(r, expected_counts)
56
57 def test_check_valid_exec(self):
58 '''Test check_valid() - exec'''
59 self.set_test_push_helper(self.default_appname, "exec", "foo")
60 c = ClickReviewPushHelper(self.test_name)
61 c.check_valid()
62 r = c.click_report
63 expected_counts = {'info': 2, 'warn': 0, 'error': 0}
64 self.check_results(r, expected_counts)
65
66 def test_check_valid_missing_exec(self):
67 '''Test check_valid() - missing exec'''
68 self.set_test_push_helper(self.default_appname, "app_id", "foo_foo")
69 c = ClickReviewPushHelper(self.test_name)
70 c.check_valid()
71 r = c.click_report
72 expected_counts = {'info': None, 'warn': 0, 'error': 1}
73 self.check_results(r, expected_counts)
74
75 def test_check_valid_app_id(self):
76 '''Test check_valid() - app_id'''
77 self.set_test_push_helper(self.default_appname, "exec", "foo")
78 self.set_test_push_helper(self.default_appname, "app_id", "foo_foo")
79 c = ClickReviewPushHelper(self.test_name)
80 c.check_valid()
81 r = c.click_report
82 expected_counts = {'info': 3, 'warn': 0, 'error': 0}
83 self.check_results(r, expected_counts)
84
85 def test_check_valid_bad_value(self):
86 '''Test check_valid() - bad value'''
87 self.set_test_push_helper(self.default_appname, "exec", [])
88 c = ClickReviewPushHelper(self.test_name)
89 c.check_valid()
90 r = c.click_report
91 expected_counts = {'info': None, 'warn': 0, 'error': 1}
92 self.check_results(r, expected_counts)
93
94 def test_check_valid_empty_value(self):
95 '''Test check_valid() - empty value'''
96 self.set_test_push_helper(self.default_appname, "exec", "foo")
97 self.set_test_push_helper(self.default_appname, "app_id", "")
98 c = ClickReviewPushHelper(self.test_name)
99 c.check_valid()
100 r = c.click_report
101 expected_counts = {'info': None, 'warn': 0, 'error': 1}
102 self.check_results(r, expected_counts)
103
104 def test_check_valid_empty_value2(self):
105 '''Test check_valid() - empty value'''
106 self.set_test_push_helper(self.default_appname, "exec", "")
107 self.set_test_push_helper(self.default_appname, "app_id", "foo_foo")
108 c = ClickReviewPushHelper(self.test_name)
109 c.check_valid()
110 r = c.click_report
111 expected_counts = {'info': None, 'warn': 0, 'error': 1}
112 self.check_results(r, expected_counts)
113
114 def test_check_hooks(self):
115 '''Test check_hooks()'''
116 self.set_test_push_helper(self.default_appname, "exec", "foo")
117 c = ClickReviewPushHelper(self.test_name)
118
119 # remove hooks that are added by the framework
120 c.manifest['hooks'][self.default_appname].pop('desktop')
121 c.manifest['hooks'][self.default_appname].pop('urls')
122
123 c.check_hooks()
124 r = c.click_report
125 expected_counts = {'info': 1, 'warn': 0, 'error': 0}
126 self.check_results(r, expected_counts)
127
128 def test_check_hooks_bad(self):
129 '''Test check_hooks() - bad'''
130 self.set_test_push_helper(self.default_appname, "exec", "foo")
131 c = ClickReviewPushHelper(self.test_name)
132
133 # The desktop and urls hooks are specified by default in the framework,
134 # so just running this without other setup should generate an error
135 c.check_hooks()
136 r = c.click_report
137 expected_counts = {'info': None, 'warn': 0, 'error': 1}
138 self.check_results(r, expected_counts)
0139
=== modified file 'clickreviews/tests/test_cr_security.py'
--- clickreviews/tests/test_cr_security.py 2014-07-14 16:40:36 +0000
+++ clickreviews/tests/test_cr_security.py 2014-07-24 21:41:48 +0000
@@ -600,3 +600,87 @@
600 report = c.click_report600 report = c.click_report
601 expected_counts = {'info': None, 'warn': 0, 'error': 1}601 expected_counts = {'info': None, 'warn': 0, 'error': 1}
602 self.check_results(report, expected_counts)602 self.check_results(report, expected_counts)
603
604 def test_check_policy_groups_pushhelper_no_hook(self):
605 '''Test check_policy_groups_pushhelper() - no hook'''
606 c = ClickReviewSecurity(self.test_name)
607 c.check_policy_groups_push_helpers()
608 report = c.click_report
609 expected_counts = {'info': 0, 'warn': 0, 'error': 0}
610 self.check_results(report, expected_counts)
611
612 def test_check_policy_groups_pushhelper(self):
613 '''Test check_policy_groups_pushhelper()'''
614 self.set_test_push_helper(self.default_appname, "exec", "foo")
615 self.set_test_security_manifest(self.default_appname,
616 "policy_groups",
617 ["push-notification-client"])
618 c = ClickReviewSecurity(self.test_name)
619 c.check_policy_groups_push_helpers()
620 report = c.click_report
621 expected_counts = {'info': 1, 'warn': 0, 'error': 0}
622 self.check_results(report, expected_counts)
623
624 def test_check_policy_groups_pushhelper_missing(self):
625 '''Test check_policy_groups_pushhelper - missing'''
626 self.set_test_push_helper(self.default_appname, "exec", "foo")
627 self.set_test_security_manifest(self.default_appname,
628 "policy_groups",
629 None)
630 c = ClickReviewSecurity(self.test_name)
631 c.check_policy_groups_push_helpers()
632 report = c.click_report
633 expected_counts = {'info': None, 'warn': 0, 'error': 1}
634 self.check_results(report, expected_counts)
635
636 def test_check_policy_groups_pushhelper_bad(self):
637 '''Test check_policy_groups_pushhelper - bad'''
638 self.set_test_push_helper(self.default_appname, "exec", "foo")
639 self.set_test_security_manifest(self.default_appname,
640 "policy_groups",
641 ["video_files",
642 "networking",
643 "push-notification-client"])
644 c = ClickReviewSecurity(self.test_name)
645 c.check_policy_groups_push_helpers()
646 report = c.click_report
647 expected_counts = {'info': None, 'warn': 0, 'error': 1}
648 self.check_results(report, expected_counts)
649
650 def test_check_template_pushhelper(self):
651 '''Test check_template_pushhelper'''
652 self.set_test_push_helper(self.default_appname, "exec", "foo")
653 self.set_test_security_manifest(self.default_appname,
654 "template", "ubuntu-sdk")
655 self.set_test_security_manifest(self.default_appname,
656 "policy_groups",
657 ["push-notification-client"])
658 c = ClickReviewSecurity(self.test_name)
659 c.check_template_push_helpers()
660 report = c.click_report
661 expected_counts = {'info': 1, 'warn': 0, 'error': 0}
662 self.check_results(report, expected_counts)
663
664 def test_check_template_pushhelper_no_hook(self):
665 '''Test check_template_pushhelper'''
666 self.set_test_security_manifest(self.default_appname,
667 "template", "ubuntu-sdk")
668 c = ClickReviewSecurity(self.test_name)
669 c.check_template_push_helpers()
670 report = c.click_report
671 expected_counts = {'info': 0, 'warn': 0, 'error': 0}
672 self.check_results(report, expected_counts)
673
674 def test_check_template_pushhelper_wrong_template(self):
675 '''Test check_template_pushhelper - wrong template()'''
676 self.set_test_push_helper(self.default_appname, "exec", "foo")
677 self.set_test_security_manifest(self.default_appname,
678 "template", "ubuntu-webapp")
679 self.set_test_security_manifest(self.default_appname,
680 "policy_groups",
681 ["push-notification-client"])
682 c = ClickReviewSecurity(self.test_name)
683 c.check_template_push_helpers()
684 report = c.click_report
685 expected_counts = {'info': None, 'warn': 0, 'error': 1}
686 self.check_results(report, expected_counts)
603687
=== modified file 'debian/changelog'
--- debian/changelog 2014-07-23 07:53:35 +0000
+++ debian/changelog 2014-07-24 21:41:48 +0000
@@ -26,11 +26,12 @@
26 group in 1.2 (LP: #1340869)26 group in 1.2 (LP: #1340869)
27 * refactor the way we handle apparmor policy into a central static list27 * refactor the way we handle apparmor policy into a central static list
28 which should be easy to update.28 which should be easy to update.
29 * implement push-helper tests
2930
30 [ Daniel Holbach ]31 [ Daniel Holbach ]
31 * refer to documentation about click in case we encounter .deb packages.32 * refer to documentation about click in case we encounter .deb packages.
3233
33 -- Jamie Strandboge <jamie@ubuntu.com> Fri, 18 Jul 2014 14:51:46 -050034 -- Jamie Strandboge <jamie@ubuntu.com> Thu, 24 Jul 2014 14:04:23 -0500
3435
35click-reviewers-tools (0.7.1) utopic; urgency=medium36click-reviewers-tools (0.7.1) utopic; urgency=medium
3637

Subscribers

People subscribed via source and target branches