storj/pkg/certdb/certdb_test.go
paul cannon c35b93766d
Unite all cryptographic signing and verifying (#1244)
this change removes the cryptopasta dependency.

a couple possible sources of problem with this change:

 * the encoding used for ECDSA signatures on SignedMessage has changed.
   the encoding employed by cryptopasta was workable, but not the same
   as the encoding used for such signatures in the rest of the world
   (most particularly, on ECDSA signatures in X.509 certificates). I
   think we'll be best served by using one ECDSA signature encoding from
   here on, but if we need to use the old encoding for backwards
   compatibility with existing nodes, that can be arranged.

 * since there's already a breaking change in SignedMessage, I changed
   it to send and receive public keys in raw PKIX format, instead of
   PEM. PEM just adds unhelpful overhead for this case.
2019-02-07 14:39:20 -06:00

55 lines
1.3 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package certdb_test
import (
"context"
"crypto/x509"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"storj.io/storj/internal/testcontext"
"storj.io/storj/internal/testidentity"
"storj.io/storj/pkg/certdb"
"storj.io/storj/satellite"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
func TestCertDB(t *testing.T) {
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
testDatabase(ctx, t, db.CertDB())
})
}
func testDatabase(ctx context.Context, t *testing.T, upldb certdb.DB) {
//testing variables
upID, err := testidentity.NewTestIdentity(ctx)
require.NoError(t, err)
upIDpubbytes, err := x509.MarshalPKIXPublicKey(upID.Leaf.PublicKey)
require.NoError(t, err)
{ // New entry
err := upldb.SavePublicKey(ctx, upID.ID, upID.Leaf.PublicKey)
assert.NoError(t, err)
}
{ // New entry
err := upldb.SavePublicKey(ctx, upID.ID, upID.Leaf.PublicKey)
assert.NoError(t, err)
}
{ // Get the corresponding Public key for the serialnum
pubkey, err := upldb.GetPublicKey(ctx, upID.ID)
assert.NoError(t, err)
pubbytes, err := x509.MarshalPKIXPublicKey(pubkey)
assert.NoError(t, err)
assert.EqualValues(t, upIDpubbytes, pubbytes)
}
}