Merge lp:~thomir-deactivatedaccount/autopilot/fix-server-side-param-matching into lp:autopilot

Proposed by Thomi Richards
Status: Merged
Approved by: Christopher Lee
Approved revision: 310
Merged at revision: 307
Proposed branch: lp:~thomir-deactivatedaccount/autopilot/fix-server-side-param-matching
Merge into: lp:autopilot
Diff against target: 88 lines (+46/-3)
2 files modified
autopilot/introspection/dbus.py (+19/-1)
autopilot/tests/unit/test_introspection_features.py (+27/-2)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/autopilot/fix-server-side-param-matching
Reviewer Review Type Date Requested Status
Christopher Lee (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+179082@code.launchpad.net

Commit message

Fix parameter matching for special characters.

Description of the change

Make the parameter matching match the deficiencies in xpathselect more closely.

To post a comment you must log in.
307. By Thomi Richards

fix typo and pep8 issues.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
308. By Thomi Richards

Added initial test, fixed function to return a boolean, rather than a re.Match object.

309. By Thomi Richards

Added tests, fixed pep8 issues.

310. By Thomi Richards

remember to save files before comitting

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Lee (veebers) wrote :

Awesome, looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/introspection/dbus.py'
2--- autopilot/introspection/dbus.py 2013-08-07 03:18:32 +0000
3+++ autopilot/introspection/dbus.py 2013-08-08 20:34:31 +0000
4@@ -29,6 +29,7 @@
5
6 from contextlib import contextmanager
7 import logging
8+import re
9 from testtools.matchers import Equals
10 from time import sleep
11 from uuid import uuid4
12@@ -391,7 +392,13 @@
13
14 first_param = ''
15 for k, v in kwargs.iteritems():
16- if isinstance(v, str) and '_' not in k:
17+ # LP Bug 1209029: The XPathSelect protocol does not allow all valid
18+ # node names or values. We need to decide here whether the filter
19+ # parameters are going to work on the backend or not. If not, we
20+ # just do the processing client-side. See the
21+ # _is_valid_server_side_filter_param function (below) for the
22+ # specific requirements.
23+ if _is_valid_server_side_filter_param(k, v):
24 first_param = '[{}={}]'.format(k, v)
25 kwargs.pop(k)
26 break
27@@ -550,6 +557,17 @@
28 self.__refresh_on_attribute = True
29
30
31+def _is_valid_server_side_filter_param(key, value):
32+ """Return True if the key and value parameters are valid for server-side
33+ processing.
34+
35+ """
36+ return (
37+ isinstance(value, str) and
38+ re.match(r'^[a-zA-Z0-9_\-]+( [a-zA-Z0-9_\-])*$', key) is not None and
39+ re.match(r'^[a-zA-Z0-9_\-]+( [a-zA-Z0-9_\-])*$', value) is not None)
40+
41+
42 class _CustomEmulatorMeta(IntrospectableObjectMetaclass):
43
44 def __new__(cls, name, bases, d):
45
46=== modified file 'autopilot/tests/unit/test_introspection_features.py'
47--- autopilot/tests/unit/test_introspection_features.py 2013-07-22 03:38:23 +0000
48+++ autopilot/tests/unit/test_introspection_features.py 2013-08-08 20:34:31 +0000
49@@ -20,8 +20,13 @@
50
51 from testtools import TestCase
52 from testtools.matchers import Equals, NotEquals
53-
54-from autopilot.introspection.dbus import CustomEmulatorBase
55+from testscenarios import TestWithScenarios
56+
57+
58+from autopilot.introspection.dbus import (
59+ CustomEmulatorBase,
60+ _is_valid_server_side_filter_param,
61+)
62
63
64 class IntrospectionFeatureTests(TestCase):
65@@ -55,3 +60,23 @@
66 pass
67
68 self.assertThat(MyEmulatorBase._id, NotEquals(MyEmulatorBase2._id))
69+
70+
71+class ServerSideParamMatchingTests(TestWithScenarios, TestCase):
72+
73+ """Tests for the server side matching decision function."""
74+
75+ scenarios = [
76+ ('should work', dict(key='keyname', value='value', result=True)),
77+ ('invalid key', dict(key='k e', value='value', result=False)),
78+ ('invalid value', dict(key='key', value='v e', result=False)),
79+ ('invalid value2', dict(key='key', value='v?e', result=False)),
80+ ('invalid value3', dict(key='key', value='1/2', result=False)),
81+ ('invalid value type', dict(key='key', value=False, result=False)),
82+ ]
83+
84+ def test_valid_server_side_param(self):
85+ self.assertThat(
86+ _is_valid_server_side_filter_param(self.key, self.value),
87+ Equals(self.result)
88+ )

Subscribers

People subscribed via source and target branches