@@ -28,6 +28,7 @@ def setUpModule():
28
28
29
29
# Since setUpModule is called after imports we need to import conditionally.
30
30
if IS_PY_VERSION_SUPPORTED :
31
+ import tuf .exceptions
31
32
from tuf .api .metadata import (
32
33
Metadata ,
33
34
Snapshot ,
@@ -152,12 +153,9 @@ def test_sign_verify(self):
152
153
153
154
# ... it has a single existing signature,
154
155
self .assertTrue (len (metadata_obj .signatures ) == 1 )
155
- # ... valid for the correct key, but
156
+ # ... which is valid for the correct key.
156
157
self .assertTrue (metadata_obj .verify (
157
158
self .keystore ['targets' ]['public' ]))
158
- # ... invalid for an unrelated key.
159
- self .assertFalse (metadata_obj .verify (
160
- self .keystore ['snapshot' ]['public' ]))
161
159
162
160
# Append a new signature with the unrelated key and assert that ...
163
161
metadata_obj .sign (self .keystore ['snapshot' ]['private' ], append = True )
@@ -177,15 +175,20 @@ def test_sign_verify(self):
177
175
self .assertTrue (metadata_obj .verify (
178
176
self .keystore ['timestamp' ]['public' ]))
179
177
180
-
181
- # Update the metadata, invalidating the existing signature, append
182
- # a new signature with the same key, and assert that ...
183
- metadata_obj .signed .bump_version ()
178
+ # Assert exception if there are more than one signatures for a key
184
179
metadata_obj .sign (self .keystore ['timestamp' ]['private' ], append = True )
185
- # ... verify returns False, because all signatures identified by a
186
- # keyid must be valid
187
- self .assertFalse (metadata_obj .verify (
188
- self .keystore ['timestamp' ]['public' ]))
180
+ with self .assertRaises (tuf .exceptions .Error ) as ctx :
181
+ metadata_obj .verify (self .keystore ['timestamp' ]['public' ])
182
+ self .assertTrue (
183
+ '2 signatures for key' in str (ctx .exception ),
184
+ str (ctx .exception ))
185
+
186
+ # Assert exception if there is no signature for a key
187
+ with self .assertRaises (tuf .exceptions .Error ) as ctx :
188
+ metadata_obj .verify (self .keystore ['targets' ]['public' ])
189
+ self .assertTrue (
190
+ 'no signature for' in str (ctx .exception ),
191
+ str (ctx .exception ))
189
192
190
193
191
194
def test_metadata_base (self ):
0 commit comments