Skip to content

Commit

Permalink
Use tuple as the cache-key for IssueTrackerType.rpc_cache internally
Browse files Browse the repository at this point in the history
in order to prevent integrations which define personal ApiTokens to
accidentally use a cached version for the same URL but different credentials
  • Loading branch information
atodorov committed Nov 20, 2023
1 parent f3352e8 commit 9136e92
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tcms/issuetracker/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,14 @@ def rpc(self):
if self.is_adding_testcase_to_issue_disabled():
return None

if self.bug_system.base_url not in self.rpc_cache:
self.rpc_cache[self.bug_system.base_url] = self._rpc_connection()

return self.rpc_cache[self.bug_system.base_url]
# NOTE: using a tuple as the cache-key to prevent integrations which define
# personal ApiTokens to accidentally use a cached version
# for the same URL but different credentials
rpc_key = (self.bug_system.base_url, getattr(self.request, "user", None))
if rpc_key not in self.rpc_cache:
self.rpc_cache[rpc_key] = self._rpc_connection()

return self.rpc_cache[rpc_key]

@property
def rpc_credentials(self):
Expand Down

0 comments on commit 9136e92

Please sign in to comment.