Skip to content

Commit

Permalink
fix more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Feb 16, 2022
1 parent dc13136 commit 27f99a5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
7 changes: 3 additions & 4 deletions pkg/storage/utils/decomposedfs/grants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package decomposedfs_test
import (
"io/fs"
"os"
"path"
"path/filepath"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand Down Expand Up @@ -115,7 +114,7 @@ var _ = Describe("Grants", func() {
err = env.Fs.AddGrant(env.Ctx, ref, grant)
Expect(err).ToNot(HaveOccurred())

localPath := path.Join(env.Root, "nodes", n.ID)
localPath := n.InternalPath()
attr, err := xattr.Get(localPath, xattrs.GrantUserAcePrefix+grant.Grantee.GetUserId().OpaqueId)
Expect(err).ToNot(HaveOccurred())
Expect(string(attr)).To(Equal("\x00t=A:f=:p=rw"))
Expand All @@ -125,8 +124,8 @@ var _ = Describe("Grants", func() {
err := env.Fs.AddGrant(env.Ctx, ref, grant)
Expect(err).ToNot(HaveOccurred())

spacesPath := filepath.Join(env.Root, "spaces")
tfs.root = spacesPath
spaceTypesPath := filepath.Join(env.Root, "spacetypes")
tfs.root = spaceTypesPath
entries, err := fs.ReadDir(tfs, "share")
Expect(err).ToNot(HaveOccurred())
Expect(len(entries)).To(BeNumerically(">=", 1))
Expand Down
14 changes: 7 additions & 7 deletions pkg/storage/utils/decomposedfs/recycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var _ = Describe("Recycle", func() {

BeforeEach(func() {
// in this scenario user "userid" has this permissions:
registerPermissions(env.Permissions, "userid", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
ListRecycle: true,
Expand Down Expand Up @@ -133,7 +133,7 @@ var _ = Describe("Recycle", func() {
})

// in this scenario user "userid" has this permissions:
registerPermissions(env.Permissions, "userid", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
ListRecycle: true,
Expand Down Expand Up @@ -245,7 +245,7 @@ var _ = Describe("Recycle", func() {
Expect(projectID).ToNot(BeNil())

// in this scenario user "userid" has this permissions:
registerPermissions(env.Permissions, "userid", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
ListRecycle: true,
Expand Down Expand Up @@ -317,7 +317,7 @@ var _ = Describe("Recycle", func() {
})

// in this scenario user "userid" has this permissions:
registerPermissions(env.Permissions, "userid", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
Delete: true,
ListRecycle: true,
PurgeRecycle: true,
Expand Down Expand Up @@ -395,22 +395,22 @@ var _ = Describe("Recycle", func() {
ctx = ctxpkg.ContextSetUser(context.Background(), &userpb.User{
Id: &userpb.UserId{
Idp: "maliciousidp",
OpaqueId: "hacker",
OpaqueId: "h-a-c-k-er",
Type: userpb.UserType_USER_TYPE_PRIMARY,
},
Username: "mrhacker",
})

// in this scenario user "userid" has this permissions:
registerPermissions(env.Permissions, "userid", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
Delete: true,
ListRecycle: true,
PurgeRecycle: true,
RestoreRecycleItem: true,
})

// and user "hacker" has no permissions:
registerPermissions(env.Permissions, "hacker", &provider.ResourcePermissions{})
registerPermissions(env.Permissions, "h-a-c-k-er", &provider.ResourcePermissions{})
})

It("cannot delete, list, purge or restore", func() {
Expand Down
20 changes: 10 additions & 10 deletions pkg/storage/utils/decomposedfs/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,31 @@ var _ = Describe("File uploads", func() {
spaceID string

o *options.Options
lookup *lookup.Lookup
lu *lookup.Lookup
permissions *mocks.PermissionsChecker
bs *treemocks.Blobstore
)

BeforeEach(func() {
ref = &provider.Reference{
ResourceId: &provider.ResourceId{
StorageId: "userid",
StorageId: "u-s-e-r-id",
},
Path: "/foo",
}

user = &userpb.User{
Id: &userpb.UserId{
Idp: "idp",
OpaqueId: "userid",
OpaqueId: "u-s-e-r-id",
Type: userpb.UserType_USER_TYPE_PRIMARY,
},
Username: "username",
}

rootRef = &provider.Reference{
ResourceId: &provider.ResourceId{
StorageId: "userid",
StorageId: "u-s-e-r-id",
},
Path: "/",
}
Expand All @@ -95,7 +95,7 @@ var _ = Describe("File uploads", func() {
"root": tmpRoot,
})
Expect(err).ToNot(HaveOccurred())
lookup = &lookup.Lookup{Options: o}
lu = &lookup.Lookup{Options: o}
permissions = &mocks.PermissionsChecker{}
bs = &treemocks.Blobstore{}
})
Expand All @@ -110,8 +110,8 @@ var _ = Describe("File uploads", func() {
BeforeEach(func() {
permissions.On("HasPermission", mock.Anything, mock.Anything, mock.Anything).Times(1).Return(true, nil)
var err error
tree := tree.New(o.Root, true, true, lookup, bs)
fs, err = decomposedfs.New(o, lookup, permissions, tree)
tree := tree.New(o.Root, true, true, lu, bs)
fs, err = decomposedfs.New(o, lu, permissions, tree)
Expect(err).ToNot(HaveOccurred())

resp, err := fs.CreateStorageSpace(ctx, &provider.CreateStorageSpaceRequest{Owner: user, Type: "personal"})
Expand Down Expand Up @@ -142,7 +142,7 @@ var _ = Describe("File uploads", func() {

When("the user wants to initiate a file upload", func() {
It("fails", func() {
msg := "error: permission denied: userid/foo"
msg := "error: permission denied: u-s-e-r-id/foo"
_, err := fs.InitiateUpload(ctx, ref, 10, map[string]string{})
Expect(err).To(MatchError(msg))
})
Expand All @@ -153,7 +153,7 @@ var _ = Describe("File uploads", func() {
JustBeforeEach(func() {
var err error
// the space name attribute is the stop condition in the lookup
h, err := lookup.RootNode(ctx)
h, err := lu.NodeFromResource(ctx, rootRef)
Expect(err).ToNot(HaveOccurred())
err = xattr.Set(h.InternalPath(), xattrs.SpaceNameAttr, []byte("username"))
Expect(err).ToNot(HaveOccurred())
Expand All @@ -162,7 +162,7 @@ var _ = Describe("File uploads", func() {

When("the user wants to initiate a file upload", func() {
It("fails", func() {
msg := "error: permission denied: userid/foo"
msg := "error: permission denied: u-s-e-r-id/foo"
_, err := fs.InitiateUpload(ctx, ref, 10, map[string]string{})
Expect(err).To(MatchError(msg))
})
Expand Down

0 comments on commit 27f99a5

Please sign in to comment.