From 73a0ad85f5d4b6a03d2c65731a61c4d738c26ec6 Mon Sep 17 00:00:00 2001 From: Michael Barz Date: Fri, 15 Sep 2023 09:52:14 +0200 Subject: [PATCH] fix the capability naming --- changelog/unreleased/add-passwod-policies.md | 1 + .../owncloud/ocs/data/capabilities.go | 33 +++++++++---------- .../handlers/apps/sharing/shares/shares.go | 18 +++++----- pkg/password/password_policies.go | 4 +-- pkg/password/password_policies_test.go | 4 +-- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/changelog/unreleased/add-passwod-policies.md b/changelog/unreleased/add-passwod-policies.md index df935246b7..c84e82737d 100644 --- a/changelog/unreleased/add-passwod-policies.md +++ b/changelog/unreleased/add-passwod-policies.md @@ -2,4 +2,5 @@ Enhancement: Add the password policies Add the password policies OCIS-3767 +https://github.com/cs3org/reva/pull/4190 https://github.com/cs3org/reva/pull/4147 diff --git a/internal/http/services/owncloud/ocs/data/capabilities.go b/internal/http/services/owncloud/ocs/data/capabilities.go index a53ac679b9..27f2456166 100644 --- a/internal/http/services/owncloud/ocs/data/capabilities.go +++ b/internal/http/services/owncloud/ocs/data/capabilities.go @@ -50,14 +50,14 @@ type CapabilitiesData struct { // Capabilities groups several capability aspects type Capabilities struct { - Core *CapabilitiesCore `json:"core" xml:"core"` - Checksums *CapabilitiesChecksums `json:"checksums" xml:"checksums"` - Files *CapabilitiesFiles `json:"files" xml:"files" mapstructure:"files"` - Dav *CapabilitiesDav `json:"dav" xml:"dav"` - FilesSharing *CapabilitiesFilesSharing `json:"files_sharing" xml:"files_sharing" mapstructure:"files_sharing"` - Spaces *Spaces `json:"spaces,omitempty" xml:"spaces,omitempty" mapstructure:"spaces"` - Graph *CapabilitiesGraph `json:"graph,omitempty" xml:"graph,omitempty" mapstructure:"graph"` - PasswordPolicies *CapabilitiesPasswordPolicies `json:"password_policies,omitempty" xml:"password_policies,omitempty" mapstructure:"password_policies"` + Core *CapabilitiesCore `json:"core" xml:"core"` + Checksums *CapabilitiesChecksums `json:"checksums" xml:"checksums"` + Files *CapabilitiesFiles `json:"files" xml:"files" mapstructure:"files"` + Dav *CapabilitiesDav `json:"dav" xml:"dav"` + FilesSharing *CapabilitiesFilesSharing `json:"files_sharing" xml:"files_sharing" mapstructure:"files_sharing"` + Spaces *Spaces `json:"spaces,omitempty" xml:"spaces,omitempty" mapstructure:"spaces"` + Graph *CapabilitiesGraph `json:"graph,omitempty" xml:"graph,omitempty" mapstructure:"graph"` + PasswordPolicy *CapabilitiesPasswordPolicy `json:"password_policy,omitempty" xml:"password_policy,omitempty" mapstructure:"password_policy"` Notifications *CapabilitiesNotifications `json:"notifications,omitempty" xml:"notifications,omitempty"` } @@ -86,15 +86,14 @@ type CapabilitiesGraph struct { Users CapabilitiesGraphUsers `json:"users" xml:"users" mapstructure:"users"` } -// CapabilitiesPasswordPolicies hold the password policies capabilities -type CapabilitiesPasswordPolicies struct { - MinCharacters int `json:"min_characters" xml:"min_characters" mapstructure:"min_characters"` - MaxCharacters int `json:"max_characters" xml:"max_characters" mapstructure:"max_characters"` - MinLowerCaseCharacters int `json:"min_lowercase_characters" xml:"min_lowercase_characters" mapstructure:"min_lowercase_characters"` - MinUpperCaseCharacters int `json:"min_uppercase_characters" xml:"min_uppercase_characters" mapstructure:"min_uppercase_characters"` - MinDigits int `json:"min_digits" xml:"min_digits" mapstructure:"min_digits"` - MinSpecialCharacters int `json:"min_special_characters" xml:"min_special_characters" mapstructure:"min_special_characters"` - SpecialCharacters string `json:"special_characters" xml:"special_characters" mapstructure:"special_characters"` +// CapabilitiesPasswordPolicy hold the password policy capabilities +type CapabilitiesPasswordPolicy struct { + MinCharacters int `json:"min_characters" xml:"min_characters" mapstructure:"min_characters"` + MaxCharacters int `json:"max_characters" xml:"max_characters" mapstructure:"max_characters"` + MinLowerCaseCharacters int `json:"min_lowercase_characters" xml:"min_lowercase_characters" mapstructure:"min_lowercase_characters"` + MinUpperCaseCharacters int `json:"min_uppercase_characters" xml:"min_uppercase_characters" mapstructure:"min_uppercase_characters"` + MinDigits int `json:"min_digits" xml:"min_digits" mapstructure:"min_digits"` + MinSpecialCharacters int `json:"min_special_characters" xml:"min_special_characters" mapstructure:"min_special_characters"` } // CapabilitiesGraphUsers holds the graph user capabilities diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index ff239b649c..28ed61adc7 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -1591,15 +1591,15 @@ func publicPwdEnforced(c *config.Config) passwordEnforced { } func passwordPolicies(c *config.Config) password.Validator { - if c.Capabilities.Capabilities == nil || c.Capabilities.Capabilities.PasswordPolicies == nil { - return password.NewPasswordPolicies(0, 0, 0, 0, 0) - } - return password.NewPasswordPolicies( - c.Capabilities.Capabilities.PasswordPolicies.MinCharacters, - c.Capabilities.Capabilities.PasswordPolicies.MinLowerCaseCharacters, - c.Capabilities.Capabilities.PasswordPolicies.MinUpperCaseCharacters, - c.Capabilities.Capabilities.PasswordPolicies.MinDigits, - c.Capabilities.Capabilities.PasswordPolicies.MinSpecialCharacters, + if c.Capabilities.Capabilities == nil || c.Capabilities.Capabilities.PasswordPolicy == nil { + return password.NewPasswordPolicy(0, 0, 0, 0, 0) + } + return password.NewPasswordPolicy( + c.Capabilities.Capabilities.PasswordPolicy.MinCharacters, + c.Capabilities.Capabilities.PasswordPolicy.MinLowerCaseCharacters, + c.Capabilities.Capabilities.PasswordPolicy.MinUpperCaseCharacters, + c.Capabilities.Capabilities.PasswordPolicy.MinDigits, + c.Capabilities.Capabilities.PasswordPolicy.MinSpecialCharacters, ) } diff --git a/pkg/password/password_policies.go b/pkg/password/password_policies.go index 9a499ba8ce..4cada0b9d3 100644 --- a/pkg/password/password_policies.go +++ b/pkg/password/password_policies.go @@ -27,8 +27,8 @@ type Policies struct { specialCharactersRegexp *regexp.Regexp } -// NewPasswordPolicies returns a new NewPasswordPolicies instance -func NewPasswordPolicies(minCharacters, minLowerCaseCharacters, minUpperCaseCharacters, minDigits, minSpecialCharacters int) Validator { +// NewPasswordPolicy returns a new NewPasswordPolicy instance +func NewPasswordPolicy(minCharacters, minLowerCaseCharacters, minUpperCaseCharacters, minDigits, minSpecialCharacters int) Validator { p := &Policies{ minCharacters: minCharacters, minLowerCaseCharacters: minLowerCaseCharacters, diff --git a/pkg/password/password_policies_test.go b/pkg/password/password_policies_test.go index ddeb7d5e3d..f1874045d5 100644 --- a/pkg/password/password_policies_test.go +++ b/pkg/password/password_policies_test.go @@ -55,7 +55,7 @@ func TestPolicies_Validate(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - s := NewPasswordPolicies( + s := NewPasswordPolicy( tt.fields.minCharacters, tt.fields.minLowerCaseCharacters, tt.fields.minUpperCaseCharacters, @@ -119,7 +119,7 @@ func TestPasswordPolicies_Count(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - i := NewPasswordPolicies( + i := NewPasswordPolicy( tt.fields.wantCharacters, tt.fields.wantLowerCaseCharacters, tt.fields.wantUpperCaseCharacters,