File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414
1515.PHONY : test
1616test :
17- uvx --with=requests --with-requirements=action.py pytest test.py
17+ uvx --with=requests --with-requirements=action.py pytest -s -o log_cli=true -o log_cli_level=DEBUG test.py
Original file line number Diff line number Diff line change 1+ import logging
12import subprocess
3+ import time
24import uuid
35from pathlib import Path
46
810
911import action
1012
13+ logger = logging .getLogger (__name__ )
14+
1115
1216@pytest .fixture (scope = "session" )
1317def id_token () -> oidc .IdentityToken :
14- resp = requests .get (
15- "https://raw.githubusercontent.com/sigstore-conformance/extremely-dangerous-public-oidc-beacon/refs/heads/current-token/oidc-token.txt" ,
16- params = {"cachebuster" : uuid .uuid4 ().hex },
17- )
18- resp .raise_for_status ()
19- id_token = resp .text .strip ()
20- return oidc .IdentityToken (id_token )
18+ def _id_token () -> oidc .IdentityToken | None :
19+ # GitHub loves to cache things it has no business caching.
20+ result = subprocess .run (
21+ [
22+ "git" ,
23+ "ls-remote" ,
24+ "https://github.com/sigstore-conformance/extremely-dangerous-public-oidc-beacon" ,
25+ "refs/heads/current-token" ,
26+ ],
27+ capture_output = True ,
28+ text = True ,
29+ check = True ,
30+ )
31+ ref = result .stdout .split ()[0 ]
32+
33+ resp = requests .get (
34+ f"https://raw.githubusercontent.com/sigstore-conformance/extremely-dangerous-public-oidc-beacon/{ ref } /oidc-token.txt" ,
35+ )
36+ resp .raise_for_status ()
37+ id_token = resp .text .strip ()
38+ try :
39+ return oidc .IdentityToken (id_token )
40+ except Exception :
41+ return None
42+
43+ # Try up to 10 times to get a valid token, waiting 3 seconds between attempts.
44+ for n in range (10 ):
45+ token = _id_token ()
46+ if token is not None :
47+ return token
48+ else :
49+ logger .warning (f"Waiting for valid OIDC identity token, try { n } ..." )
50+ time .sleep (3 )
51+
52+ raise RuntimeError ("Failed to obtain OIDC identity token for tests" )
2153
2254
2355@pytest .fixture
You can’t perform that action at this time.
0 commit comments