Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warehouse, tests: pick DB changes from #11122 #11157

Merged
merged 7 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/unit/integration/github/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ def metrics_increment(key):
user_id = uuid.UUID(bytes=b"0" * 16)
user = pretend.stub(id=user_id)
database_macaroon = pretend.stub(
user=user, id=12, caveats={"permissions": "user"}, description="foo"
user=user, id=12, permissions="user", description="foo"
)

find = pretend.call_recorder(lambda *a, **kw: database_macaroon)
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/macaroons/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_find_macaroon_invalid_macaroon(self, macaroon_service):
def test_find_macaroon(self, user_service, macaroon_service):
user = UserFactory.create()
_, macaroon = macaroon_service.create_macaroon(
"fake location", user.id, "fake description", {"fake": "caveats"}
"fake location", user.id, "fake description", [{"permissions": "user"}]
)

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

dm = macaroon_service.find_from_raw(serialized)
Expand Down Expand Up @@ -116,14 +116,14 @@ def test_find_userid_malformed_macaroon(self, macaroon_service):
def test_find_userid_valid_macaroon_trailinglinebreak(self, macaroon_service):
user = UserFactory.create()
raw_macaroon, _ = macaroon_service.create_macaroon(
"fake location", user.id, "fake description", {"fake": "caveats"}
"fake location", user.id, "fake description", [{"permissions": "user"}]
)
assert macaroon_service.find_userid(f"{raw_macaroon}\n") is None

def test_find_userid(self, macaroon_service):
user = UserFactory.create()
raw_macaroon, _ = macaroon_service.create_macaroon(
"fake location", user.id, "fake description", {"fake": "caveats"}
"fake location", user.id, "fake description", [{"permissions": "user"}]
)
user_id = macaroon_service.find_userid(raw_macaroon)

Expand Down Expand Up @@ -159,7 +159,7 @@ def test_verify_no_macaroon(self, macaroon_service):
def test_verify_invalid_macaroon(self, monkeypatch, user_service, macaroon_service):
user = UserFactory.create()
raw_macaroon, _ = macaroon_service.create_macaroon(
"fake location", user.id, "fake description", {"fake": "caveats"}
"fake location", user.id, "fake description", [{"permissions": "user"}]
)

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

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

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

dm = macaroon_service.find_macaroon(str(macaroon.id))
Expand Down
46 changes: 26 additions & 20 deletions tests/unit/manage/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1957,10 +1957,12 @@ def test_create_macaroon(self, monkeypatch):
location=request.domain,
user_id=request.user.id,
description=create_macaroon_obj.description.data,
caveats={
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
},
caveats=[
{
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
}
],
)
]
assert result == {
Expand All @@ -1975,10 +1977,12 @@ def test_create_macaroon(self, monkeypatch):
tag="account:api_token:added",
additional={
"description": create_macaroon_obj.description.data,
"caveats": {
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
},
"caveats": [
{
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
}
],
},
)
]
Expand Down Expand Up @@ -2044,10 +2048,12 @@ def test_create_macaroon_records_events_for_each_project(self, monkeypatch):
location=request.domain,
user_id=request.user.id,
description=create_macaroon_obj.description.data,
caveats={
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
},
caveats=[
{
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
}
],
)
]
assert result == {
Expand All @@ -2062,10 +2068,12 @@ def test_create_macaroon_records_events_for_each_project(self, monkeypatch):
tag="account:api_token:added",
additional={
"description": create_macaroon_obj.description.data,
"caveats": {
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
},
"caveats": [
{
"permissions": create_macaroon_obj.validated_scope,
"version": 1,
}
],
},
)
]
Expand Down Expand Up @@ -2154,9 +2162,7 @@ def test_delete_macaroon_dangerous_redirect(self, monkeypatch):
assert macaroon_service.delete_macaroon.calls == []

def test_delete_macaroon(self, monkeypatch):
macaroon = pretend.stub(
description="fake macaroon", caveats={"version": 1, "permissions": "user"}
)
macaroon = pretend.stub(description="fake macaroon", permissions="user")
macaroon_service = pretend.stub(
delete_macaroon=pretend.call_recorder(lambda id: pretend.stub()),
find_macaroon=pretend.call_recorder(lambda id: macaroon),
Expand Down Expand Up @@ -2213,7 +2219,7 @@ def test_delete_macaroon(self, monkeypatch):
def test_delete_macaroon_records_events_for_each_project(self, monkeypatch):
macaroon = pretend.stub(
description="fake macaroon",
caveats={"version": 1, "permissions": {"projects": ["foo", "bar"]}},
permissions={"projects": ["foo", "bar"]},
)
macaroon_service = pretend.stub(
delete_macaroon=pretend.call_recorder(lambda id: pretend.stub()),
Expand Down
2 changes: 1 addition & 1 deletion warehouse/integrations/github/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def _analyze_disclosure(request, disclosure_record, origin):
additional={
"macaroon_id": str(database_macaroon.id),
"public_url": disclosure.public_url,
"permissions": database_macaroon.caveats.get("permissions", "user"),
"permissions": database_macaroon.permissions,
"description": database_macaroon.description,
},
)
Expand Down
Loading