[#295] pkg: Remove usage of deprecated elements

Remove usage of deprecated of `container.ID` and `token.SessionToken` code
elements. Replace using of custom message generators with the ones provided
by packages. Replace string comparison with `Equal` method call.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-31 15:09:04 +03:00 committed by Leonard Lyubich
parent 89be8d3f5a
commit 65080c8b69
22 changed files with 97 additions and 209 deletions

View file

@ -6,26 +6,25 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test" sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTable(t *testing.T) { func TestTable(t *testing.T) {
var ( var (
v pkg.Version v pkg.Version
cid container.ID
) )
sha := sha256.Sum256([]byte("container id")) sha := sha256.Sum256([]byte("container id"))
cid.SetSHA256(sha) id := cidtest.GenerateWithChecksum(sha)
v.SetMajor(3) v.SetMajor(3)
v.SetMinor(2) v.SetMinor(2)
table := eacl.NewTable() table := eacl.NewTable()
table.SetVersion(v) table.SetVersion(v)
table.SetCID(&cid) table.SetCID(id)
table.AddRecord(eacl.CreateRecord(eacl.ActionAllow, eacl.OperationPut)) table.AddRecord(eacl.CreateRecord(eacl.ActionAllow, eacl.OperationPut))
v2 := table.ToV2() v2 := table.ToV2()
@ -43,11 +42,10 @@ func TestTable(t *testing.T) {
}) })
t.Run("create table", func(t *testing.T) { t.Run("create table", func(t *testing.T) {
var cid = new(container.ID) id := cidtest.Generate()
cid.SetSHA256(sha256.Sum256([]byte("container id")))
table := eacl.CreateTable(*cid) table := eacl.CreateTable(*id)
require.Equal(t, cid, table.CID()) require.Equal(t, id, table.CID())
require.Equal(t, *pkg.SDKVersion(), table.Version()) require.Equal(t, *pkg.SDKVersion(), table.Version())
}) })
} }

View file

@ -2,7 +2,7 @@ package audit
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/v2/audit" "github.com/nspcc-dev/neofs-api-go/v2/audit"
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
@ -87,15 +87,15 @@ func (r *Result) SetAuditEpoch(epoch uint64) {
} }
// ContainerID returns container under audit. // ContainerID returns container under audit.
func (r *Result) ContainerID() *container.ID { func (r *Result) ContainerID() *cid.ID {
return container.NewIDFromV2( return cid.NewFromV2(
(*audit.DataAuditResult)(r). (*audit.DataAuditResult)(r).
GetContainerID(), GetContainerID(),
) )
} }
// SetContainerID sets container under audit. // SetContainerID sets container under audit.
func (r *Result) SetContainerID(id *container.ID) { func (r *Result) SetContainerID(id *cid.ID) {
(*audit.DataAuditResult)(r). (*audit.DataAuditResult)(r).
SetContainerID(id.ToV2()) SetContainerID(id.ToV2())
} }

View file

