11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
+ from functools import partial
14
15
from pathlib import Path
15
16
from typing import Optional
16
17
17
18
import pytest
18
19
20
+ from sigstore ._internal .trust import ClientTrustConfig
19
21
from sigstore .models import Bundle
20
22
from sigstore .verify import Verifier
21
23
from sigstore .verify .policy import UnsafeNoOp
22
24
23
25
24
- def get_cli_params (
26
+ def _get_cli_params (
25
27
artifact_paths : list [Path ],
26
28
overwrite : bool = False ,
27
29
no_default_files : bool = False ,
28
30
output_directory : Optional [Path ] = None ,
29
31
bundle_path : Optional [Path ] = None ,
30
32
signature_path : Optional [Path ] = None ,
31
33
certificate_path : Optional [Path ] = None ,
34
+ trust_config_path : Optional [Path ] = None ,
32
35
) -> list [str ]:
33
- cli_params = ["--staging" , "sign" ]
36
+ if trust_config_path is not None :
37
+ cli_params = ["--trust-config" , str (trust_config_path ), "sign" ]
38
+ else :
39
+ cli_params = ["--staging" , "sign" ]
34
40
if output_directory is not None :
35
41
cli_params .extend (["--output-directory" , str (output_directory )])
36
42
if bundle_path is not None :
@@ -49,6 +55,52 @@ def get_cli_params(
49
55
return cli_params
50
56
51
57
58
+ @pytest .fixture (params = [
59
+ True , False
60
+ ])
61
+ def get_cli_params (request , asset ) -> callable :
62
+ """
63
+ """
64
+ if request .param :
65
+ return _get_cli_params
66
+ return partial (_get_cli_params , trust_config_path = asset ("tsa/trust_config.rekorv2_alpha.json" ))
67
+
68
+
69
+ @pytest .mark .ambient_oidc
70
+ def test_sign_success_default_output_bundle_with_trust_config (
71
+ capsys , sigstore , asset_integration , asset
72
+ ):
73
+ artifact = asset_integration ("a.txt" )
74
+ expected_output_bundle = artifact .with_name ("a.txt.sigstore.json" )
75
+
76
+ trust_config = asset ("tsa/trust_config.rekorv2_alpha.json" )
77
+
78
+ assert not expected_output_bundle .exists ()
79
+ sigstore (
80
+ * _get_cli_params (artifact_paths = [artifact ], trust_config_path = trust_config ))
81
+
82
+ assert expected_output_bundle .exists ()
83
+ verifier = Verifier (
84
+ trusted_root = ClientTrustConfig .from_json (
85
+ trust_config .read_text ()).trusted_root
86
+ )
87
+ with (
88
+ open (expected_output_bundle , "r" ) as bundle_file ,
89
+ open (artifact , "rb" ) as input_file ,
90
+ ):
91
+ bundle = Bundle .from_json (bundle_file .read ())
92
+ verifier .verify_artifact (
93
+ input_ = input_file .read (), bundle = bundle , policy = UnsafeNoOp ()
94
+ )
95
+
96
+ expected_output_bundle .unlink ()
97
+
98
+ captures = capsys .readouterr ()
99
+ assert captures .out .endswith (
100
+ f"Sigstore bundle written to { expected_output_bundle } \n "
101
+ )
102
+
103
+
52
104
@pytest .mark .staging
53
105
@pytest .mark .ambient_oidc
54
106
def test_sign_success_default_output_bundle (capsys , sigstore , asset_integration ):
@@ -57,7 +109,7 @@ def test_sign_success_default_output_bundle(capsys, sigstore, asset_integration)
57
109
58
110
assert not expected_output_bundle .exists ()
59
111
sigstore (
60
- * get_cli_params (
112
+ * _get_cli_params (
61
113
artifact_paths = [artifact ],
62
114
)
63
115
)
@@ -83,7 +135,7 @@ def test_sign_success_default_output_bundle(capsys, sigstore, asset_integration)
83
135
84
136
@pytest .mark .staging
85
137
@pytest .mark .ambient_oidc
86
- def test_sign_success_custom_outputs (capsys , sigstore , asset_integration , tmp_path ):
138
+ def test_sign_success_custom_outputs (capsys , sigstore , asset_integration , tmp_path , get_cli_params ):
87
139
artifact = asset_integration ("a.txt" )
88
140
output_bundle = tmp_path / "bundle.json"
89
141
output_cert = tmp_path / "cert.cert"
@@ -110,7 +162,7 @@ def test_sign_success_custom_outputs(capsys, sigstore, asset_integration, tmp_pa
110
162
111
163
@pytest .mark .staging
112
164
@pytest .mark .ambient_oidc
113
- def test_sign_success_custom_output_dir (capsys , sigstore , asset_integration , tmp_path ):
165
+ def test_sign_success_custom_output_dir (capsys , sigstore , asset_integration , tmp_path , get_cli_params ):
114
166
artifact = asset_integration ("a.txt" )
115
167
expected_output_bundle = tmp_path / "a.txt.sigstore.json"
116
168
@@ -131,7 +183,7 @@ def test_sign_success_custom_output_dir(capsys, sigstore, asset_integration, tmp
131
183
132
184
@pytest .mark .staging
133
185
@pytest .mark .ambient_oidc
134
- def test_sign_success_no_default_files (capsys , sigstore , asset_integration , tmp_path ):
186
+ def test_sign_success_no_default_files (capsys , sigstore , asset_integration , tmp_path , get_cli_params ):
135
187
artifact = asset_integration ("a.txt" )
136
188
default_output_bundle = tmp_path / "a.txt.sigstore.json"
137
189
output_cert = tmp_path / "cert.cert"
@@ -157,7 +209,7 @@ def test_sign_success_no_default_files(capsys, sigstore, asset_integration, tmp_
157
209
158
210
@pytest .mark .staging
159
211
@pytest .mark .ambient_oidc
160
- def test_sign_overwrite_existing_bundle (capsys , sigstore , asset_integration ):
212
+ def test_sign_overwrite_existing_bundle (capsys , sigstore , asset_integration , get_cli_params ):
161
213
artifact = asset_integration ("a.txt" )
162
214
expected_output_bundle = artifact .with_name ("a.txt.sigstore.json" )
163
215
@@ -196,7 +248,7 @@ def test_sign_overwrite_existing_bundle(capsys, sigstore, asset_integration):
196
248
197
249
198
250
def test_sign_fails_with_default_files_and_bundle_options (
199
- capsys , sigstore , asset_integration
251
+ capsys , sigstore , asset_integration , get_cli_params
200
252
):
201
253
artifact = asset_integration ("a.txt" )
202
254
output_bundle = artifact .with_name ("a.txt.sigstore.json" )
@@ -218,7 +270,7 @@ def test_sign_fails_with_default_files_and_bundle_options(
218
270
219
271
220
272
def test_sign_fails_with_multiple_inputs_and_custom_output (
221
- capsys , sigstore , asset_integration
273
+ capsys , sigstore , asset_integration , get_cli_params
222
274
):
223
275
artifact = asset_integration ("a.txt" )
224
276
@@ -263,7 +315,7 @@ def test_sign_fails_with_multiple_inputs_and_custom_output(
263
315
264
316
265
317
def test_sign_fails_with_output_dir_and_custom_output_files (
266
- capsys , sigstore , asset_integration
318
+ capsys , sigstore , asset_integration , get_cli_params
267
319
):
268
320
artifact = asset_integration ("a.txt" )
269
321
@@ -311,7 +363,7 @@ def test_sign_fails_with_output_dir_and_custom_output_files(
311
363
312
364
313
365
def test_sign_fails_without_both_output_cert_and_signature (
314
- capsys , sigstore , asset_integration
366
+ capsys , sigstore , asset_integration , get_cli_params
315
367
):
316
368
artifact = asset_integration ("a.txt" )
317
369
0 commit comments