From f44b4c7987a28f5dd312b06740bd01da96971284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krisztia=CC=81n=20Go=CC=88drei?= Date: Tue, 5 Nov 2024 15:13:18 +0100 Subject: [PATCH] Mention status report name allowed chars in error messages --- models/models_methods.go | 7 ++++--- models/models_methods_test.go | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/models/models_methods.go b/models/models_methods.go index 253046f1..8a1b4370 100644 --- a/models/models_methods.go +++ b/models/models_methods.go @@ -378,15 +378,16 @@ func (workflow *WorkflowModel) Validate() error { return validateStatusReportName(workflow.StatusReportName) } +const statusReportNameRegex = `^[a-zA-Z0-9,./():\-_ <>[\]|]*$` + func validateStatusReportName(statusReportName string) error { if len(statusReportName) > 100 { return fmt.Errorf("status_report_name (%s) is too long, max length is 100 characters", statusReportName) } - pattern := `^[a-zA-Z0-9,./():\-_ <>[\]|]*$` - re := regexp.MustCompile(pattern) + re := regexp.MustCompile(statusReportNameRegex) if !re.MatchString(statusReportName) { - return fmt.Errorf("status_report_name (%s) contains invalid characters", statusReportName) + return fmt.Errorf("status_report_name (%s) contains invalid characters, should match the '%s' regex", statusReportName, statusReportNameRegex) } return nil } diff --git a/models/models_methods_test.go b/models/models_methods_test.go index ed9e753b..8db0799e 100644 --- a/models/models_methods_test.go +++ b/models/models_methods_test.go @@ -332,7 +332,7 @@ func TestValidateConfig(t *testing.T) { bitriseData.App.StatusReportName += "*" _, err = bitriseData.Validate() - require.EqualError(t, err, "status_report_name ("+bitriseData.App.StatusReportName+") contains invalid characters") + require.EqualError(t, err, "status_report_name ("+bitriseData.App.StatusReportName+") contains invalid characters, should match the '"+statusReportNameRegex+"' regex") } t.Log("Invalid bitriseData - pipeline ID empty") @@ -634,7 +634,7 @@ func TestValidateConfig(t *testing.T) { pipeline.StatusReportName += "*" bitriseData.Pipelines["pipeline1"] = pipeline _, err = bitriseData.Validate() - require.EqualError(t, err, "status_report_name ("+pipeline.StatusReportName+") contains invalid characters") + require.EqualError(t, err, "status_report_name ("+pipeline.StatusReportName+") contains invalid characters, should match the '"+statusReportNameRegex+"' regex") } } @@ -1006,7 +1006,7 @@ workflows: require.NoError(t, workflow.Validate()) workflow.StatusReportName += "*" - require.EqualError(t, workflow.Validate(), "status_report_name ("+workflow.StatusReportName+") contains invalid characters") + require.EqualError(t, workflow.Validate(), "status_report_name ("+workflow.StatusReportName+") contains invalid characters, should match the '"+statusReportNameRegex+"' regex") } }