def test_calls_pexpect_correctly(self, spawn, __): password_matches('ckuehl', 'hunter2') spawn.assert_called_with( 'kinit --no-forwardable -l0 [email protected]', timeout=10, ) child = spawn.return_value assert child.expect.mock_calls == [ mock.call.first('[email protected]\'s Password:'******'hunter2') assert child.close.called
def login(request): error = None if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] try: if (validators.user_exists(username) and utils.password_matches(username, password)): request.session['ocf_user'] = username return redirect_back(request) else: error = ( 'Authentication failed. Did you type the wrong username or password?' ) except ValueError as ex: error = 'Authentication failed: {error}'.format( error=str(ex), ) else: form = LoginForm() return render( request, 'login/ocf/login.html', { 'title': 'OCF Login', 'form': form, 'error': error, }, )
def login(request): error = None if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] try: if (validators.user_exists(username) and utils.password_matches(username, password)): request.session['ocf_user'] = username return redirect_back(request) else: error = 'Authentication failed. Did you type the wrong' + \ 'username or password?' except ValueError as ex: error = 'Authentication failed: {error}'.format( error=str(ex), ) else: form = LoginForm() return render_to_response('login.html', { 'form': form, 'error': error }, context_instance=RequestContext(request))
def login(request: HttpRequest) -> Union[HttpResponseRedirect, HttpResponse]: error = None return_to = request.GET.get('next') if return_to and _valid_return_path(return_to): request.session['login_return_path'] = return_to if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] try: if ( validators.user_exists(username) and not user_is_sorried(username) and utils.password_matches(username, password) ): session_login(request, username) return redirect_back(request) else: error = ( 'Authentication failed. Your account may be disabled, ' 'or you may have typed the wrong username or password.' ) except ValueError as ex: error = 'Authentication failed: {error}'.format( error=str(ex), ) else: form = LoginForm() return render( request, 'login/ocf/login.html', { 'title': 'OCF Login', 'form': form, 'error': error, }, )
def login(request): error = None return_to = request.GET.get('next') if return_to and _valid_return_path(return_to): request.session['login_return_path'] = return_to if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] try: if ( validators.user_exists(username) and utils.password_matches(username, password) ): session_login(request, username) return redirect_back(request) else: error = ( 'Authentication failed. Did you type the wrong username or password?' ) except ValueError as ex: error = 'Authentication failed: {error}'.format( error=str(ex), ) else: form = LoginForm() return render( request, 'login/ocf/login.html', { 'title': 'OCF Login', 'form': form, 'error': error, }, )
def test_returns_correctly(self, spawn, __, exitstatus, success): spawn.return_value.exitstatus = exitstatus assert password_matches('ckuehl', 'hunter2') == success
def test_fails_if_user_does_not_exist(self, __): with pytest.raises(ValueError): password_matches('ckuehl', 'hunter2')
def test_fails_with_bad_password(self, password): with pytest.raises(ValueError): password_matches('ckuehl', password)
def test_fails_with_bad_username(self, user): with pytest.raises(ValueError): password_matches(user, 'hunter2')