Skip to content

Commit

Permalink
[DDO-3911] improve chart name validation (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-r-warren authored Nov 1, 2024
1 parent 8174036 commit 3c033c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sherlock/db/migrations/000101_chart_name_validation.down.sql
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions sherlock/db/migrations/000101_chart_name_validation.up.sql
Original file line number Diff line number Diff line change
@@ -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;
5 changes: 5 additions & 0 deletions sherlock/internal/models/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 3c033c9

Please sign in to comment.