[#142] Update SDK

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-04-19 18:46:51 +03:00 committed by Kirillov Denis
parent 11283c1c79
commit 2b780c1772
8 changed files with 76 additions and 61 deletions

View file

@ -7,7 +7,7 @@ import (
"errors"
"fmt"
"github.com/nspcc-dev/neofs-sdk-go/token"
"github.com/nspcc-dev/neofs-sdk-go/bearer"
"github.com/valyala/fasthttp"
)
@ -62,14 +62,14 @@ func StoreBearerToken(ctx *fasthttp.RequestCtx) error {
// LoadBearerToken returns a bearer token stored in the context given (if it's
// present there).
func LoadBearerToken(ctx context.Context) (*token.BearerToken, error) {
if tkn, ok := ctx.Value(bearerTokenKey).(*token.BearerToken); ok && tkn != nil {
func LoadBearerToken(ctx context.Context) (*bearer.Token, error) {
if tkn, ok := ctx.Value(bearerTokenKey).(*bearer.Token); ok && tkn != nil {
return tkn, nil
}
return nil, errors.New("found empty bearer token")
}
func fetchBearerToken(ctx *fasthttp.RequestCtx) (*token.BearerToken, error) {
func fetchBearerToken(ctx *fasthttp.RequestCtx) (*bearer.Token, error) {
// ignore empty value
if ctx == nil {
return nil, nil
@ -78,7 +78,7 @@ func fetchBearerToken(ctx *fasthttp.RequestCtx) (*token.BearerToken, error) {
lastErr error
buf []byte
tkn = new(token.BearerToken)
tkn = new(bearer.Token)
)
for _, parse := range []fromHandler{BearerTokenFromHeader, BearerTokenFromCookie} {
if buf = parse(&ctx.Request.Header); buf == nil {

View file

@ -4,8 +4,8 @@ import (
"encoding/base64"
"testing"
"github.com/nspcc-dev/neofs-sdk-go/owner"
"github.com/nspcc-dev/neofs-sdk-go/token"
"github.com/nspcc-dev/neofs-sdk-go/bearer"
"github.com/nspcc-dev/neofs-sdk-go/user"
"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
)
@ -59,16 +59,12 @@ func Test_fromHeader(t *testing.T) {
}
func Test_fetchBearerToken(t *testing.T) {
uid := owner.NewID()
var uid user.ID
tkn := new(token.BearerToken)
tkn.SetOwner(uid)
tkn := new(bearer.Token)
tkn.SetOwnerID(uid)
data, err := tkn.Marshal()
require.NoError(t, err)
t64 := base64.StdEncoding.EncodeToString(data)
t64 := base64.StdEncoding.EncodeToString(tkn.Marshal())
require.NotEmpty(t, t64)
cases := []struct {
@ -78,7 +74,7 @@ func Test_fetchBearerToken(t *testing.T) {
header string
error string
expect *token.BearerToken
expect *bearer.Token
}{
{name: "empty"},
@ -137,15 +133,12 @@ func makeTestRequest(cookie, header string) *fasthttp.RequestCtx {
}
func Test_checkAndPropagateBearerToken(t *testing.T) {
uid := owner.NewID()
var uid user.ID
tkn := new(token.BearerToken)
tkn.SetOwner(uid)
tkn := new(bearer.Token)
tkn.SetOwnerID(uid)
data, err := tkn.Marshal()
require.NoError(t, err)
t64 := base64.StdEncoding.EncodeToString(data)
t64 := base64.StdEncoding.EncodeToString(tkn.Marshal())
require.NotEmpty(t, t64)
ctx := makeTestRequest(t64, "")