Skip to content

Commit 79f967c

Browse files
abstract the signer fixture
Signed-off-by: Ramon Petgrave <[email protected]>
1 parent 53c9113 commit 79f967c

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

test/unit/internal/rekor/test_client_v2.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,25 @@ def client(request) -> RekorV2Client:
4545

4646

4747
@pytest.fixture()
48-
def sample_hashed_rekord_request_materials(
49-
staging,
50-
) -> tuple[Hashed, bytes, Certificate]:
48+
def sample_signer(staging):
5149
"""
52-
Creates materials needed for `RekorV2Client._build_hashed_rekord_create_entry_request`.
50+
Returns a `Signer`.
5351
"""
5452
sign_ctx_cls, _, id_token = staging
5553
with sign_ctx_cls().signer(id_token) as signer:
56-
cert = signer._signing_cert()
54+
return signer
5755

56+
57+
@pytest.fixture()
58+
def sample_hashed_rekord_request_materials(
59+
sample_signer,
60+
) -> tuple[Hashed, bytes, Certificate]:
61+
"""
62+
Creates materials needed for `RekorV2Client._build_hashed_rekord_create_entry_request`.
63+
"""
64+
cert = sample_signer._signing_cert()
5865
hashed_input = sha256_digest(secrets.token_bytes(32))
59-
signature = signer._private_key.sign(
66+
signature = sample_signer._private_key.sign(
6067
hashed_input.digest, ec.ECDSA(hashed_input._as_prehashed())
6168
)
6269
return hashed_input, signature, cert
@@ -104,13 +111,11 @@ def sample_create_entry_request(request) -> v2.CreateEntryRequest:
104111

105112

106113
@pytest.fixture()
107-
def sample_dsse_request_materials(staging) -> tuple[dsse.Envelope, Certificate]:
114+
def sample_dsse_request_materials(sample_signer) -> tuple[dsse.Envelope, Certificate]:
108115
"""
109116
Creates materials needed for `RekorV2Client._build_dsse_create_entry_request`.
110117
"""
111-
sign_ctx_cls, _, id_token = staging
112-
with sign_ctx_cls().signer(id_token) as signer:
113-
cert = signer._signing_cert()
118+
cert = sample_signer._signing_cert()
114119
stmt = (
115120
dsse.StatementBuilder()
116121
.subjects(
@@ -128,7 +133,7 @@ def sample_dsse_request_materials(staging) -> tuple[dsse.Envelope, Certificate]:
128133
}
129134
)
130135
).build()
131-
envelope = dsse._sign(key=signer._private_key, stmt=stmt)
136+
envelope = dsse._sign(key=sample_signer._private_key, stmt=stmt)
132137
return envelope, cert
133138

134139

0 commit comments

Comments
 (0)