[PATCH 1/2] Bugzilla.logged_in now returns live state
by Arun Babu Neelicattu
From: Arun Babu Neelicattu <abn(a)redhat.com>
- since BugZilla XMLRPC does not currentlly expose a way to query login state
for a user, we workaround this by calling User.get() with ids set
- extend test suite to cover Bugzilla.logged_in
---
bugzilla/base.py | 21 ++++++++++++++++++---
tests/rw_functional.py | 8 ++++++++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/bugzilla/base.py b/bugzilla/base.py
index 59dff17..fa2b0c2 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -403,7 +403,6 @@ class BugzillaBase(object):
self._cookiejar = None
self._sslverify = bool(sslverify)
- self.logged_in = False
self.bug_autorefresh = True
# Bugzilla object state info that users shouldn't mess with
@@ -644,7 +643,6 @@ class BugzillaBase(object):
try:
ret = self._login(self.user, self.password)
- self.logged_in = True
self.password = ''
log.info("login successful for user=%s", self.user)
return ret
@@ -695,7 +693,24 @@ class BugzillaBase(object):
self.disconnect()
self.user = ''
self.password = ''
- self.logged_in = False
+
+ @property
+ def logged_in(self):
+ """
+ This is True if this instance is logged in else False.
+
+ We test if this session is authenticated by calling the User.get()
+ XMLRPC method with ids set. Logged-out users cannot pass the 'ids'
+ parameter and will result in a 505 error.
+ """
+ try:
+ self._proxy.User.get({'ids': []})
+ return True
+ except Fault:
+ e = sys.exc_info()[1]
+ if e.faultCode == 505:
+ return False
+ raise e
#############################################
diff --git a/tests/rw_functional.py b/tests/rw_functional.py
index 10d4c6d..caab7d5 100644
--- a/tests/rw_functional.py
+++ b/tests/rw_functional.py
@@ -633,6 +633,14 @@ class RHPartnerTest(BaseTest):
self.assertTrue("Login failed: " in ret)
+ def test10LoginState(self):
+ bz = self.bzclass(url=self.url, cookiefile=None, tokenfile=None)
+ self.assertFalse(bz.logged_in, "Login state check failed for logged out user.")
+
+ bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf)
+ self.assertTrue(bz.logged_in, "Login state check failed for logged in user.")
+
+
def test11UserUpdate(self):
# This won't work if run by the same user we are using
bz = self.bzclass(url=self.url, cookiefile=cf, tokenfile=tf)
--
1.9.3
9 years, 4 months
[PATCH] Add is_logged_in utility method.
by Arun Babu Neelicattu
From: Arun Babu Neelicattu <abn(a)redhat.com>
---
bugzilla/base.py | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/bugzilla/base.py b/bugzilla/base.py
index e06223f..7aba942 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -697,6 +697,26 @@ class BugzillaBase(object):
self.password = ''
self.logged_in = False
+ def is_logged_in(self):
+ """
+ Utility method to check if this instance has already been logged in.
+
+ If the instance has its logged_in attribute set to True, this method
+ returns true. Otherwise, to test if this session is authenticated, the
+ method calls the User.get() XMLRPC method with ids set. Logged-out users
+ cannot pass the 'ids' parameter and will result in a 505 error.
+ """
+ try:
+ if self.logged_in:
+ return True
+ self._proxy.User.get({'ids': self._listify([])})
+ return True
+ except Fault:
+ e = sys.exc_info()[1]
+ if e.faultCode == 505:
+ return False
+ raise e
+
#############################################
# Fetching info about the bugzilla instance #
--
1.9.3
9 years, 4 months
SSL Certificate Verification
by Mildred Clarke
All,
What is the recommended approach to require the verification of a self
signed SSL certificate when using python-bugzilla ? I don't see the option
to provide a custom CA file when connecting via RHBugzilla44.
I believe the reasoning for the failure I'm getting is that the Bugzilla
module is unable to verify the self signed certificate of my local Bugzilla
instance. I understand that I can enable sslverify=False to work around
this, however it is not desired in my environment. How do you provide a
bundle for verification purposes of self signed certs ? I know "requests"
has this functionality via function parameter and "REQUESTS_CA_BUNDLE"
environment variable but thus far neither seem to provide the desired
results with python-bugzilla module.
Please advise.
Thanks
Mildred
9 years, 4 months