Skip to content

Commit 8c6c45f

Browse files
authored
Disable staging in tests (#993)
* tests: Refactor signer_and_ident fixture * Do the parametrization in the test: this sets marks (e.g. "staging" and "production") that we can use to skip tests * Provide the environment name to the fixture as argument Signed-off-by: Jussi Kukkonen <jkukkonen@google.com> * tests: Add ability to skip staging * Mark tests that use staging infra in some way with "staging" * Only leave "online" to tests that require network in some other way * When --skip-online is give, skip "staging", "production" and "online" tests * When --skip-staging is given, skip all "staging" tests Signed-off-by: Jussi Kukkonen <jkukkonen@google.com> * workflows: Skip staging temporarily The staging infra is having a moment this week as rekor keeps responding with 50x. Disable staging for now. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com> * tests: lint fixes Signed-off-by: Jussi Kukkonen <jkukkonen@google.com> * tests: Remove a debug fixture Signed-off-by: Jussi Kukkonen <jkukkonen@google.com> --------- Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 7e7cb04 commit 8c6c45f

File tree

4 files changed

+63
-37
lines changed

4 files changed

+63
-37
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
unshare --map-root-user --net make test TEST_ARGS="--skip-online -vv --showlocals"
5252
5353
- name: test
54-
run: make test TEST_ARGS="-vv --showlocals"
54+
run: make test TEST_ARGS="-vv --showlocals --skip-staging"
5555

5656
- name: test (interactive)
5757
if: (github.event_name != 'pull_request') || !github.event.pull_request.head.repo.fork

test/unit/conftest.py

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,44 @@ def pytest_addoption(parser):
8484
action="store_true",
8585
help="skip tests that require network connectivity",
8686
)
87+
parser.addoption(
88+
"--skip-staging",
89+
action="store_true",
90+
help="skip tests that require Sigstore staging infrastructure",
91+
)
8792

8893

8994
def pytest_runtest_setup(item):
90-
if "online" in item.keywords and item.config.getoption("--skip-online"):
95+
# Do we need a network connection?
96+
online = False
97+
for mark in ["online", "staging", "production"]:
98+
if mark in item.keywords:
99+
online = True
100+
101+
if online and item.config.getoption("--skip-online"):
91102
pytest.skip(
92103
"skipping test that requires network connectivity due to `--skip-online` flag"
93104
)
94105
elif "ambient_oidc" in item.keywords and not _has_oidc_id():
95106
pytest.skip("skipping test that requires an ambient OIDC credential")
96107

108+
if "staging" in item.keywords and item.config.getoption("--skip-staging"):
109+
pytest.skip(
110+
"skipping test that requires staging infrastructure due to `--skip-staging` flag"
111+
)
112+
97113

