github.com/cs3org/reva/v2@v2.27.7/internal/http/services/owncloud/ocdav/net/context_test.go (about) 1 // Copyright 2018-2022 CERN 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package net_test 20 21 import ( 22 "context" 23 24 userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" 25 provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" 26 "github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav/net" 27 ctxpkg "github.com/cs3org/reva/v2/pkg/ctx" 28 29 . "github.com/onsi/ginkgo/v2" 30 . "github.com/onsi/gomega" 31 ) 32 33 var _ = Describe("Net", func() { 34 var ( 35 alice = &userpb.User{ 36 Id: &userpb.UserId{ 37 OpaqueId: "alice", 38 }, 39 Username: "alice", 40 } 41 bob = &userpb.User{ 42 Id: &userpb.UserId{ 43 OpaqueId: "bob", 44 }, 45 Username: "bob", 46 } 47 spaceManager = &userpb.User{ 48 Id: &userpb.UserId{ 49 OpaqueId: "space-id", 50 }, 51 Username: "virtual", 52 } 53 mdSpaceManager = &provider.ResourceInfo{ 54 Owner: &userpb.UserId{ 55 OpaqueId: "user-1", 56 Type: userpb.UserType_USER_TYPE_SPACE_OWNER, 57 }, 58 PermissionSet: &provider.ResourcePermissions{ 59 AddGrant: true, 60 }, 61 } 62 63 mdSpaceViewer = &provider.ResourceInfo{ 64 Owner: &userpb.UserId{ 65 OpaqueId: "user-1", 66 Type: userpb.UserType_USER_TYPE_SPACE_OWNER, 67 }, 68 PermissionSet: &provider.ResourcePermissions{ 69 ListContainer: true, 70 }, 71 } 72 aliceCtx = ctxpkg.ContextSetUser(context.Background(), alice) 73 bobCtx = ctxpkg.ContextSetUser(context.Background(), bob) 74 ) 75 76 Describe("IsCurrentUserOwnerOrManager", func() { 77 It("returns true", func() { 78 Expect(net.IsCurrentUserOwnerOrManager(aliceCtx, alice.Id, nil)).To(BeTrue()) 79 }) 80 81 It("returns false", func() { 82 Expect(net.IsCurrentUserOwnerOrManager(bobCtx, alice.Id, nil)).To(BeFalse()) 83 }) 84 85 It("user is space manager", func() { 86 Expect(net.IsCurrentUserOwnerOrManager(bobCtx, spaceManager.Id, mdSpaceManager)).To(BeTrue()) 87 }) 88 89 It("user is space viewer", func() { 90 Expect(net.IsCurrentUserOwnerOrManager(bobCtx, spaceManager.Id, mdSpaceViewer)).To(BeFalse()) 91 }) 92 }) 93 })