-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Delegations prereq 7] Make signers addressible by key ID in LocalSto…
…re (#197) * [Delegations prereq] Use a verify.DB for delegation in client Splitting up #175 * stash * Add tests to make sure the top level targets 'delegation' edge has associated keys. Make NewDelegationsIterator return an error if the passed DB is missing the top level targets role * [Delegations prereq] Make signers addressible by key ID in LocalStore Splitting up #175 * Clarify naming * Add local_store_test.go * Another test case
- Loading branch information
1 parent
314eed4
commit d85e0a2
Showing
4 changed files
with
240 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package tuf | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/theupdateframework/go-tuf/pkg/keys" | ||
) | ||
|
||
func TestLocalStoreSigners(t *testing.T) { | ||
tmpdir, err := os.MkdirTemp("", "") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer func() { | ||
os.RemoveAll(tmpdir) | ||
}() | ||
|
||
stores := map[string]LocalStore{ | ||
"MemoryStore": MemoryStore(nil, nil), | ||
"FileSystemStore": FileSystemStore(tmpdir, nil), | ||
} | ||
|
||
for name, store := range stores { | ||
t.Run(name, func(t *testing.T) { | ||
signers, err := store.GetSigners("abc") | ||
assert.NoError(t, err) | ||
assert.Equal(t, len(signers), 0) | ||
|
||
// Add two signers to role "a". | ||
aSigner1, err := keys.GenerateEd25519Key() | ||
assert.NoError(t, err) | ||
err = store.SaveSigner("a", aSigner1) | ||
assert.NoError(t, err) | ||
|
||
aSigner2, err := keys.GenerateEd25519Key() | ||
assert.NoError(t, err) | ||
err = store.SaveSigner("a", aSigner2) | ||
assert.NoError(t, err) | ||
|
||
// Add one signer to role "b". | ||
bSigner, err := keys.GenerateEd25519Key() | ||
assert.NoError(t, err) | ||
err = store.SaveSigner("b", bSigner) | ||
assert.NoError(t, err) | ||
|
||
// Add to b again to test deduplication. | ||
err = store.SaveSigner("b", bSigner) | ||
assert.NoError(t, err) | ||
|
||
signers, err = store.GetSigners("a") | ||
assert.NoError(t, err) | ||
assert.ElementsMatch(t, []keys.Signer{aSigner1, aSigner2}, signers) | ||
|
||
signers, err = store.GetSigners("b") | ||
assert.NoError(t, err) | ||
assert.ElementsMatch(t, []keys.Signer{bSigner}, signers) | ||
|
||
a1KeyIDs := aSigner1.PublicData().IDs() | ||
a2KeyIDs := aSigner2.PublicData().IDs() | ||
bKeyIDs := bSigner.PublicData().IDs() | ||
|
||
assert.Equal(t, []keys.Signer{aSigner1}, store.SignersForKeyIDs(a1KeyIDs)) | ||
assert.Equal(t, []keys.Signer{aSigner2}, store.SignersForKeyIDs(a2KeyIDs)) | ||
assert.ElementsMatch(t, []keys.Signer{aSigner1, aSigner2}, store.SignersForKeyIDs(append(a1KeyIDs, a2KeyIDs...))) | ||
assert.Equal(t, []keys.Signer{bSigner}, store.SignersForKeyIDs(bKeyIDs)) | ||
}) | ||
} | ||
} |
Oops, something went wrong.