@ -7,7 +7,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/audit" "github.com/nspcc-dev/neofs-api-go/pkg/audit"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -17,13 +17,6 @@ func testSHA256() (cs [sha256.Size]byte) {
return return
} }
func testCID() *container.ID {
cid := container.NewID()
cid.SetSHA256(testSHA256())
return cid
}
func testOID() *object.ID { func testOID() *object.ID {
id := object.NewID() id := object.NewID()
id.SetSHA256(testSHA256()) id.SetSHA256(testSHA256())
@ -39,7 +32,7 @@ func TestResult(t *testing.T) {
r.SetAuditEpoch(epoch) r.SetAuditEpoch(epoch)
require.Equal(t, epoch, r.AuditEpoch()) require.Equal(t, epoch, r.AuditEpoch())
cid := testCID() cid := cidtest.Generate()
r.SetContainerID(cid) r.SetContainerID(cid)
require.Equal(t, cid, r.ContainerID()) require.Equal(t, cid, r.ContainerID())
@ -90,7 +83,7 @@ func TestResult(t *testing.T) {
func TestStorageGroupEncoding(t *testing.T) { func TestStorageGroupEncoding(t *testing.T) {
r := audit.NewResult() r := audit.NewResult()
r.SetAuditEpoch(13) r.SetAuditEpoch(13)
r.SetContainerID(testCID()) r.SetContainerID(cidtest.Generate())
r.SetPublicKey([]byte{1, 2, 3}) r.SetPublicKey([]byte{1, 2, 3})
r.SetPassSG([]*object.ID{testOID(), testOID()}) r.SetPassSG([]*object.ID{testOID(), testOID()})
r.SetFailSG([]*object.ID{testOID(), testOID()}) r.SetFailSG([]*object.ID{testOID(), testOID()})

View file

@ -8,6 +8,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl"
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/session" "github.com/nspcc-dev/neofs-api-go/pkg/session"
"github.com/nspcc-dev/neofs-api-go/rpc/client" "github.com/nspcc-dev/neofs-api-go/rpc/client"
@ -21,19 +22,19 @@ import (
// Container contains methods related to container and ACL. // Container contains methods related to container and ACL.
type Container interface { type Container interface {
// PutContainer creates new container in the NeoFS network. // PutContainer creates new container in the NeoFS network.
PutContainer(context.Context, *container.Container, ...CallOption) (*container.ID, error) PutContainer(context.Context, *container.Container, ...CallOption) (*cid.ID, error)
// GetContainer returns container by ID. // GetContainer returns container by ID.
GetContainer(context.Context, *container.ID, ...CallOption) (*container.Container, error) GetContainer(context.Context, *cid.ID, ...CallOption) (*container.Container, error)
// ListContainers return container list with the provided owner. // ListContainers return container list with the provided owner.
ListContainers(context.Context, *owner.ID, ...CallOption) ([]*container.ID, error) ListContainers(context.Context, *owner.ID, ...CallOption) ([]*cid.ID, error)
// DeleteContainer removes container from NeoFS network. // DeleteContainer removes container from NeoFS network.
DeleteContainer(context.Context, *container.ID, ...CallOption) error DeleteContainer(context.Context, *cid.ID, ...CallOption) error
// GetEACL returns extended ACL for a given container. // GetEACL returns extended ACL for a given container.
GetEACL(context.Context, *container.ID, ...CallOption) (*EACLWithSignature, error) GetEACL(context.Context, *cid.ID, ...CallOption) (*EACLWithSignature, error)
// SetEACL sets extended ACL. // SetEACL sets extended ACL.
SetEACL(context.Context, *eacl.Table, ...CallOption) error SetEACL(context.Context, *eacl.Table, ...CallOption) error
@ -71,7 +72,7 @@ func (e EACLWithSignature) Signature() *pkg.Signature {
return e.table.Signature() return e.table.Signature()
} }
func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*container.ID, error) { func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container, opts ...CallOption) (*cid.ID, error) {
// apply all available options // apply all available options
callOptions := c.defaultCallOptions() callOptions := c.defaultCallOptions()
@ -134,13 +135,13 @@ func (c *clientImpl) PutContainer(ctx context.Context, cnr *container.Container,
return nil, fmt.Errorf("can't verify response message: %w", err) return nil, fmt.Errorf("can't verify response message: %w", err)
} }
return container.NewIDFromV2(resp.GetBody().GetContainerID()), nil return cid.NewFromV2(resp.GetBody().GetContainerID()), nil
} }
// GetContainer receives container structure through NeoFS API call. // GetContainer receives container structure through NeoFS API call.
// //
// Returns error if container structure is received but does not meet NeoFS API specification. // Returns error if container structure is received but does not meet NeoFS API specification.
func (c *clientImpl) GetContainer(ctx context.Context, id *container.ID, opts ...CallOption) (*container.Container, error) { func (c *clientImpl) GetContainer(ctx context.Context, id *cid.ID, opts ...CallOption) (*container.Container, error) {
// apply all available options // apply all available options
callOptions := c.defaultCallOptions() callOptions := c.defaultCallOptions()
@ -192,7 +193,7 @@ func (c *clientImpl) GetContainer(ctx context.Context, id *container.ID, opts ..
// which checks if the structure of the resulting container matches its identifier. // which checks if the structure of the resulting container matches its identifier.
// //
// Returns an error if container does not match the identifier. // Returns an error if container does not match the identifier.
func GetVerifiedContainerStructure(ctx context.Context, c Client, id *container.ID, opts ...CallOption) (*container.Container, error) { func GetVerifiedContainerStructure(ctx context.Context, c Client, id *cid.ID, opts ...CallOption) (*container.Container, error) {
cnr, err := c.GetContainer(ctx, id, opts...) cnr, err := c.GetContainer(ctx, id, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
@ -205,7 +206,7 @@ func GetVerifiedContainerStructure(ctx context.Context, c Client, id *container.
return cnr, nil return cnr, nil
} }
func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) ([]*container.ID, error) { func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts ...CallOption) ([]*cid.ID, error) {
// apply all available options // apply all available options
callOptions := c.defaultCallOptions() callOptions := c.defaultCallOptions()
@ -245,15 +246,15 @@ func (c *clientImpl) ListContainers(ctx context.Context, ownerID *owner.ID, opts
return nil, fmt.Errorf("can't verify response message: %w", err) return nil, fmt.Errorf("can't verify response message: %w", err)
} }
result := make([]*container.ID, 0, len(resp.GetBody().GetContainerIDs())) result := make([]*cid.ID, 0, len(resp.GetBody().GetContainerIDs()))
for _, cidV2 := range resp.GetBody().GetContainerIDs() { for _, cidV2 := range resp.GetBody().GetContainerIDs() {
result = append(result, container.NewIDFromV2(cidV2)) result = append(result, cid.NewFromV2(cidV2))
} }
return result, nil return result, nil
} }
func (c *clientImpl) DeleteContainer(ctx context.Context, id *container.ID, opts ...CallOption) error { func (c *clientImpl) DeleteContainer(ctx context.Context, id *cid.ID, opts ...CallOption) error {
// apply all available options // apply all available options
callOptions := c.defaultCallOptions() callOptions := c.defaultCallOptions()
@ -301,7 +302,7 @@ func (c *clientImpl) DeleteContainer(ctx context.Context, id *container.ID, opts
return nil return nil
} }
func (c *clientImpl) GetEACL(ctx context.Context, id *container.ID, opts ...CallOption) (*EACLWithSignature, error) { func (c *clientImpl) GetEACL(ctx context.Context, id *cid.ID, opts ...CallOption) (*EACLWithSignature, error) {
// apply all available options // apply all available options
callOptions := c.defaultCallOptions() callOptions := c.defaultCallOptions()

View file

@ -9,7 +9,7 @@ import (
"fmt" "fmt"
"io" "io"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/object" "github.com/nspcc-dev/neofs-api-go/pkg/object"
"github.com/nspcc-dev/neofs-api-go/rpc/client" "github.com/nspcc-dev/neofs-api-go/rpc/client"
signer "github.com/nspcc-dev/neofs-api-go/util/signature" signer "github.com/nspcc-dev/neofs-api-go/util/signature"
@ -106,7 +106,7 @@ type RangeChecksumParams struct {
} }
type SearchObjectParams struct { type SearchObjectParams struct {
cid *container.ID cid *cid.ID
filters object.SearchFilters filters object.SearchFilters
} }
@ -1092,7 +1092,7 @@ func (c *clientImpl) objectPayloadRangeHash(ctx context.Context, p *RangeChecksu
return res, nil return res, nil
} }
func (p *SearchObjectParams) WithContainerID(v *container.ID) *SearchObjectParams { func (p *SearchObjectParams) WithContainerID(v *cid.ID) *SearchObjectParams {
if p != nil { if p != nil {
p.cid = v p.cid = v
} }
@ -1100,7 +1100,7 @@ func (p *SearchObjectParams) WithContainerID(v *container.ID) *SearchObjectParam
return p return p
} }
func (p *SearchObjectParams) ContainerID() *container.ID { func (p *SearchObjectParams) ContainerID() *cid.ID {
if p != nil { if p != nil {
return p.cid return p.cid
} }

View file

@ -6,6 +6,7 @@ import (
"time" "time"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/session"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/pkg/token"
"github.com/nspcc-dev/neofs-api-go/rpc/client" "github.com/nspcc-dev/neofs-api-go/rpc/client"
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
@ -24,7 +25,7 @@ type (
ttl uint32 ttl uint32
epoch uint64 epoch uint64
key *ecdsa.PrivateKey key *ecdsa.PrivateKey
session *token.SessionToken session *session.Token
bearer *token.BearerToken bearer *token.BearerToken
} }
@ -75,7 +76,7 @@ func WithEpoch(epoch uint64) CallOption {
} }
} }
func WithSession(token *token.SessionToken) CallOption { func WithSession(token *session.Token) CallOption {
return func(opts *callOptions) { return func(opts *callOptions) {
opts.session = token opts.session = token
} }

View file

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/pkg/session"
"github.com/nspcc-dev/neofs-api-go/rpc/client" "github.com/nspcc-dev/neofs-api-go/rpc/client"
rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc" rpcapi "github.com/nspcc-dev/neofs-api-go/v2/rpc"
v2session "github.com/nspcc-dev/neofs-api-go/v2/session" v2session "github.com/nspcc-dev/neofs-api-go/v2/session"
@ -16,12 +16,12 @@ import (
// Session contains session-related methods. // Session contains session-related methods.
type Session interface { type Session interface {
// CreateSession creates session using provided expiration time. // CreateSession creates session using provided expiration time.
CreateSession(context.Context, uint64, ...CallOption) (*token.SessionToken, error) CreateSession(context.Context, uint64, ...CallOption) (*session.Token, error)
} }
var errMalformedResponseBody = errors.New("malformed response body") var errMalformedResponseBody = errors.New("malformed response body")
func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*token.SessionToken, error) { func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts ...CallOption) (*session.Token, error) {
// apply all available options // apply all available options
callOptions := c.defaultCallOptions() callOptions := c.defaultCallOptions()
@ -65,7 +65,7 @@ func (c *clientImpl) CreateSession(ctx context.Context, expiration uint64, opts
return nil, errMalformedResponseBody return nil, errMalformedResponseBody
} }
sessionToken := token.NewSessionToken() sessionToken := session.NewToken()
sessionToken.SetID(body.GetID()) sessionToken.SetID(body.GetID())
sessionToken.SetSessionKey(body.GetSessionKey()) sessionToken.SetSessionKey(body.GetSessionKey())
sessionToken.SetOwnerID(ownerID) sessionToken.SetOwnerID(ownerID)

View file

@ -1,6 +1,7 @@
package container package container
import ( import (
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/v2/container" "github.com/nspcc-dev/neofs-api-go/v2/container"
) )
@ -30,14 +31,14 @@ func (a *UsedSpaceAnnouncement) SetEpoch(epoch uint64) {
} }
// ContainerID of the announcement. // ContainerID of the announcement.
func (a *UsedSpaceAnnouncement) ContainerID() *ID { func (a *UsedSpaceAnnouncement) ContainerID() *cid.ID {
return NewIDFromV2( return cid.NewFromV2(
(*container.UsedSpaceAnnouncement)(a).GetContainerID(), (*container.UsedSpaceAnnouncement)(a).GetContainerID(),
) )
} }
// SetContainerID sets announcement container value. // SetContainerID sets announcement container value.
func (a *UsedSpaceAnnouncement) SetContainerID(cid *ID) { func (a *UsedSpaceAnnouncement) SetContainerID(cid *cid.ID) {
(*container.UsedSpaceAnnouncement)(a).SetContainerID(cid.ToV2()) (*container.UsedSpaceAnnouncement)(a).SetContainerID(cid.ToV2())
} }

View file

@ -5,6 +5,8 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -12,18 +14,17 @@ import (
func TestAnnouncement(t *testing.T) { func TestAnnouncement(t *testing.T) {
const epoch, usedSpace uint64 = 10, 100 const epoch, usedSpace uint64 = 10, 100
cidValue := [32]byte{1, 2, 3} cidValue := [sha256.Size]byte{1, 2, 3}
cid := container.NewID() id := cidtest.GenerateWithChecksum(cidValue)
cid.SetSHA256(cidValue)
a := container.NewAnnouncement() a := container.NewAnnouncement()
a.SetEpoch(epoch) a.SetEpoch(epoch)
a.SetContainerID(cid) a.SetContainerID(id)
a.SetUsedSpace(usedSpace) a.SetUsedSpace(usedSpace)
require.Equal(t, epoch, a.Epoch()) require.Equal(t, epoch, a.Epoch())
require.Equal(t, usedSpace, a.UsedSpace()) require.Equal(t, usedSpace, a.UsedSpace())
require.Equal(t, cid, a.ContainerID()) require.Equal(t, id, a.ContainerID())
t.Run("test v2", func(t *testing.T) { t.Run("test v2", func(t *testing.T) {
const newEpoch, newUsedSpace uint64 = 20, 200 const newEpoch, newUsedSpace uint64 = 20, 200
@ -45,7 +46,7 @@ func TestAnnouncement(t *testing.T) {
require.Equal(t, newEpoch, newA.Epoch()) require.Equal(t, newEpoch, newA.Epoch())
require.Equal(t, newUsedSpace, newA.UsedSpace()) require.Equal(t, newUsedSpace, newA.UsedSpace())
require.Equal(t, container.NewIDFromV2(newCID), newA.ContainerID()) require.Equal(t, cid.NewFromV2(newCID), newA.ContainerID())
}) })
} }
@ -54,8 +55,7 @@ func TestUsedSpaceEncoding(t *testing.T) {
a.SetUsedSpace(13) a.SetUsedSpace(13)
a.SetEpoch(666) a.SetEpoch(666)
id := container.NewID() id := cidtest.Generate()
id.SetSHA256([sha256.Size]byte{1, 2, 3})
a.SetContainerID(id) a.SetContainerID(id)

View file

@ -5,6 +5,7 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/session" "github.com/nspcc-dev/neofs-api-go/pkg/session"
@ -63,13 +64,13 @@ func NewContainerFromV2(c *container.Container) *Container {
// CalculateID calculates container identifier // CalculateID calculates container identifier
// based on its structure. // based on its structure.
func CalculateID(c *Container) *ID { func CalculateID(c *Container) *cid.ID {
data, err := c.ToV2().StableMarshal(nil) data, err := c.ToV2().StableMarshal(nil)
if err != nil { if err != nil {
panic(err) panic(err)
} }
id := NewID() id := cid.New()
id.SetSHA256(sha256.Sum256(data)) id.SetSHA256(sha256.Sum256(data))
return id return id

View file

@ -10,7 +10,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/container"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/token" sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
"github.com/nspcc-dev/neofs-crypto/test" "github.com/nspcc-dev/neofs-crypto/test"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -98,8 +98,7 @@ func TestContainerEncoding(t *testing.T) {
} }
func TestContainer_SessionToken(t *testing.T) { func TestContainer_SessionToken(t *testing.T) {
tok := token.NewSessionToken() tok := sessiontest.Generate()
tok.SetID([]byte{1, 2, 3})
cnr := container.New() cnr := container.New()

View file

@ -16,11 +16,9 @@ func randSHA256Checksum() (cs [sha256.Size]byte) {
} }
func TestID_ToV2(t *testing.T) { func TestID_ToV2(t *testing.T) {
id := cid.New()
checksum := randSHA256Checksum() checksum := randSHA256Checksum()
id.SetSHA256(checksum) id := cidtest.GenerateWithChecksum(checksum)
idV2 := id.ToV2() idV2 := id.ToV2()

View file

@ -4,7 +4,7 @@ import (
"errors" "errors"
"strings" "strings"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
) )
@ -36,14 +36,14 @@ func (a *Address) ToV2() *refs.Address {
} }
// ContainerID returns container identifier. // ContainerID returns container identifier.
func (a *Address) ContainerID() *container.ID { func (a *Address) ContainerID() *cid.ID {
return container.NewIDFromV2( return cid.NewFromV2(
(*refs.Address)(a).GetContainerID(), (*refs.Address)(a).GetContainerID(),
) )
} }
// SetContainerID sets container identifier. // SetContainerID sets container identifier.
func (a *Address) SetContainerID(id *container.ID) { func (a *Address) SetContainerID(id *cid.ID) {
(*refs.Address)(a).SetContainerID(id.ToV2()) (*refs.Address)(a).SetContainerID(id.ToV2())
} }
@ -64,20 +64,20 @@ func (a *Address) Parse(s string) error {
var ( var (
err error err error
oid = NewID() oid = NewID()
cid = container.NewID() id = cid.New()
parts = strings.Split(s, addressSeparator) parts = strings.Split(s, addressSeparator)
) )
if len(parts) != addressParts { if len(parts) != addressParts {
return errInvalidAddressString return errInvalidAddressString
} else if err = cid.Parse(parts[0]); err != nil { } else if err = id.Parse(parts[0]); err != nil {
return err return err
} else if err = oid.Parse(parts[1]); err != nil { } else if err = oid.Parse(parts[1]); err != nil {
return err return err
} }
a.SetObjectID(oid) a.SetObjectID(oid)
a.SetContainerID(cid) a.SetContainerID(id)
return nil return nil
} }

View file

@ -4,19 +4,18 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestAddress_SetContainerID(t *testing.T) { func TestAddress_SetContainerID(t *testing.T) {
a := NewAddress() a := NewAddress()
cid := container.NewID() id := cidtest.Generate()
cid.SetSHA256(randSHA256Checksum(t))
a.SetContainerID(cid) a.SetContainerID(id)
require.Equal(t, cid, a.ContainerID()) require.Equal(t, id, a.ContainerID())
} }
func TestAddress_SetObjectID(t *testing.T) { func TestAddress_SetObjectID(t *testing.T) {
@ -30,8 +29,7 @@ func TestAddress_SetObjectID(t *testing.T) {
} }
func TestAddress_Parse(t *testing.T) { func TestAddress_Parse(t *testing.T) {
cid := container.NewID() cid := cidtest.Generate()
cid.SetSHA256(randSHA256Checksum(t))
oid := NewID() oid := NewID()
oid.SetSHA256(randSHA256Checksum(t)) oid.SetSHA256(randSHA256Checksum(t))
@ -64,7 +62,7 @@ func TestAddress_Parse(t *testing.T) {
func TestAddressEncoding(t *testing.T) { func TestAddressEncoding(t *testing.T) {
a := NewAddress() a := NewAddress()
a.SetObjectID(randID(t)) a.SetObjectID(randID(t))
a.SetContainerID(randCID(t)) a.SetContainerID(cidtest.Generate())
t.Run("binary", func(t *testing.T) { t.Run("binary", func(t *testing.T) {
data, err := a.Marshal() data, err := a.Marshal()

View file

@ -2,9 +2,9 @@ package object
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/pkg/session"
"github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/object"
) )
@ -71,7 +71,7 @@ func (o *RawObject) SetPayloadSize(v uint64) {
} }
// SetContainerID sets identifier of the related container. // SetContainerID sets identifier of the related container.
func (o *RawObject) SetContainerID(v *container.ID) { func (o *RawObject) SetContainerID(v *cid.ID) {
o.setContainerID(v) o.setContainerID(v)
} }
@ -127,7 +127,7 @@ func (o *RawObject) SetParent(v *Object) {
// SetSessionToken sets token of the session // SetSessionToken sets token of the session
// within which object was created. // within which object was created.
func (o *RawObject) SetSessionToken(v *token.SessionToken) { func (o *RawObject) SetSessionToken(v *session.Token) {
o.setSessionToken(v) o.setSessionToken(v)
} }

View file

@ -6,9 +6,9 @@ import (
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cidtest "github.com/nspcc-dev/neofs-api-go/pkg/container/id/test"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
"github.com/nspcc-dev/neofs-api-go/pkg/token" sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
"github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -20,13 +20,6 @@ func randID(t *testing.T) *ID {
return id return id
} }
func randCID(t *testing.T) *container.ID {
id := container.NewID()
id.SetSHA256(randSHA256Checksum(t))
return id
}
func randSHA256Checksum(t *testing.T) (cs [sha256.Size]byte) { func randSHA256Checksum(t *testing.T) (cs [sha256.Size]byte) {
_, err := rand.Read(cs[:]) _, err := rand.Read(cs[:])
require.NoError(t, err) require.NoError(t, err)
@ -98,10 +91,7 @@ func TestRawObject_SetPayloadSize(t *testing.T) {
func TestRawObject_SetContainerID(t *testing.T) { func TestRawObject_SetContainerID(t *testing.T) {
obj := NewRaw() obj := NewRaw()
checksum := randSHA256Checksum(t) cid := cidtest.Generate()
cid := container.NewID()
cid.SetSHA256(checksum)
obj.SetContainerID(cid) obj.SetContainerID(cid)
@ -111,11 +101,7 @@ func TestRawObject_SetContainerID(t *testing.T) {
func TestRawObject_SetOwnerID(t *testing.T) { func TestRawObject_SetOwnerID(t *testing.T) {
obj := NewRaw() obj := NewRaw()
w := new(owner.NEO3Wallet) ownerID := ownertest.Generate()
_, _ = rand.Read(w.Bytes())
ownerID := owner.NewID()
ownerID.SetNeo3Wallet(w)
obj.SetOwnerID(ownerID) obj.SetOwnerID(ownerID)
@ -208,7 +194,7 @@ func TestRawObject_SetParent(t *testing.T) {
par := NewRaw() par := NewRaw()
par.SetID(randID(t)) par.SetID(randID(t))
par.SetContainerID(container.NewID()) par.SetContainerID(cidtest.Generate())
par.SetSignature(pkg.NewSignature()) par.SetSignature(pkg.NewSignature())
parObj := par.Object() parObj := par.Object()
@ -230,8 +216,7 @@ func TestRawObject_ToV2(t *testing.T) {
func TestRawObject_SetSessionToken(t *testing.T) { func TestRawObject_SetSessionToken(t *testing.T) {
obj := NewRaw() obj := NewRaw()
tok := token.NewSessionToken() tok := sessiontest.Generate()
tok.SetID([]byte{1, 2, 3})
obj.SetSessionToken(tok) obj.SetSessionToken(tok)

View file

@ -2,9 +2,9 @@ package object
import ( import (
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/nspcc-dev/neofs-api-go/pkg/token" "github.com/nspcc-dev/neofs-api-go/pkg/session"
"github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
) )
@ -108,15 +108,15 @@ func (o *rwObject) setPayloadSize(v uint64) {
} }
// ContainerID returns identifier of the related container. // ContainerID returns identifier of the related container.
func (o *rwObject) ContainerID() *container.ID { func (o *rwObject) ContainerID() *cid.ID {
return container.NewIDFromV2( return cid.NewFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
GetContainerID(), GetContainerID(),
) )
} }
func (o *rwObject) setContainerID(v *container.ID) { func (o *rwObject) setContainerID(v *cid.ID) {
o.setHeaderField(func(h *object.Header) { o.setHeaderField(func(h *object.Header) {
h.SetContainerID(v.ToV2()) h.SetContainerID(v.ToV2())
}) })
@ -327,15 +327,15 @@ func (o *rwObject) resetRelations() {
// SessionToken returns token of the session // SessionToken returns token of the session
// within which object was created. // within which object was created.
func (o *rwObject) SessionToken() *token.SessionToken { func (o *rwObject) SessionToken() *session.Token {
return token.NewSessionTokenFromV2( return session.NewTokenFromV2(
(*object.Object)(o). (*object.Object)(o).
GetHeader(). GetHeader().
GetSessionToken(), GetSessionToken(),
) )
} }
func (o *rwObject) setSessionToken(v *token.SessionToken) { func (o *rwObject) setSessionToken(v *session.Token) {
o.setHeaderField(func(h *object.Header) { o.setHeaderField(func(h *object.Header) {
h.SetSessionToken(v.ToV2()) h.SetSessionToken(v.ToV2())
}) })

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neofs-api-go/pkg" "github.com/nspcc-dev/neofs-api-go/pkg"
"github.com/nspcc-dev/neofs-api-go/pkg/container" cid "github.com/nspcc-dev/neofs-api-go/pkg/container/id"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" "github.com/nspcc-dev/neofs-api-go/pkg/owner"
v2object "github.com/nspcc-dev/neofs-api-go/v2/object" v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
) )
@ -199,7 +199,7 @@ func (f *SearchFilters) AddObjectVersionFilter(op SearchMatchType, v *pkg.Versio
f.addReservedFilter(op, fKeyVersion, v) f.addReservedFilter(op, fKeyVersion, v)
} }
func (f *SearchFilters) AddObjectContainerIDFilter(m SearchMatchType, id *container.ID) { func (f *SearchFilters) AddObjectContainerIDFilter(m SearchMatchType, id *cid.ID) {
f.addReservedFilter(m, fKeyContainerID, id) f.addReservedFilter(m, fKeyContainerID, id)
} }

View file

@ -1,7 +1,6 @@
package owner_test package owner_test
import ( import (
"crypto/rand"
"strconv" "strconv"
"testing" "testing"
@ -12,21 +11,8 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func randID(t *testing.T) *ID {
id := NewID()
wallet := new(NEO3Wallet)
_, err := rand.Read(wallet.Bytes())
require.NoError(t, err)
id.SetNeo3Wallet(wallet)
return id
}
func TestIDV2(t *testing.T) { func TestIDV2(t *testing.T) {
id := randID(t) id := ownertest.Generate()
idV2 := id.ToV2() idV2 := id.ToV2()
@ -73,7 +59,7 @@ func TestID_Parse(t *testing.T) {
} }
func TestIDEncoding(t *testing.T) { func TestIDEncoding(t *testing.T) {
id := randID(t) id := ownertest.Generate()
t.Run("binary", func(t *testing.T) { t.Run("binary", func(t *testing.T) {
data, err := id.Marshal() data, err := id.Marshal()

View file

@ -1,10 +1,9 @@
package session_test package session_test
import ( import (
"crypto/rand"
"testing" "testing"
"github.com/nspcc-dev/neofs-api-go/pkg/owner" ownertest "github.com/nspcc-dev/neofs-api-go/pkg/owner/test"
"github.com/nspcc-dev/neofs-api-go/pkg/session" "github.com/nspcc-dev/neofs-api-go/pkg/session"
sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test" sessiontest "github.com/nspcc-dev/neofs-api-go/pkg/session/test"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -22,12 +21,7 @@ func TestSessionToken_SetID(t *testing.T) {
func TestSessionToken_SetOwnerID(t *testing.T) { func TestSessionToken_SetOwnerID(t *testing.T) {
token := session.NewToken() token := session.NewToken()
w := new(owner.NEO3Wallet) ownerID := ownertest.Generate()
_, err := rand.Read(w.Bytes())
require.NoError(t, err)
ownerID := owner.NewID()
ownerID.SetNeo3Wallet(w)
token.SetOwnerID(ownerID) token.SetOwnerID(ownerID)

View file

@ -27,7 +27,7 @@ func TestBearerToken_Issuer(t *testing.T) {
bearerToken.SetEACLTable(eacl.NewTable()) bearerToken.SetEACLTable(eacl.NewTable())
require.NoError(t, bearerToken.SignToken(key)) require.NoError(t, bearerToken.SignToken(key))
require.Equal(t, bearerToken.Issuer().String(), ownerID.String()) require.True(t, ownerID.Equal(bearerToken.Issuer()))
}) })
} }

View file

@ -1,67 +0,0 @@
package token
import (
"crypto/rand"
"testing"
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
"github.com/stretchr/testify/require"
)
func TestSessionToken_SetID(t *testing.T) {
token := NewSessionToken()
id := []byte{1, 2, 3}
token.SetID(id)
require.Equal(t, id, token.ID())
}
func TestSessionToken_SetOwnerID(t *testing.T) {
token := NewSessionToken()
w := new(owner.NEO3Wallet)
_, err := rand.Read(w.Bytes())
require.NoError(t, err)
ownerID := owner.NewID()
ownerID.SetNeo3Wallet(w)
token.SetOwnerID(ownerID)
require.Equal(t, ownerID, token.OwnerID())
}
func TestSessionToken_SetSessionKey(t *testing.T) {
token := NewSessionToken()
key := []byte{1, 2, 3}
token.SetSessionKey(key)
require.Equal(t, key, token.SessionKey())
}
func TestSessionTokenEncoding(t *testing.T) {
tok := NewSessionToken()
tok.SetID([]byte("id"))
t.Run("binary", func(t *testing.T) {
data, err := tok.Marshal()
require.NoError(t, err)
tok2 := NewSessionToken()
require.NoError(t, tok2.Unmarshal(data))
require.Equal(t, tok, tok2)
})
t.Run("json", func(t *testing.T) {
data, err := tok.MarshalJSON()
require.NoError(t, err)
tok2 := NewSessionToken()
require.NoError(t, tok2.UnmarshalJSON(data))
require.Equal(t, tok, tok2)
})
}