@@ -184,7 +184,7 @@ func (rs *RepoSuite) TestGenKey(c *C) {
184184
185185 // generate a key for an unknown role
186186 _ , err = r .GenKey ("foo" )
187- c .Assert (err , Equals , ErrInvalidRole {"foo" })
187+ c .Assert (err , Equals , ErrInvalidRole {"foo" , "only support adding keys for top-level roles" })
188188
189189 // generate a root key
190190 ids := genKey (c , r , "root" )
@@ -346,7 +346,7 @@ func (rs *RepoSuite) TestAddPrivateKey(c *C) {
346346 signer , err := keys .GenerateEd25519Key ()
347347 c .Assert (err , IsNil )
348348 err = r .AddPrivateKey ("foo" , signer )
349- c .Assert (err , Equals , ErrInvalidRole {"foo" })
349+ c .Assert (err , Equals , ErrInvalidRole {"foo" , "only support adding keys for top-level roles" })
350350
351351 // add a root key
352352 ids := addPrivateKey (c , r , "root" , signer )
@@ -511,7 +511,7 @@ func (rs *RepoSuite) TestRevokeKey(c *C) {
511511 c .Assert (err , IsNil )
512512
513513 // revoking a key for an unknown role returns ErrInvalidRole
514- c .Assert (r .RevokeKey ("foo" , "" ), DeepEquals , ErrInvalidRole {"foo" })
514+ c .Assert (r .RevokeKey ("foo" , "" ), DeepEquals , ErrInvalidRole {"foo" , "only revocations for top-level roles supported" })
515515
516516 // revoking a key which doesn't exist returns ErrKeyNotFound
517517 c .Assert (r .RevokeKey ("root" , "nonexistent" ), DeepEquals , ErrKeyNotFound {"root" , "nonexistent" })
@@ -632,6 +632,8 @@ func (rs *RepoSuite) TestSign(c *C) {
632632 r , err := NewRepo (local )
633633 c .Assert (err , IsNil )
634634
635+ c .Assert (r .Sign ("foo.json" ), Equals , ErrInvalidRole {"foo" , "only signing top-level metadata supported" })
636+
635637 // signing with no keys returns ErrInsufficientKeys
636638 c .Assert (r .Sign ("root.json" ), Equals , ErrInsufficientKeys {"root.json" })
637639
@@ -676,6 +678,9 @@ func (rs *RepoSuite) TestSign(c *C) {
676678 c .Assert (local .SaveSigner ("root" , newKey ), IsNil )
677679 c .Assert (r .Sign ("root.json" ), IsNil )
678680 checkSigIDs (append (signer .PublicData ().IDs (), newKey .PublicData ().IDs ()... )... )
681+
682+ // attempt to sign missing metadata
683+ c .Assert (r .Sign ("targets.json" ), Equals , ErrMissingMetadata {"targets.json" })
679684}
680685
681686func (rs * RepoSuite ) TestCommit (c * C ) {
@@ -1386,6 +1391,12 @@ func (rs *RepoSuite) TestKeyPersistence(c *C) {
13861391 tmp = newTmpDir (c )
13871392 store = FileSystemStore (tmp .path , testPassphraseFunc )
13881393
1394+ // 1.5. Changing passphrase only works for top-level roles.
1395+ r , err := NewRepo (store )
1396+ c .Assert (err , IsNil )
1397+
1398+ c .Assert (r .ChangePassphrase ("foo" ), DeepEquals , ErrInvalidRole {"foo" , "only support passphrases for top-level roles" })
1399+
13891400 // 2. Test changing the passphrase when the keys file does not exist - should FAIL
13901401 c .Assert (store .(PassphraseChanger ).ChangePassphrase ("root" ), NotNil )
13911402
@@ -1598,6 +1609,11 @@ func (rs *RepoSuite) TestThreshold(c *C) {
15981609 r , err := NewRepo (local )
15991610 c .Assert (err , IsNil )
16001611
1612+ _ , err = r .GetThreshold ("root" )
1613+ c .Assert (err , DeepEquals , ErrInvalidRole {"root" , "role missing from root metadata" })
1614+ err = r .SetThreshold ("root" , 2 )
1615+ c .Assert (err , DeepEquals , ErrInvalidRole {"root" , "role missing from root metadata" })
1616+
16011617 // Add one key to each role
16021618 genKey (c , r , "root" )
16031619 genKey (c , r , "targets" )
@@ -1607,6 +1623,11 @@ func (rs *RepoSuite) TestThreshold(c *C) {
16071623 c .Assert (err , IsNil )
16081624 c .Assert (t , Equals , 1 )
16091625
1626+ _ , err = r .GetThreshold ("foo" )
1627+ c .Assert (err , DeepEquals , ErrInvalidRole {"foo" , "only thresholds for top-level roles supported" })
1628+ err = r .SetThreshold ("foo" , 2 )
1629+ c .Assert (err , DeepEquals , ErrInvalidRole {"foo" , "only thresholds for top-level roles supported" })
1630+
16101631 // commit the metadata to the store.
16111632 c .Assert (r .AddTargets ([]string {}, nil ), IsNil )
16121633 c .Assert (r .Snapshot (), IsNil )
@@ -1727,6 +1748,10 @@ func (rs *RepoSuite) TestBadAddOrUpdateSignatures(c *C) {
17271748 // don't use consistent snapshots to make the checks simpler
17281749 c .Assert (r .Init (false ), IsNil )
17291750
1751+ c .Assert (r .AddOrUpdateSignature ("targets.json" , data.Signature {
1752+ KeyID : "foo" ,
1753+ Signature : nil }), Equals , ErrInvalidRole {"targets" , "role missing from top-level keys" })
1754+
17301755 // generate root key offline and add as a verification key
17311756 rootKey , err := keys .GenerateEd25519Key ()
17321757 c .Assert (err , IsNil )
@@ -1749,7 +1774,7 @@ func (rs *RepoSuite) TestBadAddOrUpdateSignatures(c *C) {
17491774 for _ , id := range rootKey .PublicData ().IDs () {
17501775 c .Assert (r .AddOrUpdateSignature ("invalid_root.json" , data.Signature {
17511776 KeyID : id ,
1752- Signature : rootSig }), Equals , ErrInvalidRole {"invalid_root" })
1777+ Signature : rootSig }), Equals , ErrInvalidRole {"invalid_root" , "only signing top-level metadata supported" })
17531778 }
17541779
17551780 // add a root signature with an key ID that is for the targets role
0 commit comments