Skip to content

Commit 7b8d18e

Browse files
crazyscientistcrobinso
authored andcommitted
fix: Emulate permissive on REST backend (closes #222)
`_BackendREST.bug_get` cannot pass a `permissive` parameter to the server as the REST API does not honor such a parameter. With this change, permissiveness is handled inside the method: If `permissive` is false and a single ID or alias is requested, the "get" method is used and an exception gets raised in case of error. Otherwise, the "search" method is used, which may return an empty list, if the client is not authenticated or an ID or alias does not exist.
1 parent 5f89e28 commit 7b8d18e

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

bugzilla/_backendrest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,15 @@ def bug_fields(self, paramdict):
109109
def bug_get(self, bug_ids, aliases, paramdict):
110110
bug_list = listify(bug_ids)
111111
alias_list = listify(aliases)
112+
permissive = paramdict.pop("permissive", False)
112113
data = paramdict.copy()
113114

114115
# FYI: The high-level API expects the backends to raise an exception
115116
# when retrieval of a single bug fails (default behavior of the XMLRPC
116117
# API), but the REST API simply returns an empty search result set.
117118
# To ensure compliant behavior, the REST backend needs to use the
118119
# explicit URL to get a single bug.
119-
if len(bug_list or []) + len(alias_list or []) == 1:
120+
if not permissive and len(bug_list or []) + len(alias_list or []) == 1:
120121
for id_list in (bug_list, alias_list):
121122
if id_list:
122123
return self._get("/bug/%s" % id_list[0], data)

tests/test_backend_rest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,26 @@ def _assertion(self, *args):
4242
backend.bug_get(_ids, aliases, {})
4343

4444
assert backend.assertion_called is True
45+
46+
def test_getbug__permissive(self):
47+
backend = self.backend
48+
49+
def _assertion(self, *args):
50+
self.assertion_called = True
51+
assert args and args[0] == url and args[1] == params
52+
53+
setattr(backend, "_get", MethodType(_assertion, backend))
54+
55+
for _ids, aliases, url, params in (
56+
(1, None, "/bug", {"id": [1], "alias": None}),
57+
([1], [], "/bug", {"id": [1], "alias": []}),
58+
(None, "CVE-1999-0001", "/bug", {"alias": ["CVE-1999-0001"], "id": None}),
59+
([], ["CVE-1999-0001"], "/bug", {"alias": ["CVE-1999-0001"], "id": []}),
60+
(1, "CVE-1999-0001", "/bug", {"id": [1], "alias": ["CVE-1999-0001"]}),
61+
([1, 2], None, "/bug", {"id": [1, 2], "alias": None})
62+
):
63+
backend.assertion_called = False
64+
65+
backend.bug_get(_ids, aliases, {"permissive": True})
66+
67+
assert backend.assertion_called is True

0 commit comments

Comments
 (0)