package frostfs import ( "context" "testing" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/authmate" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/accessbox" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/creds/tokens" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/bearer" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" ) func TestGetCredsObject(t *testing.T) { ctx, bktName, payload, newPayload := context.Background(), "bucket", []byte("payload"), []byte("new-payload") key, err := keys.NewPrivateKey() require.NoError(t, err) var userID user.ID userID.SetScriptHash(key.PublicKey().GetScriptHash()) var token bearer.Token err = token.Sign(key.PrivateKey) require.NoError(t, err) ctx = middleware.SetBox(ctx, &middleware.Box{AccessBox: &accessbox.Box{ Gate: &accessbox.GateData{ BearerToken: &token, }, }}) frostfs := NewAuthmateFrostFS(layer.NewTestFrostFS(key), zaptest.NewLogger(t)) cid, err := frostfs.CreateContainer(ctx, authmate.PrmContainerCreate{ FriendlyName: bktName, Owner: userID, }) require.NoError(t, err) objID, err := frostfs.CreateObject(ctx, tokens.PrmObjectCreate{ Container: cid, Payload: payload, }) require.NoError(t, err) var addr oid.Address addr.SetContainer(cid) addr.SetObject(objID) obj, err := frostfs.GetCredsObject(ctx, addr) require.NoError(t, err) require.Equal(t, payload, obj.Payload()) _, err = frostfs.CreateObject(ctx, tokens.PrmObjectCreate{ Container: cid, Payload: newPayload, NewVersionFor: &objID, }) require.NoError(t, err) obj, err = frostfs.GetCredsObject(ctx, addr) require.NoError(t, err) require.Equal(t, newPayload, obj.Payload()) }