Fix bug with ED25519 cryptoservice's ListKeys

Signed-off-by: Ying Li <ying.li@docker.com>
This commit is contained in:
Ying Li 2015-12-04 13:47:54 -08:00
parent dd69872bb6
commit bf0c6d0844
2 changed files with 28 additions and 2 deletions

View File

@ -46,8 +46,10 @@ func (e *Ed25519) RemoveKey(keyID string) error {
// ListKeys returns the list of keys IDs for the role
func (e *Ed25519) ListKeys(role string) []string {
keyIDs := make([]string, 0, len(e.keys))
for id := range e.keys {
keyIDs = append(keyIDs, id)
for id, edCryptoKey := range e.keys {
if edCryptoKey.role == role {
keyIDs = append(keyIDs, id)
}
}
return keyIDs
}

View File

@ -0,0 +1,24 @@
package signed
import (
"testing"
"github.com/docker/notary/tuf/data"
"github.com/stretchr/testify/assert"
)
// ListKeys only returns the keys for that role
func TestListKeys(t *testing.T) {
c := NewEd25519()
tskey, err := c.Create(data.CanonicalTimestampRole, data.ED25519Key)
assert.NoError(t, err)
_, err = c.Create(data.CanonicalRootRole, data.ED25519Key)
assert.NoError(t, err)
tsKeys := c.ListKeys(data.CanonicalTimestampRole)
assert.Len(t, tsKeys, 1)
assert.Equal(t, tskey.ID(), tsKeys[0])
assert.Len(t, c.ListKeys(data.CanonicalTargetsRole), 0)
}