Allow + . and @ in account ids

This commit is contained in:
Benedikt Kulmann
2020-08-12 15:26:12 +02:00
parent 0a16aaa73c
commit 17658df8b6
2 changed files with 57 additions and 4 deletions
+48
View File
@@ -1173,6 +1173,54 @@ func TestSaveGetListSettingsValues(t *testing.T) {
Status: "Internal Server Error",
},
},
{
testDataName: "../ in account uuid",
SettingsValue: proto.SettingsValue{
Identifier: &proto.Identifier{
Extension: "great-extension",
BundleKey: "bobs-bundle",
AccountUuid: "../123e4567-e89b-12d3-a456-426652340000",
SettingKey: "should-not-be-possible",
},
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
},
expectedError: CustomError{
ID: "go.micro.client",
Code: 500,
Detail: "account_uuid: must be in a valid format.",
Status: "Internal Server Error",
},
},
{
testDataName: "\\ in fields that are used to create folder and file names",
SettingsValue: proto.SettingsValue{
Identifier: &proto.Identifier{
Extension: "\\-extension",
BundleKey: "\\-bundle",
AccountUuid: "\\123e4567-e89b-12d3-a456-426652340000",
SettingKey: "should-not-be-possible",
},
Value: &proto.SettingsValue_BoolValue{BoolValue: false},
},
expectedError: CustomError{
ID: "go.micro.client",
Code: 500,
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)
+9 -4
View File
@@ -8,8 +8,13 @@ import (
)
var (
regexForKeys = regexp.MustCompile(`^[A-Za-z0-9\-_]*$`)
keyRule = []validation.Rule{
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),
}
@@ -48,7 +53,7 @@ func validateGetSettingsValue(req *proto.GetSettingsValueRequest) error {
func validateListSettingsValues(req *proto.ListSettingsValuesRequest) error {
return validation.ValidateStruct(
req.Identifier,
validation.Field(&req.Identifier.AccountUuid, keyRule...),
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)),
@@ -71,6 +76,6 @@ func validateValueIdentifier(identifier *proto.Identifier) error {
validation.Field(&identifier.Extension, keyRule...),
validation.Field(&identifier.BundleKey, keyRule...),
validation.Field(&identifier.SettingKey, keyRule...),
validation.Field(&identifier.AccountUuid, keyRule...),
validation.Field(&identifier.AccountUuid, accountUUIDRule...),
)
}