Skip to content

Commit 3397c7d

Browse files
woodruffwdomdfcoding
authored andcommitted
warehouse, tests: pick DB changes from pypi#11122 (pypi#11157)
* warehouse, tests: pick DB changes from pypi#11122 * warehouse: `make translations` * manage/views: remove outdated note * warehouse, tests: `Macaroon.permissions -> Macaroon.permissions_caveat` Emphasizes that this is the entire caveat, and not just the permissions body. * warehouse: `make translations` * warehouse/templates: handle stale event caveats Prior to these changes, the `caveats` field in API token events was a dictionary, not a list. * warehouse: `make translations`
1 parent 268920c commit 3397c7d

File tree

11 files changed

+201
-128
lines changed

11 files changed

+201
-128
lines changed

tests/unit/integration/github/test_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,10 @@ def metrics_increment(key):
554554
user_id = uuid.UUID(bytes=b"0" * 16)
555555
user = pretend.stub(id=user_id)
556556
database_macaroon = pretend.stub(
557-
user=user, id=12, caveats={"permissions": "user"}, description="foo"
557+
user=user,
558+
id=12,
559+
permissions_caveat={"permissions": "user", "version": 1},
560+
description="foo",
558561
)
559562

560563
find = pretend.call_recorder(lambda *a, **kw: database_macaroon)

tests/unit/macaroons/test_services.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_find_macaroon_invalid_macaroon(self, macaroon_service):
6161
def test_find_macaroon(self, user_service, macaroon_service):
6262
user = UserFactory.create()
6363
_, macaroon = macaroon_service.create_macaroon(
64-
"fake location", user.id, "fake description", {"fake": "caveats"}
64+
"fake location", user.id, "fake description", [{"permissions": "user"}]
6565
)
6666

6767
dm = macaroon_service.find_macaroon(str(macaroon.id))
@@ -72,7 +72,7 @@ def test_find_macaroon(self, user_service, macaroon_service):
7272
def test_find_from_raw(self, user_service, macaroon_service):
7373
user = UserFactory.create()
7474
serialized, macaroon = macaroon_service.create_macaroon(
75-
"fake location", user.id, "fake description", {"fake": "caveats"}
75+
"fake location", user.id, "fake description", [{"permissions": "user"}]
7676
)
7777

7878
dm = macaroon_service.find_from_raw(serialized)
@@ -116,14 +116,14 @@ def test_find_userid_malformed_macaroon(self, macaroon_service):
116116
def test_find_userid_valid_macaroon_trailinglinebreak(self, macaroon_service):
117117
user = UserFactory.create()
118118
raw_macaroon, _ = macaroon_service.create_macaroon(
119-
"fake location", user.id, "fake description", {"fake": "caveats"}
119+
"fake location", user.id, "fake description", [{"permissions": "user"}]
120120
)
121121
assert macaroon_service.find_userid(f"{raw_macaroon}\n") is None
122122

123123
def test_find_userid(self, macaroon_service):
124124
user = UserFactory.create()
125125
raw_macaroon, _ = macaroon_service.create_macaroon(
126-
"fake location", user.id, "fake description", {"fake": "caveats"}
126+
"fake location", user.id, "fake description", [{"permissions": "user"}]
127127
)
128128
user_id = macaroon_service.find_userid(raw_macaroon)
129129

@@ -159,7 +159,7 @@ def test_verify_no_macaroon(self, macaroon_service):
159159
def test_verify_invalid_macaroon(self, monkeypatch, user_service, macaroon_service):
160160
user = UserFactory.create()
161161
raw_macaroon, _ = macaroon_service.create_macaroon(
162-
"fake location", user.id, "fake description", {"fake": "caveats"}
162+
"fake location", user.id, "fake description", [{"permissions": "user"}]
163163
)
164164

165165
verifier_obj = pretend.stub(verify=pretend.call_recorder(lambda k: False))
@@ -219,7 +219,7 @@ def test_verify_malformed_macaroon(self, macaroon_service):
219219
def test_verify_valid_macaroon(self, monkeypatch, macaroon_service):
220220
user = UserFactory.create()
221221
raw_macaroon, _ = macaroon_service.create_macaroon(
222-
"fake location", user.id, "fake description", {"fake": "caveats"}
222+
"fake location", user.id, "fake description", [{"permissions": "user"}]
223223
)
224224

225225
verifier_obj = pretend.stub(verify=pretend.call_recorder(lambda k: True))
@@ -238,7 +238,7 @@ def test_verify_valid_macaroon(self, monkeypatch, macaroon_service):
238238
def test_delete_macaroon(self, user_service, macaroon_service):
239239
user = UserFactory.create()
240240
_, macaroon = macaroon_service.create_macaroon(
241-
"fake location", user.id, "fake description", {"fake": "caveats"}
241+
"fake location", user.id, "fake description", [{"permissions": "user"}]
242242
)
243243
macaroon_id = str(macaroon.id)
244244

