Skip to content

Commit d925a0c

Browse files
committed
Always store principals as strings
Before, these were always UUID objects, but since #1329 this is stored as a string for session-based authentication only. To keep everything consistent, always use strings over UUID objects.
1 parent ac97462 commit d925a0c

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

tests/unit/accounts/test_auth_policy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# limitations under the License.
1212

1313
import pretend
14+
import uuid
1415

1516
from pyramid import authentication
1617
from pyramid.interfaces import IAuthenticationPolicy
@@ -74,7 +75,7 @@ def test_unauthenticated_userid_with_userid(self, monkeypatch):
7475
add_vary_cb = pretend.call_recorder(lambda *v: vary_cb)
7576
monkeypatch.setattr(auth_policy, "add_vary_callback", add_vary_cb)
7677

77-
userid = pretend.stub()
78+
userid = uuid.uuid4()
7879
service = pretend.stub(
7980
find_userid=pretend.call_recorder(lambda username: userid),
8081
)
@@ -83,7 +84,7 @@ def test_unauthenticated_userid_with_userid(self, monkeypatch):
8384
add_response_callback=pretend.call_recorder(lambda cb: None),
8485
)
8586

86-
assert policy.unauthenticated_userid(request) is userid
87+
assert policy.unauthenticated_userid(request) == str(userid)
8788
assert extract_http_basic_credentials.calls == [pretend.call(request)]
8889
assert request.find_service.calls == [
8990
pretend.call(IUserService, context=None),

tests/unit/packaging/test_models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def test_acl(self, db_session):
9595

9696
assert project.__acl__() == [
9797
(Allow, "group:admins", "admin"),
98-
(Allow, owner1.user.id, ["manage", "upload"]),
99-
(Allow, owner2.user.id, ["manage", "upload"]),
100-
(Allow, maintainer1.user.id, ["upload"]),
101-
(Allow, maintainer2.user.id, ["upload"]),
98+
(Allow, str(owner1.user.id), ["manage", "upload"]),
99+
(Allow, str(owner2.user.id), ["manage", "upload"]),
100+
(Allow, str(maintainer1.user.id), ["upload"]),
101+
(Allow, str(maintainer2.user.id), ["upload"]),
102102
]
103103

104104

warehouse/accounts/auth_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def unauthenticated_userid(self, request):
3434
# want to locate the userid from the IUserService.
3535
if username is not None:
3636
login_service = request.find_service(IUserService, context=None)
37-
return login_service.find_userid(username)
37+
return str(login_service.find_userid(username))
3838

3939

4040
class SessionAuthenticationPolicy(_SessionAuthenticationPolicy):

warehouse/packaging/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ def __acl__(self):
148148
query.all(),
149149
key=lambda x: ["Owner", "Maintainer"].index(x.role_name)):
150150
if role.role_name == "Owner":
151-
acls.append((Allow, role.user.id, ["manage", "upload"]))
151+
acls.append((Allow, str(role.user.id), ["manage", "upload"]))
152152
else:
153-
acls.append((Allow, role.user.id, ["upload"]))
153+
acls.append((Allow, str(role.user.id), ["upload"]))
154154
return acls
155155

156156
@property

0 commit comments

Comments
 (0)