Merge pull request #44 from owncloud/no-validate-uuid
Allow any user id format
This commit is contained in:
@@ -8,3 +8,4 @@ coverage.out
|
||||
/node_modules
|
||||
/assets
|
||||
/ocis-settings-store
|
||||
pkg/proto/v0/ocis-settings-store/
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
Bugfix: Adjust UUID validation to be more tolerant
|
||||
|
||||
The UUID now allows any alphanumeric character and "-", "_", ".", "+" and "@" which
|
||||
can also allow regular user names.
|
||||
|
||||
https://github.com/owncloud/ocis-settings/issues/41
|
||||
@@ -1187,7 +1187,7 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
||||
expectedError: CustomError{
|
||||
ID: "go.micro.client",
|
||||
Code: 500,
|
||||
Detail: "account_uuid: must be a valid UUID.",
|
||||
Detail: "account_uuid: must be in a valid format.",
|
||||
Status: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
@@ -1205,10 +1205,22 @@ func TestSaveGetListSettingsValues(t *testing.T) {
|
||||
expectedError: CustomError{
|
||||
ID: "go.micro.client",
|
||||
Code: 500,
|
||||
Detail: "account_uuid: must be a valid UUID; bundle_key: must be in a valid format; extension: must be in a valid format.",
|
||||
Detail: "account_uuid: must be in a valid format; bundle_key: must be in a valid format; extension: must be in a valid format.",
|
||||
Status: "Internal Server Error",
|
||||
},
|
||||
},
|
||||
{
|
||||
testDataName: "account uuid allows alphanumeric and +_.-@",
|
||||
SettingsValue: proto.SettingsValue{
|
||||
Identifier: &proto.Identifier{
|
||||
Extension: "extension",
|
||||
BundleKey: "bundle",
|
||||
AccountUuid: "123-abc-ABC-+_.-@",
|
||||
SettingKey: "setting",
|
||||
},
|
||||
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
|
||||
},
|
||||
},
|
||||
}
|
||||
client := service.Client()
|
||||
cl := proto.NewValueService("com.owncloud.api.settings", client)
|
||||
|
||||
@@ -2,7 +2,6 @@ package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/owncloud/ocis-pkg/v2/middleware"
|
||||
"github.com/owncloud/ocis-settings/pkg/config"
|
||||
@@ -119,6 +118,5 @@ func getFailsafeIdentifier(c context.Context, identifier *proto.Identifier) *pro
|
||||
identifier.AccountUuid = ownAccountUUID
|
||||
}
|
||||
}
|
||||
identifier.AccountUuid = strings.ToLower(identifier.AccountUuid)
|
||||
return identifier
|
||||
}
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
"github.com/go-ozzo/ozzo-validation/v4/is"
|
||||
"github.com/owncloud/ocis-settings/pkg/proto/v0"
|
||||
)
|
||||
|
||||
var (
|
||||
regexForAccountUUID = regexp.MustCompile(`^[A-Za-z0-9\-_.+@]+$`)
|
||||
accountUUIDRule = []validation.Rule{
|
||||
validation.Required,
|
||||
validation.Match(regexForAccountUUID),
|
||||
}
|
||||
regexForKeys = regexp.MustCompile(`^[A-Za-z0-9\-_]*$`)
|
||||
keyRule = []validation.Rule{
|
||||
validation.Required,
|
||||
validation.Match(regexForKeys),
|
||||
}
|
||||
settingKeyRule = []validation.Rule{
|
||||
validation.Required,
|
||||
validation.Match(regexForKeys),
|
||||
}
|
||||
accountUUIDRule = []validation.Rule{
|
||||
validation.Required,
|
||||
is.UUID,
|
||||
}
|
||||
)
|
||||
|
||||
func validateSaveSettingsBundle(req *proto.SaveSettingsBundleRequest) error {
|
||||
@@ -56,10 +51,9 @@ func validateGetSettingsValue(req *proto.GetSettingsValueRequest) error {
|
||||
}
|
||||
|
||||
func validateListSettingsValues(req *proto.ListSettingsValuesRequest) error {
|
||||
fmt.Println(req.Identifier)
|
||||
return validation.ValidateStruct(
|
||||
req.Identifier,
|
||||
validation.Field(&req.Identifier.AccountUuid, is.UUID),
|
||||
validation.Field(&req.Identifier.AccountUuid, accountUUIDRule...),
|
||||
validation.Field(&req.Identifier.Extension, validation.Match(regexForKeys)),
|
||||
validation.Field(&req.Identifier.Extension, validation.When(req.Identifier.BundleKey != "", validation.Required)),
|
||||
validation.Field(&req.Identifier.BundleKey, validation.Match(regexForKeys)),
|
||||
@@ -81,7 +75,7 @@ func validateValueIdentifier(identifier *proto.Identifier) error {
|
||||
identifier,
|
||||
validation.Field(&identifier.Extension, keyRule...),
|
||||
validation.Field(&identifier.BundleKey, keyRule...),
|
||||
validation.Field(&identifier.SettingKey, settingKeyRule...),
|
||||
validation.Field(&identifier.SettingKey, keyRule...),
|
||||
validation.Field(&identifier.AccountUuid, accountUUIDRule...),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user