[Django] #27542: Testclients force_login should be smarter about which authentication backend is used

8 views
Skip to first unread message

Django

unread,
Nov 28, 2016, 8:59:18 AM11/28/16
to django-...@googlegroups.com
#27542: Testclients force_login should be smarter about which authentication
backend is used
---------------------------------------------+------------------------
Reporter: Tom | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
In the current code if no `backend` is passed to the
TestClient.force_login it simply uses the first one:

https://github.com/django/django/blob/master/django/test/client.py#L635

I think this could be improved. Libraries like `django-rules` are
implemented as an authentication backend but don't implement a `get_user`
method. This leads to confusing errors, as described in this ticket:
https://github.com/dfunckt/django-rules/issues/46

Perhaps rather than doing `backend = settings.AUTHENTICATION_BACKENDS[0]`
it could filter out backends that don't implement a `get_user` method, or
follow the usual chain of authentication backends (i.e skipping ones that
return None)?

--
Ticket URL: <https://code.djangoproject.com/ticket/27542>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 28, 2016, 10:15:18 AM11/28/16
to django-...@googlegroups.com
#27542: Client.force_login() shouldn't use authentication backends without a
get_user() method
--------------------------------------+------------------------------------
Reporter: Tom | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* type: New feature => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27542#comment:1>

Django

unread,
Nov 28, 2016, 6:01:47 PM11/28/16
to django-...@googlegroups.com
#27542: Client.force_login() shouldn't use authentication backends without a
get_user() method
--------------------------------------+------------------------------------
Reporter: Tom | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Testing framework | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Daniel Hahler):

* cc: django@… (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/27542#comment:2>

Django

unread,
Nov 29, 2016, 2:35:50 PM11/29/16
to django-...@googlegroups.com
#27542: Client.force_login() shouldn't use authentication backends without a
get_user() method
--------------------------------------+------------------------------------
Reporter: Tom | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Testing framework | Version: master

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* cc: desecho@… (added)
* has_patch: 0 => 1
* version: 1.10 => master


Comment:

Added [https://github.com/django/django/pull/7634 PR].

--
Ticket URL: <https://code.djangoproject.com/ticket/27542#comment:3>

Django

unread,
Dec 1, 2016, 10:27:00 AM12/1/16
to django-...@googlegroups.com
#27542: Client.force_login() shouldn't use authentication backends without a
get_user() method
--------------------------------------+------------------------------------
Reporter: Tom | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"47744a0a4ed0b9e2d3f52de65abcf6cef9a14e31" 47744a0a]:
{{{
#!CommitTicketReference repository=""
revision="47744a0a4ed0b9e2d3f52de65abcf6cef9a14e31"
Fixed #27542 -- Made Client.force_login() skip auth backends without
get_user().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27542#comment:4>

Reply all
Reply to author
Forward
0 new messages