2024-04-26 14:32:58 +00:00
|
|
|
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"
|
2024-07-15 12:47:19 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2024-04-26 14:32:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
}})
|
|
|
|
|
2024-07-15 12:47:19 +00:00
|
|
|
frostfs := NewAuthmateFrostFS(layer.NewTestFrostFS(key), zaptest.NewLogger(t))
|
2024-04-26 14:32:58 +00:00
|
|
|
|
|
|
|
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())
|
|
|
|
}
|