Skip to content

Commit

Permalink
tests: add unit tests for public share provider
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Apr 20, 2024
1 parent 2d0c2ca commit 45a3673
Show file tree
Hide file tree
Showing 5 changed files with 578 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/unreleased/fix-public-share-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Bugfix: Fix public share update

We fixed the permission check for updating public shares. When updating the permissions of a public share while not providing a password, the check must be against the new permissions to take into account that users can opt out only for view permissions.

https://github.com/cs3org/reva/pull/4633
https://github.com/cs3org/reva/pull/4622
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s *service) Register(ss *grpc.Server) {
link.RegisterLinkAPIServer(ss, s)
}

func parseConfig(m map[string]interface{}) (*config, error) {
func ParseConfig(m map[string]interface{}) (*config, error) {
c := &config{}
if err := mapstructure.Decode(m, c); err != nil {
err = errors.Wrap(err, "error decoding config")
Expand All @@ -118,7 +118,7 @@ func parseConfig(m map[string]interface{}) (*config, error) {
return c, nil
}

func parsePasswordPolicy(m map[string]interface{}) (*passwordPolicy, error) {
func ParsePasswordPolicy(m map[string]interface{}) (*passwordPolicy, error) {
p := &passwordPolicy{}
if err := mapstructure.Decode(m, p); err != nil {
err = errors.Wrap(err, "error decoding password policy config")
Expand All @@ -129,11 +129,11 @@ func parsePasswordPolicy(m map[string]interface{}) (*passwordPolicy, error) {

// New creates a new public share provider svc initialized from defaults
func NewDefault(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error) {
c, err := parseConfig(m)
c, err := ParseConfig(m)
if err != nil {
return nil, err
}
p, err := parsePasswordPolicy(c.PasswordPolicy)
p, err := ParsePasswordPolicy(c.PasswordPolicy)
if err != nil {
return nil, err
}
Expand All @@ -149,7 +149,7 @@ func NewDefault(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error
if err != nil {
return nil, err
}
return New(gatewaySelector, sm, c, p), nil
return New(gatewaySelector, sm, c, p)
}

// New creates a new user share provider svc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package publicshareprovider_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestPublicShareProvider(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "PublicShareProvider Suite")
}
Loading

0 comments on commit 45a3673

Please sign in to comment.