Skip to content

Commit 774e935

Browse files
authored
Fix delete objects permissions bug (treeverse#1260)
1 parent 298093d commit 774e935

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

gateway/handler.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ func authorize(w http.ResponseWriter, req *http.Request, authService simulator.G
247247
o := ctx.Value(ContextKeyOperation).(*operations.Operation)
248248
username := ctx.Value(ContextKeyUser).(*model.User).Username
249249
authContext := ctx.Value(ContextKeyAuthContext).(sig.SigContext)
250+
251+
if len(perms) == 0 {
252+
// Either no permissions are required, or they will be checked later.
253+
return &operations.AuthorizedOperation{
254+
Operation: o,
255+
Principal: username,
256+
}
257+
}
258+
250259
authResp, err := authService.Authorize(&auth.AuthorizationRequest{
251260
Username: username,
252261
RequiredPermissions: perms,

nessie/delete_objects_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package nessie
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
7+
"github.com/aws/aws-sdk-go/aws"
8+
"github.com/aws/aws-sdk-go/service/s3"
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestDeleteObjects(t *testing.T) {
13+
ctx, _, repo := setupTest(t)
14+
const numOfObjects = 10
15+
16+
identifiers := make([]*s3.ObjectIdentifier, 0, numOfObjects)
17+
18+
for i := 1; i <= numOfObjects; i++ {
19+
file := strconv.Itoa(i) + ".txt"
20+
identifiers = append(identifiers, &s3.ObjectIdentifier{
21+
Key: aws.String(masterBranch + "/" + file),
22+
})
23+
_, _ = uploadFileRandomData(ctx, t, repo, masterBranch, file)
24+
}
25+
26+
listOut, err := svc.ListObjects(&s3.ListObjectsInput{
27+
Bucket: aws.String(repo),
28+
Prefix: aws.String(masterBranch + "/"),
29+
})
30+
31+
assert.NoError(t, err)
32+
assert.Len(t, listOut.Contents, numOfObjects)
33+
34+
deleteOut, err := svc.DeleteObjects(&s3.DeleteObjectsInput{
35+
Bucket: aws.String(repo),
36+
Delete: &s3.Delete{
37+
Objects: identifiers,
38+
},
39+
})
40+
41+
assert.NoError(t, err)
42+
assert.Len(t, deleteOut.Deleted, numOfObjects)
43+
44+
listOut, err = svc.ListObjects(&s3.ListObjectsInput{
45+
Bucket: aws.String(repo),
46+
Prefix: aws.String(masterBranch + "/"),
47+
})
48+
49+
assert.NoError(t, err)
50+
assert.Len(t, listOut.Contents, 0)
51+
}

0 commit comments

Comments
 (0)