98114
def pytest_configure(config):
99115
config.addinivalue_line(
100-
"markers", "online: mark test as requiring network connectivity"
116+
"markers", "staging: mark test as requiring Sigstore staging infrastructure"
117+
)
118+
config.addinivalue_line(
119+
"markers",
120+
"production: mark test as requiring Sigstore production infrastructure",
121+
)
122+
config.addinivalue_line(
123+
"markers",
124+
"online: mark test as requiring network connectivity (but not a specific Sigstore infrastructure)",
101125
)
102126
config.addinivalue_line(
103127
"markers", "ambient_oidc: mark test as requiring an ambient OIDC identity"
@@ -236,22 +260,23 @@ def tuf_dirs(monkeypatch, tmp_path):
236260
return (data_dir, cache_dir)
237261

238262

239-
@pytest.fixture(
240-
params=[
241-
("production", SigningContext.production),
242-
("staging", SigningContext.staging),
243-
],
244-
ids=["production", "staging"],
245-
)
246-
def signer_and_ident(request) -> tuple[type[SigningContext], type[IdentityToken]]:
247-
env, signer = request.param
248-
# Detect env variable for local interactive tests.
263+
@pytest.fixture
264+
def sign_ctx_and_ident_for_env(
265+
env: str,
266+
) -> tuple[type[SigningContext], type[IdentityToken]]:
267+
if env == "staging":
268+
ctx_cls = SigningContext.staging
269+
elif env == "production":
270+
ctx_cls = SigningContext.production
271+
else:
272+
raise ValueError(f"Unknown env {env}")
273+
249274
token = os.getenv(f"SIGSTORE_IDENTITY_TOKEN_{env}")
250275
if not token:
251276
# If the variable is not defined, try getting an ambient token.
252277
token = detect_credential(_DEFAULT_AUDIENCE)
253278

254-
return signer, IdentityToken(token)
279+
return ctx_cls, IdentityToken(token)
255280

256281

257282
@pytest.fixture

test/unit/test_sign.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@
2828

2929

3030
class TestSigningContext:
31-
@pytest.mark.online
31+
@pytest.mark.production
3232
def test_production(self):
3333
assert SigningContext.production() is not None
3434

3535
def test_staging(self, mock_staging_tuf):
3636
assert SigningContext.staging() is not None
3737

3838

39-
@pytest.mark.online
39+
@pytest.mark.parametrize("env", ["staging", "production"])
4040
@pytest.mark.ambient_oidc
41-
def test_sign_rekor_entry_consistent(signer_and_ident):
42-
ctx_cls, identity = signer_and_ident
41+
def test_sign_rekor_entry_consistent(sign_ctx_and_ident_for_env):
42+
ctx_cls, identity = sign_ctx_and_ident_for_env
4343

4444
# NOTE: The actual signer instance is produced lazily, so that parameter
4545
# expansion doesn't fail in offline tests.
@@ -58,10 +58,10 @@ def test_sign_rekor_entry_consistent(signer_and_ident):
5858
assert expected_entry.log_index == actual_entry.log_index
5959

6060

61-
@pytest.mark.online
61+
@pytest.mark.parametrize("env", ["staging", "production"])
6262
@pytest.mark.ambient_oidc
63-
def test_sct_verify_keyring_lookup_error(signer_and_ident, monkeypatch):
64-
ctx, identity = signer_and_ident
63+
def test_sct_verify_keyring_lookup_error(sign_ctx_and_ident_for_env, monkeypatch):
64+
ctx, identity = sign_ctx_and_ident_for_env
6565

6666
# a signer whose keyring always fails to lookup a given key.
6767
ctx: SigningContext = ctx()
@@ -77,10 +77,10 @@ def test_sct_verify_keyring_lookup_error(signer_and_ident, monkeypatch):
7777
signer.sign_artifact(payload)
7878

7979

80-
@pytest.mark.online
80+
@pytest.mark.parametrize("env", ["staging", "production"])
8181
@pytest.mark.ambient_oidc
82-
def test_sct_verify_keyring_error(signer_and_ident, monkeypatch):
83-
ctx, identity = signer_and_ident
82+
def test_sct_verify_keyring_error(sign_ctx_and_ident_for_env, monkeypatch):
83+
ctx, identity = sign_ctx_and_ident_for_env
8484

8585
# a signer whose keyring throws an internal error.
8686
ctx: SigningContext = ctx()
@@ -98,10 +98,10 @@ def test_sct_verify_keyring_error(signer_and_ident, monkeypatch):
9898
signer.sign_artifact(payload)
9999

100100

101-
@pytest.mark.online
101+
@pytest.mark.parametrize("env", ["staging", "production"])
102102
@pytest.mark.ambient_oidc
103-
def test_identity_proof_claim_lookup(signer_and_ident, monkeypatch):
104-
ctx_cls, identity = signer_and_ident
103+
def test_identity_proof_claim_lookup(sign_ctx_and_ident_for_env, monkeypatch):
104+
ctx_cls, identity = sign_ctx_and_ident_for_env
105105

106106
ctx: SigningContext = ctx_cls()
107107
assert identity is not None
@@ -121,7 +121,7 @@ def test_identity_proof_claim_lookup(signer_and_ident, monkeypatch):
121121
assert expected_entry.log_index == actual_entry.log_index
122122

123123

124-
@pytest.mark.online
124+
@pytest.mark.staging
125125
@pytest.mark.ambient_oidc
126126
def test_sign_prehashed(staging):
127127
sign_ctx_cls, verifier_cls, identity = staging
@@ -146,7 +146,7 @@ def test_sign_prehashed(staging):
146146
verifier.verify_artifact(hashed, bundle=bundle, policy=UnsafeNoOp())
147147

148148

149-
@pytest.mark.online
149+
@pytest.mark.staging
150150
@pytest.mark.ambient_oidc
151151
def test_sign_dsse(staging):
152152
sign_ctx, _, identity = staging

test/unit/verify/test_verifier.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from sigstore.verify.verifier import Verifier
2626

2727

28-
@pytest.mark.online
28+
@pytest.mark.production
2929
def test_verifier_production():
3030
verifier = Verifier.production()
3131
assert verifier is not None
@@ -36,7 +36,7 @@ def test_verifier_staging(mock_staging_tuf):
3636
assert verifier is not None
3737

3838

39-
@pytest.mark.online
39+
@pytest.mark.staging
4040
def test_verifier_one_verification(signing_materials, null_policy):
4141
verifier = Verifier.staging()
4242

@@ -45,6 +45,7 @@ def test_verifier_one_verification(signing_materials, null_policy):
4545
verifier.verify_artifact(file.read_bytes(), bundle, null_policy)
4646

4747

48+
@pytest.mark.staging
4849
def test_verifier_inconsistent_log_entry(signing_bundle, null_policy, mock_staging_tuf):
4950
(file, bundle) = signing_bundle("bundle_cve_2022_36056.txt")
5051

@@ -57,7 +58,7 @@ def test_verifier_inconsistent_log_entry(signing_bundle, null_policy, mock_stagi
5758
verifier.verify_artifact(file.read_bytes(), bundle, null_policy)
5859

5960

60-
@pytest.mark.online
61+
@pytest.mark.staging
6162
def test_verifier_multiple_verifications(signing_materials, null_policy):
6263
verifier = Verifier.staging()
6364

@@ -78,7 +79,7 @@ def test_verifier_bundle(signing_bundle, null_policy, mock_staging_tuf, filename
7879
verifier.verify_artifact(file.read_bytes(), bundle, null_policy)
7980

8081

81-
@pytest.mark.online
82+
@pytest.mark.staging
8283
def test_verifier_email_identity(signing_materials):
8384
verifier = Verifier.staging()
8485

@@ -95,7 +96,7 @@ def test_verifier_email_identity(signing_materials):
9596
)
9697

9798

98-
@pytest.mark.online
99+
@pytest.mark.staging
99100
def test_verifier_uri_identity(signing_materials):
100101
verifier = Verifier.staging()
101102
(file, bundle) = signing_materials("c.txt", verifier._rekor)
@@ -114,7 +115,7 @@ def test_verifier_uri_identity(signing_materials):
114115
)
115116

116117

117-
@pytest.mark.online
118+
@pytest.mark.staging
118119
def test_verifier_policy_check(signing_materials):
119120
verifier = Verifier.staging()
120121
(file, bundle) = signing_materials("a.txt", verifier._rekor)
@@ -130,7 +131,7 @@ def test_verifier_policy_check(signing_materials):
130131
)
131132

132133

133-
@pytest.mark.online
134+
@pytest.mark.staging
134135
@pytest.mark.xfail
135136
def test_verifier_fail_expiry(signing_materials, null_policy, monkeypatch):
136137
# FIXME(jl): can't mock:
@@ -151,7 +152,7 @@ def test_verifier_fail_expiry(signing_materials, null_policy, monkeypatch):
151152
verifier.verify_artifact(file.read_bytes(), bundle, null_policy)
152153

153154

154-
@pytest.mark.online
155+
@pytest.mark.staging
155156
@pytest.mark.ambient_oidc
156157
def test_verifier_dsse_roundtrip(staging):
157158
signer_cls, verifier_cls, identity = staging

0 commit comments

Comments
 (0)