Skip to content

Commit

Permalink
Mention status report name allowed chars in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
godrei committed Nov 5, 2024
1 parent fc7bc31 commit f44b4c7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions models/models_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions models/models_methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -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")
}
}

Expand Down

0 comments on commit f44b4c7

Please sign in to comment.