Address review comments

Signed-off-by: Riyaz Faizullabhoy <riyaz.faizullabhoy@docker.com>
This commit is contained in:
Riyaz Faizullabhoy 2016-03-10 11:26:00 -08:00
parent 8336bba114
commit e1613cdcb2
3 changed files with 8 additions and 15 deletions

View File

@ -105,8 +105,8 @@ func TestPrettyPrintRootAndSigningKeys(t *testing.T) {
// add keys to the key stores
assert.NoError(t, keyStores[0].AddKey(trustmanager.KeyInfo{Role: root, Gun: ""}, keys[0]))
assert.NoError(t, keyStores[1].AddKey(trustmanager.KeyInfo{Role: root, Gun: ""}, keys[0]))
assert.NoError(t, keyStores[0].AddKey(trustmanager.KeyInfo{Role: "targets", Gun: strings.Repeat("/a", 30)}, keys[1]))
assert.NoError(t, keyStores[1].AddKey(trustmanager.KeyInfo{Role: "snapshot", Gun: "short/gun"}, keys[1]))
assert.NoError(t, keyStores[0].AddKey(trustmanager.KeyInfo{Role: data.CanonicalTargetsRole, Gun: strings.Repeat("/a", 30)}, keys[1]))
assert.NoError(t, keyStores[1].AddKey(trustmanager.KeyInfo{Role: data.CanonicalSnapshotRole, Gun: "short/gun"}, keys[1]))
assert.NoError(t, keyStores[0].AddKey(trustmanager.KeyInfo{Role: "targets/a", Gun: ""}, keys[3]))
assert.NoError(t, keyStores[0].AddKey(trustmanager.KeyInfo{Role: "invalidRole", Gun: ""}, keys[2]))
@ -118,8 +118,8 @@ func TestPrettyPrintRootAndSigningKeys(t *testing.T) {
{"invalidRole", keys[2].ID(), keyStores[0].Name()},
{"targets/a", keys[3].ID(), keyStores[0].Name()},
// these have guns, and are sorted then by guns
{"targets", "..." + strings.Repeat("/a", 11), keys[1].ID(), keyStores[0].Name()},
{"snapshot", "short/gun", keys[1].ID(), longNameShortened},
{data.CanonicalTargetsRole, "..." + strings.Repeat("/a", 11), keys[1].ID(), keyStores[0].Name()},
{data.CanonicalSnapshotRole, "short/gun", keys[1].ID(), longNameShortened},
}
var b bytes.Buffer

View File

@ -300,7 +300,7 @@ func (c CryptoServiceTester) TestListFromMultipleKeystores(t *testing.T) {
}
}
// asserts that adding a key adds to all keystores
// asserts that adding a key adds to just the first keystore
// and adding an existing key either succeeds if the role matches or fails if it does not
func (c CryptoServiceTester) TestAddKey(t *testing.T) {
cryptoService := c.cryptoServiceFactory()

View File

@ -193,8 +193,7 @@ func (s *KeyFileStore) RemoveKey(keyID string) error {
return nil
}
// ExportKey exports the encrypted bytes from the keystore and writes it to
// dest.
// ExportKey exports the encrypted bytes from the keystore
func (s *KeyFileStore) ExportKey(keyID string) ([]byte, error) {
if keyInfo, ok := s.keyInfoMap[keyID]; ok {
keyID = filepath.Join(keyInfo.Gun, keyID)
@ -283,17 +282,11 @@ func (s *KeyMemoryStore) RemoveKey(keyID string) error {
return err
}
// Remove this key from our keyInfo map if we removed from our filesystem
if _, ok := s.keyInfoMap[keyID]; ok {
delete(s.keyInfoMap, keyID)
} else {
// This might be of the form GUN/ID - try to delete without the gun
delete(s.keyInfoMap, filepath.Base(keyID))
}
delete(s.keyInfoMap, filepath.Base(keyID))
return nil
}
// ExportKey exports the encrypted bytes from the keystore and writes it to
// dest.
// ExportKey exports the encrypted bytes from the keystore
func (s *KeyMemoryStore) ExportKey(keyID string) ([]byte, error) {
keyBytes, _, err := getRawKey(s, keyID)
if err != nil {