storj/pkg/auth/signature_test.go
JT Olio ccb158c99b
pkg/auth: add monkit task to missing places (#2123)
What: add monkit.Task to a bunch of functions that are missing it

Why: this will significantly help our instrumentation, data collection, and tracing about what's going on in the network
2019-06-05 07:47:01 -06:00

41 lines
881 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package auth
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"storj.io/storj/internal/testidentity"
"storj.io/storj/pkg/pkcrypto"
)
func TestGenerateSignature(t *testing.T) {
ctx := context.Background()
ca, err := testidentity.NewTestCA(ctx)
assert.NoError(t, err)
identity, err := ca.NewIdentity()
assert.NoError(t, err)
for _, tt := range []struct {
data []byte
verified bool
}{
{identity.ID.Bytes(), true},
{[]byte("non verifiable data"), false},
} {
signature, err := GenerateSignature(ctx, identity.ID.Bytes(), identity)
assert.NoError(t, err)
verifyError := pkcrypto.HashAndVerifySignature(identity.Leaf.PublicKey, tt.data, signature)
if tt.verified {
assert.NoError(t, verifyError)
} else {
assert.Error(t, verifyError)
}
}
}