Skip to content

Commit 13c8be5

Browse files
authored
Merge pull request #104 from ASPP/password_prompt
rewrite password prompt using click so that we can test it
2 parents 846c199 + 1397efb commit 13c8be5

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

massmail/massmail.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def tease(msg, nmsgs):
196196
# ask for confirmation before really sending stuff
197197
rprint(f'[bold]About to send {nmsgs} email messages like the one above…[/bold]')
198198
if not rich.prompt.Confirm.ask(f'[bold]Send?[/bold]'):
199-
#if not click.confirm('Send the emails above?', default=None):
199+
# #if not click.confirm('Send the emails above?', default=None):
200200
raise click.ClickException('Aborted! We did not send anything!')
201201

202202

@@ -214,12 +214,6 @@ def server_login(server, user, password):
214214

215215
if user is not None:
216216
try:
217-
# get password if needed
218-
if password is None:
219-
password = rich.prompt.Prompt.ask(f'Enter password for '
220-
f'[bold]{user}[/bold] '
221-
f'on [bold]{servername}[/bold]',
222-
password=True)
223217
server.login(user, password)
224218
except Exception as err:
225219
raise click.ClickException(f'Can not login to {servername}: {err}')
@@ -355,6 +349,9 @@ def main(fromh, subject, server, parameter_file, body_file, bcc, cc, flip_bcc, d
355349
msgs = create_email_bodies(body, items, fromh, subject, cc, bcc, inreply_to, attachments, flip_bcc)
356350

357351
# login to the server
352+
if user and not password:
353+
prompt = 'Enter password for ' + click.style(f'{user}', bold=True) + ' on ' + click.style(f'{server.split(":")[0]}', bold=True)
354+
password = click.prompt(prompt, hide_input=True)
358355
server_connection = server_login(server, user, password)
359356

360357
# do the real work

massmail/test_massmail.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ def test_server_wrong_authentication(server, parm, body):
436436
opts = {'--user' : 'noone', '--password' : 'nopass' }
437437
assert 'Can not login' in cli(server, parm, body, opts=opts, errs=True)
438438

439+
def test_password_prompt(server, parm, body):
440+
opts = {'--user' : 'noone'}
441+
assert 'Can not login' in cli(server, parm, body, opts=opts, input='wrong\n', errs=True)
442+
439443
def test_server_notls(server_notls, parm, body):
440444
opts = {'--server' : '127.0.0.1:8026' }
441445
assert 'Could not STARTTLS' in cli(server_notls, parm, body, opts=opts, errs=True)

0 commit comments

Comments
 (0)