Skip to content

Commit 5a6d423

Browse files
committed
Fix alchemy Mapper error in tests. Required bringing db_request back into the test
1 parent cd922e3 commit 5a6d423

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

tests/unit/oidc/test_views.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,19 @@ def test_mint_token_from_pending_trusted_publisher_invalidates_others(
372372

373373

374374
def test_mint_token_from_oidc_only_pending_publisher_fail(monkeypatch, db_request):
375-
publisher = PendingGitHubPublisherFactory()
375+
pending_publisher = PendingGitHubPublisherFactory()
376376

377377
def _find_publisher(claims, pending=False):
378-
return publisher
378+
return pending_publisher
379379

380380
oidc_service = pretend.stub(
381381
verify_jwt_signature=pretend.call_recorder(
382382
lambda token: {"ref": "someref", "sha": "somesha"}
383383
),
384384
find_publisher=pretend.call_recorder(_find_publisher),
385-
reify_pending_publisher=pretend.call_recorder(lambda *a, **kw: publisher),
385+
reify_pending_publisher=pretend.call_recorder(
386+
lambda *a, **kw: pending_publisher
387+
),
386388
)
387389

388390
db_request.body = json.dumps(
@@ -445,7 +447,7 @@ def _find_publisher(claims, pending=False):
445447
],
446448
)
447449
def test_mint_token_from_oidc_no_pending_publisher_ok(
448-
monkeypatch, claims_in_token, claims_input
450+
monkeypatch, db_request, claims_in_token, claims_input
449451
):
450452
time = pretend.stub(time=pretend.call_recorder(lambda: 0))
451453
monkeypatch.setattr(views, "time", time)
@@ -456,15 +458,14 @@ def test_mint_token_from_oidc_no_pending_publisher_ok(
456458
)
457459

458460
publisher = GitHubPublisherFactory()
459-
460461
monkeypatch.setattr(publisher.__class__, "projects", [project])
461462
publisher.publisher_url = pretend.call_recorder(lambda **kw: "https://fake/url")
462463
# NOTE: Can't set __str__ using pretend.stub()
463464
monkeypatch.setattr(publisher.__class__, "__str__", lambda s: "fakespecifier")
464465

465466
def _find_publisher(claims, pending=False):
466467
if pending:
467-
raise errors.InvalidPublisherError
468+
return None
468469
else:
469470
return publisher
470471

@@ -487,16 +488,19 @@ def find_service(iface, **kw):
487488
return macaroon_service
488489
assert False, iface
489490

490-
request = pretend.stub(
491-
response=pretend.stub(status=None),
492-
body=json.dumps({"token": "faketoken"}),
493-
find_service=find_service,
494-
domain="fakedomain",
495-
remote_addr="0.0.0.0",
496-
flags=pretend.stub(disallow_oidc=lambda *a: False),
497-
)
491+
# request = pretend.stub(
492+
# response=pretend.stub(status=None),
493+
# body=json.dumps({"token": "faketoken"}),
494+
# find_service=find_service,
495+
# domain="fakedomain",
496+
# remote_addr="0.0.0.0",
497+
# flags=pretend.stub(disallow_oidc=lambda *a: False),
498+
# )
499+
monkeypatch.setattr(db_request, "find_service", find_service)
500+
monkeypatch.setattr(db_request, "body", json.dumps({"token": "faketoken"}))
501+
monkeypatch.setattr(db_request, "domain", "fakedomain")
498502

499-
response = views.mint_token(oidc_service, request)
503+
response = views.mint_token(oidc_service, db_request)
500504
assert response == {
501505
"success": True,
502506
"token": "raw-macaroon",
@@ -526,7 +530,7 @@ def find_service(iface, **kw):
526530
assert project.record_event.calls == [
527531
pretend.call(
528532
tag=EventTag.Project.ShortLivedAPITokenAdded,
529-
request=request,
533+
request=db_request,
530534
additional={
531535
"expires": 900,
532536
"publisher_name": "GitHub",

warehouse/oidc/services.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ def find_publisher(
294294
publisher = find_publisher_by_issuer(
295295
self.db, self.issuer_url, signed_claims, pending=pending
296296
)
297-
298297
publisher.verify_claims(signed_claims)
299298
self.metrics.increment(
300299
"warehouse.oidc.find_publisher.ok",

0 commit comments

Comments
 (0)