diff --git a/sherlock/db/migrations/000101_chart_name_validation.down.sql b/sherlock/db/migrations/000101_chart_name_validation.down.sql new file mode 100644 index 00000000..813bd648 --- /dev/null +++ b/sherlock/db/migrations/000101_chart_name_validation.down.sql @@ -0,0 +1,6 @@ +alter table charts + add constraint name_present + check (name is not null and name != ''); + +alter table environments + drop constraint if exists name_valid; diff --git a/sherlock/db/migrations/000101_chart_name_validation.up.sql b/sherlock/db/migrations/000101_chart_name_validation.up.sql new file mode 100644 index 00000000..ccd87b01 --- /dev/null +++ b/sherlock/db/migrations/000101_chart_name_validation.up.sql @@ -0,0 +1,6 @@ +alter table charts + add constraint name_valid + check (name is not null and name != '' and name similar to '[a-z0-9]([-a-z0-9]*[a-z0-9])?'); + +alter table environments + drop constraint if exists name_present; diff --git a/sherlock/internal/models/chart_test.go b/sherlock/internal/models/chart_test.go index dc78219a..a9124d1f 100644 --- a/sherlock/internal/models/chart_test.go +++ b/sherlock/internal/models/chart_test.go @@ -14,6 +14,11 @@ func (s *modelSuite) TestChartNameValidationSqlEmpty() { s.ErrorContains(err, "name") } +func (s *modelSuite) TestChartNameValidationSqlBadCharacters() { + err := s.DB.Create(&Chart{ChartRepo: utils.PointerTo("repo"), Name: "special characters!!!"}).Error + s.ErrorContains(err, "name") +} + func (s *modelSuite) TestChartRepoValidationSqlMissing() { err := s.DB.Create(&Chart{Name: "name"}).Error s.ErrorContains(err, "chart_repo")