Skip to content

Commit

Permalink
uplink: add test for copy and move permission denied errors
Browse files Browse the repository at this point in the history
previously the errors returned for CopyObject and MoveObject were
only rpcstatus.Unauthenticated which resulted in unmapped errors.

This adds tests to ensure the satellite is returning the correct
rpc status and it's being mapped to an uplink error.

Change-Id: Idd7911abacc82381c6e483325d6a598adab77213
  • Loading branch information
halkyon committed Sep 28, 2023
1 parent 5e63b72 commit c46ff1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (project *Project) CopyObject(ctx context.Context, oldBucket, oldKey, newBu
NewSegmentKeys: newKeys,
})
if err != nil {
return nil, packageError.Wrap(err)
return nil, convertKnownErrors(err, oldBucket, oldKey)
}

db, err := project.dialMetainfoDB(ctx)
Expand Down
30 changes: 30 additions & 0 deletions testsuite/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,36 @@ func TestVeryLongDownload(t *testing.T) {
})
}

func TestObjectPermissionDenied(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1,
StorageNodeCount: 0,
UplinkCount: 1,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
access := planet.Uplinks[0].Access[planet.Satellites[0].ID()]

deleteAccess, err := access.Share(uplink.Permission{AllowDelete: true}, uplink.SharePrefix{
Bucket: "source-bucket",
})
require.NoError(t, err)

project, err := uplink.OpenProject(ctx, deleteAccess)
require.NoError(t, err)
defer ctx.Check(project.Close)

err = planet.Uplinks[0].Upload(ctx, planet.Satellites[0], "source-bucket", "testkey", []byte("hello"))
require.NoError(t, err)

_, err = project.CopyObject(ctx, "source-bucket", "testkey", "source-bucket", "testkey-copy", nil)
require.Error(t, err)
require.ErrorIs(t, err, uplink.ErrPermissionDenied)

err = project.MoveObject(ctx, "source-bucket", "testkey", "source-bucket", "testkey-copy", nil)
require.Error(t, err)
require.ErrorIs(t, err, uplink.ErrPermissionDenied)
})
}

func assertObject(t *testing.T, obj *uplink.Object, expectedKey string) {
assert.Equal(t, expectedKey, obj.Key)
assert.WithinDuration(t, time.Now(), obj.System.Created, 10*time.Second)
Expand Down

0 comments on commit c46ff1e

Please sign in to comment.