Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
a3ba2662
Kaydet (Commit)
a3ba2662
authored
May 22, 2017
tarafından
Daniel Hahler
Kaydeden (comit)
Tim Graham
May 22, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #28207 -- Fixed contrib.auth.authenticate() if 'backend' is in the credentials.
Regression in
3008f30f
.
üst
266b2431
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
__init__.py
django/contrib/auth/__init__.py
+3
-2
test_auth_backends_deprecation.py
tests/auth_tests/test_auth_backends_deprecation.py
+22
-0
No files found.
django/contrib/auth/__init__.py
Dosyayı görüntüle @
a3ba2662
...
...
@@ -67,7 +67,7 @@ def authenticate(request=None, **credentials):
"""
for
backend
,
backend_path
in
_get_backends
(
return_tuples
=
True
):
try
:
user
=
_authenticate_with_backend
(
backend
,
backend_path
,
request
,
**
credentials
)
user
=
_authenticate_with_backend
(
backend
,
backend_path
,
request
,
credentials
)
except
PermissionDenied
:
# This backend says to stop in our tracks - this user should not be allowed in at all.
break
...
...
@@ -81,13 +81,14 @@ def authenticate(request=None, **credentials):
user_login_failed
.
send
(
sender
=
__name__
,
credentials
=
_clean_credentials
(
credentials
),
request
=
request
)
def
_authenticate_with_backend
(
backend
,
backend_path
,
request
,
**
credentials
):
def
_authenticate_with_backend
(
backend
,
backend_path
,
request
,
credentials
):
args
=
(
request
,)
# Does the backend accept a request argument?
try
:
inspect
.
getcallargs
(
backend
.
authenticate
,
request
,
**
credentials
)
except
TypeError
:
args
=
()
credentials
.
pop
(
'request'
,
None
)
# Does the backend accept a request keyword argument?
try
:
inspect
.
getcallargs
(
backend
.
authenticate
,
request
=
request
,
**
credentials
)
...
...
tests/auth_tests/test_auth_backends_deprecation.py
Dosyayı görüntüle @
a3ba2662
...
...
@@ -4,6 +4,7 @@ from django.contrib.auth import authenticate
from
django.test
import
SimpleTestCase
,
override_settings
mock_request
=
object
()
mock_backend
=
object
()
class
NoRequestBackend
:
...
...
@@ -19,6 +20,14 @@ class RequestNotPositionArgBackend:
assert
request
is
mock_request
class
RequestNotPositionArgWithUsedKwargBackend
:
def
authenticate
(
self
,
username
=
None
,
password
=
None
,
request
=
None
,
backend
=
None
):
assert
username
==
'username'
assert
password
==
'pass'
assert
request
is
mock_request
assert
backend
is
mock_backend
class
AcceptsRequestBackendTest
(
SimpleTestCase
):
"""
A deprecation warning is shown for backends that have an authenticate()
...
...
@@ -26,6 +35,7 @@ class AcceptsRequestBackendTest(SimpleTestCase):
"""
no_request_backend
=
'
%
s.NoRequestBackend'
%
__name__
request_not_positional_backend
=
'
%
s.RequestNotPositionArgBackend'
%
__name__
request_not_positional_with_used_kwarg_backend
=
'
%
s.RequestNotPositionArgWithUsedKwargBackend'
%
__name__
@override_settings
(
AUTHENTICATION_BACKENDS
=
[
no_request_backend
])
def
test_no_request_deprecation_warning
(
self
):
...
...
@@ -68,3 +78,15 @@ class AcceptsRequestBackendTest(SimpleTestCase):
"Update
%
s.authenticate() to accept a positional `request` "
"argument."
%
self
.
no_request_backend
)
@override_settings
(
AUTHENTICATION_BACKENDS
=
[
request_not_positional_with_used_kwarg_backend
])
def
test_handles_backend_in_kwargs
(
self
):
with
warnings
.
catch_warnings
(
record
=
True
)
as
warns
:
warnings
.
simplefilter
(
'always'
)
authenticate
(
username
=
'username'
,
password
=
'pass'
,
request
=
mock_request
,
backend
=
mock_backend
)
self
.
assertEqual
(
len
(
warns
),
1
)
self
.
assertEqual
(
str
(
warns
[
0
]
.
message
),
"In
%
s.authenticate(), move the `request` keyword argument to the "
"first positional argument."
%
self
.
request_not_positional_with_used_kwarg_backend
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment