package frostfs import ( "context" "strings" "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)) cnrID, err := frostfs.CreateContainer(ctx, authmate.PrmContainerCreate{ FriendlyName: bktName, Owner: userID, }) require.NoError(t, err) objID, err := frostfs.CreateObject(ctx, tokens.PrmObjectCreate{ Container: cnrID, Payload: payload, }) require.NoError(t, err) var addr oid.Address addr.SetContainer(cnrID) addr.SetObject(objID) accessKeyID := getAccessKeyID(addr) obj, err := frostfs.GetCredsObject(ctx, tokens.PrmGetCredsObject{ Container: cnrID, AccessKeyID: accessKeyID, }) require.NoError(t, err) require.Equal(t, payload, obj.Payload()) _, err = frostfs.CreateObject(ctx, tokens.PrmObjectCreate{ Container: cnrID, Payload: newPayload, NewVersionForAccessKeyID: accessKeyID, }) require.NoError(t, err) obj, err = frostfs.GetCredsObject(ctx, tokens.PrmGetCredsObject{ Container: cnrID, AccessKeyID: getAccessKeyID(addr), }) require.NoError(t, err) require.Equal(t, newPayload, obj.Payload()) } func getAccessKeyID(addr oid.Address) string { return strings.ReplaceAll(addr.EncodeToString(), "/", "0") }