Skip to content

Commit

Permalink
Merge branch 'master' into dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
mantas-sidlauskas authored May 8, 2023
2 parents c87d629 + f86d183 commit a50cf5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
11 changes: 11 additions & 0 deletions common/domain/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package domain
import (
"context"
"fmt"
"regexp"
"time"

"github.com/pborman/uuid"
Expand All @@ -44,6 +45,7 @@ import (

var (
errDomainUpdateTooFrequent = &types.ServiceBusyError{Message: "Domain update too frequent."}
errInvalidDomainName = &types.BadRequestError{Message: "Domain name can only include alphanumeric and dash characters."}
)

type (
Expand Down Expand Up @@ -144,6 +146,15 @@ func (d *handlerImpl) RegisterDomain(
return err
}

// input validation on domain name
matchedRegex, err := regexp.MatchString("^[a-zA-Z0-9-]+$", registerRequest.GetName())
if err != nil {
return err
}
if !matchedRegex {
return errInvalidDomainName
}

activeClusterName := d.clusterMetadata.GetCurrentClusterName()
// input validation on cluster names
if registerRequest.ActiveClusterName != "" {
Expand Down
14 changes: 12 additions & 2 deletions common/domain/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (s *domainHandlerCommonSuite) TestListDomain() {

func (s *domainHandlerCommonSuite) TestRegisterDomain_InvalidRetentionPeriod() {
registerRequest := &types.RegisterDomainRequest{
Name: "random domain name",
Name: "random-domain-name",
Description: "random domain name",
WorkflowExecutionRetentionPeriodInDays: int32(0),
IsGlobalDomain: false,
Expand All @@ -403,8 +403,18 @@ func (s *domainHandlerCommonSuite) TestRegisterDomain_InvalidRetentionPeriod() {
s.Equal(errInvalidRetentionPeriod, err)
}

func (s *domainHandlerCommonSuite) TestRegisterDomain_InvalidDomainName() {
registerRequest := &types.RegisterDomainRequest{
Name: "random-domain name!^",
Description: "a domain with bad naming",
WorkflowExecutionRetentionPeriodInDays: int32(3),
}
err := s.handler.RegisterDomain(context.Background(), registerRequest)
s.Equal(errInvalidDomainName, err)
}

func (s *domainHandlerCommonSuite) TestUpdateDomain_InvalidRetentionPeriod() {
domain := "random domain name"
domain := "random-domain-name"
registerRequest := &types.RegisterDomainRequest{
Name: domain,
Description: domain,
Expand Down

0 comments on commit a50cf5c

Please sign in to comment.