@@ -256,7 +256,7 @@ def test_get_macaroon_by_description_no_macaroon(self, macaroon_service):
256256
def test_get_macaroon_by_description(self, macaroon_service):
257257
user = UserFactory.create()
258258
_, macaroon = macaroon_service.create_macaroon(
259-
"fake location", user.id, "fake description", {"fake": "caveats"}
259+
"fake location", user.id, "fake description", [{"permissions": "user"}]
260260
)
261261

262262
dm = macaroon_service.find_macaroon(str(macaroon.id))

tests/unit/manage/test_views.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,10 +1957,12 @@ def test_create_macaroon(self, monkeypatch):
19571957
location=request.domain,
19581958
user_id=request.user.id,
19591959
description=create_macaroon_obj.description.data,
1960-
caveats={
1961-
"permissions": create_macaroon_obj.validated_scope,
1962-
"version": 1,
1963-
},
1960+
caveats=[
1961+
{
1962+
"permissions": create_macaroon_obj.validated_scope,
1963+
"version": 1,
1964+
}
1965+
],
19641966
)
19651967
]
19661968
assert result == {
@@ -1975,10 +1977,12 @@ def test_create_macaroon(self, monkeypatch):
19751977
tag="account:api_token:added",
19761978
additional={
19771979
"description": create_macaroon_obj.description.data,
1978-
"caveats": {
1979-
"permissions": create_macaroon_obj.validated_scope,
1980-
"version": 1,
1981-
},
1980+
"caveats": [
1981+
{
1982+
"permissions": create_macaroon_obj.validated_scope,
1983+
"version": 1,
1984+
}
1985+
],
19821986
},
19831987
)
19841988
]
@@ -2044,10 +2048,12 @@ def test_create_macaroon_records_events_for_each_project(self, monkeypatch):
20442048
location=request.domain,
20452049
user_id=request.user.id,
20462050
description=create_macaroon_obj.description.data,
2047-
caveats={
2048-
"permissions": create_macaroon_obj.validated_scope,
2049-
"version": 1,
2050-
},
2051+
caveats=[
2052+
{
2053+
"permissions": create_macaroon_obj.validated_scope,
2054+
"version": 1,
2055+
}
2056+
],
20512057
)
20522058
]
20532059
assert result == {
@@ -2062,10 +2068,12 @@ def test_create_macaroon_records_events_for_each_project(self, monkeypatch):
20622068
tag="account:api_token:added",
20632069
additional={
20642070
"description": create_macaroon_obj.description.data,
2065-
"caveats": {
2066-
"permissions": create_macaroon_obj.validated_scope,
2067-
"version": 1,
2068-
},
2071+
"caveats": [
2072+
{
2073+
"permissions": create_macaroon_obj.validated_scope,
2074+
"version": 1,
2075+
}
2076+
],
20692077
},
20702078
)
20712079
]
@@ -2154,9 +2162,7 @@ def test_delete_macaroon_dangerous_redirect(self, monkeypatch):
21542162
assert macaroon_service.delete_macaroon.calls == []
21552163

21562164
def test_delete_macaroon(self, monkeypatch):
2157-
macaroon = pretend.stub(
2158-
description="fake macaroon", caveats={"version": 1, "permissions": "user"}
2159-
)
2165+
macaroon = pretend.stub(description="fake macaroon", permissions_caveat="user")
21602166
macaroon_service = pretend.stub(
21612167
delete_macaroon=pretend.call_recorder(lambda id: pretend.stub()),
21622168
find_macaroon=pretend.call_recorder(lambda id: macaroon),
@@ -2213,7 +2219,7 @@ def test_delete_macaroon(self, monkeypatch):
22132219
def test_delete_macaroon_records_events_for_each_project(self, monkeypatch):
22142220
macaroon = pretend.stub(
22152221
description="fake macaroon",
2216-
caveats={"version": 1, "permissions": {"projects": ["foo", "bar"]}},
2222+
permissions_caveat={"projects": ["foo", "bar"]},
22172223
)
22182224
macaroon_service = pretend.stub(
22192225
delete_macaroon=pretend.call_recorder(lambda id: pretend.stub()),

warehouse/integrations/github/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ def _analyze_disclosure(request, disclosure_record, origin):
251251
additional={
252252
"macaroon_id": str(database_macaroon.id),
253253
"public_url": disclosure.public_url,
254-
"permissions": database_macaroon.caveats.get("permissions", "user"),
254+
"permissions": database_macaroon.permissions_caveat.get(
255+
"permissions", "user"
256+
),
255257
"description": database_macaroon.description,
256258
},
257259
)

0 commit comments

Comments
 (0)