From 7c979aded799a861d6b07cee4b29ac59a36a54b6 Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Tue, 30 Aug 2022 16:07:14 +0300 Subject: [PATCH] [#61] Fix tests Signed-off-by: Denis Kirillov --- cmd/neofs-rest-gw/integration_test.go | 9 ++------- handlers/auth_test.go | 12 +++--------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/cmd/neofs-rest-gw/integration_test.go b/cmd/neofs-rest-gw/integration_test.go index 73246f6..79206b0 100644 --- a/cmd/neofs-rest-gw/integration_test.go +++ b/cmd/neofs-rest-gw/integration_test.go @@ -3,10 +3,6 @@ package main import ( "bytes" "context" - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" - "crypto/sha512" "encoding/base64" "encoding/hex" "encoding/json" @@ -1061,10 +1057,9 @@ func makeAuthTokenRequest(ctx context.Context, t *testing.T, bearers []*models.B } func signToken(t *testing.T, key *keys.PrivateKey, data []byte) *handlers.BearerToken { - h := sha512.Sum512(data) - x, y, err := ecdsa.Sign(rand.Reader, &key.PrivateKey, h[:]) + signer := neofsecdsa.Signer(key.PrivateKey) + sign, err := signer.Sign(data) require.NoError(t, err) - sign := elliptic.Marshal(elliptic.P256(), x, y) return &handlers.BearerToken{ Token: base64.StdEncoding.EncodeToString(data), diff --git a/handlers/auth_test.go b/handlers/auth_test.go index ebc2c98..ae953fb 100644 --- a/handlers/auth_test.go +++ b/handlers/auth_test.go @@ -2,9 +2,6 @@ package handlers import ( "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" - "crypto/sha512" "encoding/base64" "encoding/hex" "math" @@ -12,6 +9,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neofs-api-go/v2/acl" + crypto "github.com/nspcc-dev/neofs-crypto" "github.com/nspcc-dev/neofs-rest-gw/gen/models" "github.com/nspcc-dev/neofs-rest-gw/internal/util" "github.com/nspcc-dev/neofs-sdk-go/user" @@ -54,12 +52,8 @@ func TestSign(t *testing.T) { binaryBearer := v2token.GetBody().StableMarshal(nil) bearerBase64 := base64.StdEncoding.EncodeToString(binaryBearer) - h := sha512.Sum512(binaryBearer) - x, y, err := ecdsa.Sign(rand.Reader, &key.PrivateKey, h[:]) - if err != nil { - panic(err) - } - signatureData := elliptic.Marshal(elliptic.P256(), x, y) + signatureData, err := crypto.Sign(&key.PrivateKey, binaryBearer) + require.NoError(t, err) bt := &BearerToken{ Token: bearerBase64,