Skip to content

Commit 982985a

Browse files
authored
chore: return message on basic auth usage (#15132)
1 parent 2379c5c commit 982985a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

tests/unit/accounts/test_core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import pytest
1818

1919
from celery.schedules import crontab
20-
from pyramid.httpexceptions import HTTPUnauthorized
20+
from pyramid.httpexceptions import HTTPForbidden, HTTPUnauthorized
2121

2222
from warehouse import accounts
2323
from warehouse.accounts import security_policy
@@ -325,11 +325,12 @@ def test_with_valid_password(self, monkeypatch, pyramid_request, pyramid_service
325325
)
326326

327327
pyramid_request.matched_route = pretend.stub(name="forklift.legacy.file_upload")
328+
pyramid_request.help_url = pretend.call_recorder(lambda **kw: "/the/help/url/")
328329

329330
now = datetime.datetime.utcnow()
330331

331-
with freezegun.freeze_time(now):
332-
assert _basic_auth_check("myuser", "mypass", pyramid_request) is True
332+
with freezegun.freeze_time(now), pytest.raises(HTTPForbidden):
333+
_basic_auth_check("myuser", "mypass", pyramid_request)
333334

334335
assert service.find_userid.calls == [pretend.call("myuser")]
335336
assert service.get_user.calls == [pretend.call(2)]

warehouse/accounts/security_policy.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
extract_http_basic_credentials,
1818
)
1919
from pyramid.authorization import ACLHelper
20-
from pyramid.httpexceptions import HTTPUnauthorized
20+
from pyramid.httpexceptions import HTTPForbidden, HTTPUnauthorized
2121
from pyramid.interfaces import ISecurityPolicy
2222
from pyramid.security import Allowed
2323
from zope.interface import implementer
@@ -105,7 +105,14 @@ def _basic_auth_check(username, password, request):
105105
request=request,
106106
additional={"auth_method": "basic"},
107107
)
108-
return True
108+
109+
raise _format_exc_status(
110+
HTTPForbidden(),
111+
"Username/Password authentication is no longer supported. "
112+
"Migrate to API Tokens or Trusted Publishers instead. "
113+
f"See {request.help_url(_anchor='apitoken')} "
114+
f"and {request.help_url(_anchor='trusted-publishers')}",
115+
)
109116
else:
110117
user.record_event(
111118
tag=EventTag.Account.LoginFailure,

0 commit comments

Comments
 (0)