diff --git a/ocflib/account/utils.py b/ocflib/account/utils.py index ca12021..b1ff6f1 100644 --- a/ocflib/account/utils.py +++ b/ocflib/account/utils.py @@ -24,7 +24,12 @@ def password_matches(username, password): child.expect("{}@OCF.BERKELEY.EDU's Password:".format(username)) child.sendline(password) - child.expect(pexpect.EOF) + result = child.expect([pexpect.EOF, 'expired']) + + if (result == 1): + child.close() + raise ValueError("User's password has expired") + child.close() return child.exitstatus == 0 diff --git a/tests/account/utils_test.py b/tests/account/utils_test.py index 5d52a2d..3ef2329 100644 --- a/tests/account/utils_test.py +++ b/tests/account/utils_test.py @@ -53,7 +53,7 @@ def test_calls_pexpect_correctly(self, spawn, __): assert child.expect.mock_calls == [ mock.call.first('ckuehl@OCF.BERKELEY.EDU\'s Password:'), - mock.call.second(pexpect.EOF), + mock.call.second([pexpect.EOF, 'expired']), ] child.sendline.assert_called_with('hunter2') assert child.close.called