mirror of https://github.com/docker/docs.git
Amend rotation tests to assert old keys are removed after rotation.
Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
parent
ca1623e17b
commit
2c7e632925
|
@ -653,11 +653,7 @@ func (r *NotaryRepository) RotateKey(role string, serverManagesKey bool) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.rootFileKeyChange(role, changelist.ActionCreate, pubKey)
|
return r.rootFileKeyChange(role, changelist.ActionCreate, pubKey)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *NotaryRepository) rootFileKeyChange(role, action string, key data.PublicKey) error {
|
func (r *NotaryRepository) rootFileKeyChange(role, action string, key data.PublicKey) error {
|
||||||
|
|
|
@ -1055,11 +1055,10 @@ func TestRotateKeyInvalidRole(t *testing.T) {
|
||||||
func assertRotationSuccessful(t *testing.T, repo *NotaryRepository,
|
func assertRotationSuccessful(t *testing.T, repo *NotaryRepository,
|
||||||
keysToRotate map[string]bool) {
|
keysToRotate map[string]bool) {
|
||||||
|
|
||||||
oldKeyIDs := make(map[string]string)
|
oldKeyIDs := make(map[string][]string)
|
||||||
for role := range keysToRotate {
|
for role := range keysToRotate {
|
||||||
keyIDs := repo.tufRepo.Root.Signed.Roles[role].KeyIDs
|
keyIDs := repo.tufRepo.Root.Signed.Roles[role].KeyIDs
|
||||||
assert.Len(t, keyIDs, 1)
|
oldKeyIDs[role] = keyIDs
|
||||||
oldKeyIDs[role] = keyIDs[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do rotation
|
// Do rotation
|
||||||
|
@ -1078,7 +1077,17 @@ func assertRotationSuccessful(t *testing.T, repo *NotaryRepository,
|
||||||
for role, isRemoteKey := range keysToRotate {
|
for role, isRemoteKey := range keysToRotate {
|
||||||
keyIDs := repo.tufRepo.Root.Signed.Roles[role].KeyIDs
|
keyIDs := repo.tufRepo.Root.Signed.Roles[role].KeyIDs
|
||||||
assert.Len(t, keyIDs, 1)
|
assert.Len(t, keyIDs, 1)
|
||||||
assert.NotEqual(t, oldKeyIDs[role], keyIDs[0])
|
|
||||||
|
// the new key is not the same as any of the old keys, and the
|
||||||
|
// old keys have been removed not just from the TUF file, but
|
||||||
|
// from the cryptoservice
|
||||||
|
for _, oldKeyID := range oldKeyIDs[role] {
|
||||||
|
assert.NotEqual(t, oldKeyID, keyIDs[0])
|
||||||
|
_, _, err := repo.CryptoService.GetPrivateKey(oldKeyID)
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// the new key is present in the cryptoservice, or not present if remote
|
||||||
key, _, err := repo.CryptoService.GetPrivateKey(keyIDs[0])
|
key, _, err := repo.CryptoService.GetPrivateKey(keyIDs[0])
|
||||||
if isRemoteKey {
|
if isRemoteKey {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
Loading…
Reference in New Issue