Skip to content

Commit e54e1d9

Browse files
committed
tests: Add a bunch more login tests
1 parent 475ab0a commit e54e1d9

3 files changed

Lines changed: 47 additions & 8 deletions

File tree

bugzilla/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
1010
# the full text of the license.
1111

12+
import getpass
1213
import locale
1314
from logging import getLogger
1415
import os
1516
import sys
1617

17-
from getpass import getpass
1818
from io import BytesIO
1919

2020
if hasattr(sys.version_info, "major") and sys.version_info.major >= 3:
@@ -670,7 +670,7 @@ def interactive_login(self, user=None, password=None, force=False):
670670
sys.stdout.write('Bugzilla Username: ')
671671
user = sys.stdin.readline().strip()
672672
if not password:
673-
password = getpass('Bugzilla Password: ')
673+
password = getpass.getpass('Bugzilla Password: ')
674674

675675
log.info('Logging in... ')
676676
self.login(user, password)

tests/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def difffile(expect, filename):
5757

5858

5959
def clicomm(argv, bzinstance, returnmain=False, printcliout=False,
60-
stdin=None, expectfail=False):
60+
stdin=None, stdinstr=None, expectfail=False):
6161
"""
6262
Run bin/bugzilla.main() directly with passed argv
6363
"""
@@ -75,6 +75,9 @@ def clicomm(argv, bzinstance, returnmain=False, printcliout=False,
7575
sys.stderr = out
7676
if stdin:
7777
sys.stdin = stdin
78+
elif stdinstr:
79+
sys.stdin = StringIO(stdinstr)
80+
7881
sys.argv = argv
7982

8083
ret = 0

tests/rw_functional.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,47 @@ def test10Login(self):
625625
"""
626626
Failed login test, gives us a bit more coverage
627627
"""
628-
ret = tests.clicomm("bugzilla --bugzilla %s "
629-
630-
"--password foobar login" % self.url, None,
631-
expectfail=True)
632-
self.assertTrue("Login failed: " in ret)
628+
# We overwrite getpass for testing
629+
import getpass
630+
631+
def fakegetpass(prompt):
632+
sys.stdout.write(prompt)
633+
sys.stdout.flush()
634+
return sys.stdin.readline()
635+
oldgetpass = getpass.getpass
636+
getpass.getpass = fakegetpass
637+
638+
try:
639+
# Implied login with --username and --password
640+
ret = tests.clicomm("bugzilla --bugzilla %s "
641+
642+
"--password foobar query -b 123456" % self.url,
643+
None, expectfail=True)
644+
self.assertTrue("Login failed: " in ret)
645+
646+
# 'login' with explicit options
647+
ret = tests.clicomm("bugzilla --bugzilla %s "
648+
649+
"--password foobar login" % self.url,
650+
None, expectfail=True)
651+
self.assertTrue("Login failed: " in ret)
652+
653+
# 'login' with positional options
654+
ret = tests.clicomm("bugzilla --bugzilla %s "
655+
"login [email protected] foobar" % self.url,
656+
None, expectfail=True)
657+
self.assertTrue("Login failed: " in ret)
658+
659+
660+
# bare 'login'
661+
stdinstr = "[email protected]\n\rfoobar\n\r"
662+
ret = tests.clicomm("bugzilla --bugzilla %s login" % self.url,
663+
None, expectfail=True, stdinstr=stdinstr)
664+
self.assertTrue("Bugzilla Username:" in ret)
665+
self.assertTrue("Bugzilla Password:" in ret)
666+
self.assertTrue("Login failed: " in ret)
667+
finally:
668+
getpass.getpass = oldgetpass
633669

634670

635671
def test10LoginState(self):

0 commit comments

Comments
 (0)