Skip to content

Commit

Permalink
More testing
Browse files Browse the repository at this point in the history
Signed-off-by: Riyaz Faizullabhoy <[email protected]>
  • Loading branch information
riyazdf committed Aug 2, 2016
1 parent cc9d381 commit 1a8ca83
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
13 changes: 13 additions & 0 deletions client/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/sha256"
"encoding/json"
"net/http"
"testing"
"time"

Expand Down Expand Up @@ -1019,3 +1020,15 @@ func TestAllNotNearExpiry(t *testing.T) {
require.NotContains(t, a.String(), "snapshot is nearing expiry, you should re-sign the role metadata", "Snapshot should not show near expiry")
require.NotContains(t, a.String(), "timestamp", "there should be no logrus warnings pertaining to timestamp")
}

func TestRotateRemoteKeyOffline(t *testing.T) {
// without a valid roundtripper, rotation should fail since we cannot initialize a HTTPStore
key, err := rotateRemoteKey("invalidURL", "gun", data.CanonicalSnapshotRole, nil)
require.Error(t, err)
require.Nil(t, key)

// if the underlying remote store is faulty and cannot rotate keys, we should get back the error
key, err = rotateRemoteKey("https://notary-server", "gun", data.CanonicalSnapshotRole, http.DefaultTransport)
require.Error(t, err)
require.Nil(t, key)
}
8 changes: 7 additions & 1 deletion signer/keydbstore/keydbstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,20 @@ func testMarkKeyActive(t *testing.T, dbStore keyActivator) (data.PrivateKey, dat
func testGetPendingKey(t *testing.T, dbStore keyActivator) (data.PrivateKey, data.PrivateKey) {
// Create a test key and add it to the db such that it will be pending (never marked active)
keyInfo := trustmanager.KeyInfo{Role: data.CanonicalSnapshotRole, Gun: "gun"}

// There should be no keys to start
retrievedKey, err := dbStore.GetPendingKey(keyInfo)
require.Error(t, err)
require.Nil(t, retrievedKey)

pendingTestKey, err := utils.GenerateECDSAKey(rand.Reader)
require.NoError(t, err)
requireGetKeyFailure(t, dbStore, pendingTestKey.ID())
err = dbStore.AddKey(keyInfo, pendingTestKey)
require.NoError(t, err)
requireGetKeySuccess(t, dbStore, data.CanonicalSnapshotRole, pendingTestKey)

retrievedKey, err := dbStore.GetPendingKey(keyInfo)
retrievedKey, err = dbStore.GetPendingKey(keyInfo)
require.NoError(t, err)
require.Equal(t, pendingTestKey.Public(), retrievedKey.Public())

Expand Down

0 comments on commit 1a8ca83

Please sign in to comment.