mirror of
https://github.com/drakkan/sftpgo.git
synced 2026-03-14 14:25:52 +01:00
Enforce missing naming rule for actions and rules
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
1ad5456d91
commit
fd0444c8ff
8 changed files with 30 additions and 18 deletions
|
|
@ -5775,7 +5775,7 @@ func TestBackupAsAttachment(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
a1 := dataprovider.BaseEventAction{
|
||||
Name: "a1",
|
||||
Name: "a1 with space",
|
||||
Type: dataprovider.ActionTypeBackup,
|
||||
}
|
||||
a2 := dataprovider.BaseEventAction{
|
||||
|
|
|
|||
|
|
@ -1256,6 +1256,12 @@ func (a *BaseEventAction) validate() error {
|
|||
if !util.IsNameValid(a.Name) {
|
||||
return util.NewI18nError(errInvalidInput, util.I18nErrorInvalidInput)
|
||||
}
|
||||
if config.NamingRules&1 == 0 && !usernameRegex.MatchString(a.Name) {
|
||||
return util.NewI18nError(
|
||||
util.NewValidationError(fmt.Sprintf("name %q is not valid, the following characters are allowed: a-zA-Z0-9-_.~", a.Name)),
|
||||
util.I18nErrorInvalidUser,
|
||||
)
|
||||
}
|
||||
if !isActionTypeValid(a.Type) {
|
||||
return util.NewValidationError(fmt.Sprintf("invalid action type: %d", a.Type))
|
||||
}
|
||||
|
|
@ -1682,6 +1688,12 @@ func (r *EventRule) validate() error { //nolint:gocyclo
|
|||
if !util.IsNameValid(r.Name) {
|
||||
return util.NewI18nError(errInvalidInput, util.I18nErrorInvalidInput)
|
||||
}
|
||||
if config.NamingRules&1 == 0 && !usernameRegex.MatchString(r.Name) {
|
||||
return util.NewI18nError(
|
||||
util.NewValidationError(fmt.Sprintf("name %q is not valid, the following characters are allowed: a-zA-Z0-9-_.~", r.Name)),
|
||||
util.I18nErrorInvalidUser,
|
||||
)
|
||||
}
|
||||
if !r.isStatusValid() {
|
||||
return util.NewValidationError(fmt.Sprintf("invalid event rule status: %d", r.Status))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2146,7 +2146,7 @@ func TestIPListEntriesValidation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBasicActionRulesHandling(t *testing.T) {
|
||||
actionName := "test action"
|
||||
actionName := "test_action"
|
||||
a := dataprovider.BaseEventAction{
|
||||
Name: actionName,
|
||||
Description: "test description",
|
||||
|
|
@ -2286,7 +2286,7 @@ func TestBasicActionRulesHandling(t *testing.T) {
|
|||
assert.Equal(t, defaultPassword, dbAction.Options.HTTPConfig.Password.GetPayload())
|
||||
|
||||
r := dataprovider.EventRule{
|
||||
Name: "test rule name",
|
||||
Name: "test_rule_name",
|
||||
Status: 1,
|
||||
Description: "",
|
||||
Trigger: dataprovider.EventTriggerFsEvent,
|
||||
|
|
@ -2548,7 +2548,7 @@ func TestActionRuleRelations(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOnDemandEventRules(t *testing.T) {
|
||||
ruleName := "test on demand rule"
|
||||
ruleName := "test_on_demand_rule"
|
||||
a := dataprovider.BaseEventAction{
|
||||
Name: "a",
|
||||
Type: dataprovider.ActionTypeBackup,
|
||||
|
|
@ -2589,7 +2589,7 @@ func TestOnDemandEventRules(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIDPLoginEventRule(t *testing.T) {
|
||||
ruleName := "test IDP login rule"
|
||||
ruleName := "test_IDP_login_rule"
|
||||
a := dataprovider.BaseEventAction{
|
||||
Name: "a",
|
||||
Type: dataprovider.ActionTypeIDPAccountCheck,
|
||||
|
|
@ -7929,7 +7929,7 @@ func TestProviderErrors(t *testing.T) {
|
|||
backupData = dataprovider.BackupData{
|
||||
EventActions: []dataprovider.BaseEventAction{
|
||||
{
|
||||
Name: "quota reset",
|
||||
Name: "quota_reset",
|
||||
Type: dataprovider.ActionTypeFolderQuotaReset,
|
||||
},
|
||||
},
|
||||
|
|
@ -7944,7 +7944,7 @@ func TestProviderErrors(t *testing.T) {
|
|||
backupData = dataprovider.BackupData{
|
||||
EventRules: []dataprovider.EventRule{
|
||||
{
|
||||
Name: "quota reset",
|
||||
Name: "quota_reset",
|
||||
Trigger: dataprovider.EventTriggerSchedule,
|
||||
Conditions: dataprovider.EventConditions{
|
||||
Schedules: []dataprovider.Schedule{
|
||||
|
|
@ -8738,7 +8738,7 @@ func TestLoaddata(t *testing.T) {
|
|||
}
|
||||
action := dataprovider.BaseEventAction{
|
||||
ID: 81,
|
||||
Name: "test restore action",
|
||||
Name: "test_restore_action",
|
||||
Type: dataprovider.ActionTypeHTTP,
|
||||
Options: dataprovider.BaseEventActionOptions{
|
||||
HTTPConfig: dataprovider.EventActionHTTPConfig{
|
||||
|
|
@ -8754,7 +8754,7 @@ func TestLoaddata(t *testing.T) {
|
|||
}
|
||||
rule := dataprovider.EventRule{
|
||||
ID: 100,
|
||||
Name: "test rule restore",
|
||||
Name: "test_rule_restore",
|
||||
Description: "",
|
||||
Trigger: dataprovider.EventTriggerFsEvent,
|
||||
Conditions: dataprovider.EventConditions{
|
||||
|
|
@ -9119,7 +9119,7 @@ func TestLoaddataMode(t *testing.T) {
|
|||
}
|
||||
action := dataprovider.BaseEventAction{
|
||||
ID: 81,
|
||||
Name: "test restore action data mode",
|
||||
Name: "test_restore_action_data_mode",
|
||||
Description: "action desc",
|
||||
Type: dataprovider.ActionTypeHTTP,
|
||||
Options: dataprovider.BaseEventActionOptions{
|
||||
|
|
@ -9136,7 +9136,7 @@ func TestLoaddataMode(t *testing.T) {
|
|||
}
|
||||
rule := dataprovider.EventRule{
|
||||
ID: 100,
|
||||
Name: "test rule restore data mode",
|
||||
Name: "test_rule_restore_data_mode",
|
||||
Description: "rule desc",
|
||||
Trigger: dataprovider.EventTriggerFsEvent,
|
||||
Conditions: dataprovider.EventConditions{
|
||||
|
|
@ -9643,7 +9643,7 @@ func TestEventRuleErrorsMock(t *testing.T) {
|
|||
checkResponseCode(t, http.StatusBadRequest, rr)
|
||||
|
||||
a := dataprovider.BaseEventAction{
|
||||
Name: "action name",
|
||||
Name: "action_name",
|
||||
Description: "test description",
|
||||
Type: dataprovider.ActionTypeBackup,
|
||||
Options: dataprovider.BaseEventActionOptions{},
|
||||
|
|
@ -9658,7 +9658,7 @@ func TestEventRuleErrorsMock(t *testing.T) {
|
|||
checkResponseCode(t, http.StatusBadRequest, rr)
|
||||
|
||||
r := dataprovider.EventRule{
|
||||
Name: "test event rule",
|
||||
Name: "test_event_rule",
|
||||
Trigger: dataprovider.EventTriggerSchedule,
|
||||
Conditions: dataprovider.EventConditions{
|
||||
Schedules: []dataprovider.Schedule{
|
||||
|
|
|
|||
|
|
@ -1414,7 +1414,7 @@ func TestCreateShareCookieError(t *testing.T) {
|
|||
err := dataprovider.AddUser(user, "", "", "")
|
||||
assert.NoError(t, err)
|
||||
share := &dataprovider.Share{
|
||||
Name: "test share cookie error",
|
||||
Name: "test_share_cookie_error",
|
||||
ShareID: util.GenerateUniqueID(),
|
||||
Scope: dataprovider.ShareScopeRead,
|
||||
Password: pwd,
|
||||
|
|
|
|||
|
|
@ -500,7 +500,7 @@
|
|||
"user": {
|
||||
"view_manage": "Benutzer anzeigen und verwalten",
|
||||
"username_reserved": "Der angegebene Benutzername ist reserviert",
|
||||
"username_invalid": "Der angegebene Benutzername ist ungültig, die folgenden Zeichen sind erlaubt: a-zA-Z0-9-_.~",
|
||||
"username_invalid": "Der angegebene Name ist ungültig. Die folgenden Zeichen sind zulässig: a-z A-Z 0-9 - _ . ~",
|
||||
"home_required": "Das Home-Verzeichnis ist obligatorisch",
|
||||
"home_invalid": "Das Home-Verzeichnis muss ein absoluter Pfad sein",
|
||||
"pub_key_invalid": "Ungültiger öffentlicher Schlüssel",
|
||||
|
|
|
|||
|
|
@ -500,7 +500,7 @@
|
|||
"user": {
|
||||
"view_manage": "View and manage users",
|
||||
"username_reserved": "The specified username is reserved",
|
||||
"username_invalid": "The specified username is not valid, the following characters are allowed: a-zA-Z0-9-_.~",
|
||||
"username_invalid": "The specified name is not valid, the following characters are allowed: a-z A-Z 0-9 - _ . ~",
|
||||
"home_required": "The home directory is mandatory",
|
||||
"home_invalid": "The home directory must be an absolute path",
|
||||
"pub_key_invalid": "Invalid public key",
|
||||
|
|
|
|||
|
|
@ -500,7 +500,7 @@
|
|||
"user": {
|
||||
"view_manage": "Voir et gérer les utilisateurs",
|
||||
"username_reserved": "Le nom d'utilisateur spécifié est réservé",
|
||||
"username_invalid": "Le nom d'utilisateur spécifié n'est pas valide, les caractères suivants sont autorisés : a-zA-Z0-9-_.~",
|
||||
"username_invalid": "Le nom indiqué n’est pas valide. Les caractères suivants sont autorisés : a-z A-Z 0-9 - _ . ~",
|
||||
"home_required": "Le répertoire de base est obligatoire",
|
||||
"home_invalid": "Le répertoire de base doit être un chemin absolu",
|
||||
"pub_key_invalid": "Clé publique invalide",
|
||||
|
|
|
|||
|
|
@ -500,7 +500,7 @@
|
|||
"user": {
|
||||
"view_manage": "Visualizza e gestisci utenti",
|
||||
"username_reserved": "Il nome utente specificato è riservato",
|
||||
"username_invalid": "Il nome utente specificato non è valido, sono consentiti i seguenti caratteri: a-zA-Z0-9-_.~",
|
||||
"username_invalid": "Il nome specificato non è valido. Sono consentiti i seguenti caratteri: a-z A-Z 0-9 - _ . ~",
|
||||
"home_required": "La directory principale è obbligatoria",
|
||||
"home_invalid": "La directory principale deve essere un path assoluto",
|
||||
"pub_key_invalid": "Chiave pubblica non valida",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue