Skip to content

Commit

Permalink
HMS-1832 fix: prevent changing domain name
Browse files Browse the repository at this point in the history
Detect if client is attempting to change the domain name.  Return an
error if so.

Also remove processing related to Title, Description and
AutoEnrollmentEnabled fields.  These fields do not appear in the
UpdateDomainAgentRequest payload type.
  • Loading branch information
frasertweedale authored and cryptomilk committed Nov 8, 2023
1 parent bc2f218 commit 19447cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
9 changes: 9 additions & 0 deletions internal/handler/impl/domain_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ func (a *application) UpdateDomainAgent(ctx echo.Context, domain_id uuid.UUID, p
return err
}

if data.DomainName != nil &&
currentData.DomainName != nil &&
*data.DomainName != *currentData.DomainName {
return internal_errors.NewHTTPErrorF(
http.StatusBadRequest,
"'domain_name' may not be changed",
)
}

if err = a.fillDomain(currentData, data); err != nil {
return err
}
Expand Down
25 changes: 0 additions & 25 deletions internal/usecase/repository/domain_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/openlyinc/pointy"
"github.com/podengo-project/idmsvc-backend/internal/api/public"
"github.com/podengo-project/idmsvc-backend/internal/domain/model"
internal_errors "github.com/podengo-project/idmsvc-backend/internal/errors"
Expand Down Expand Up @@ -144,30 +143,6 @@ func (r *domainRepository) UpdateAgent(
return err
}

if data.DomainName != nil {
currentDomain.DomainName = data.DomainName
} else {
currentDomain.DomainName = pointy.String("")
}

if data.Title != nil {
currentDomain.Title = data.Title
} else {
currentDomain.Title = pointy.String("")
}

if data.Description != nil {
currentDomain.Description = data.Description
} else {
currentDomain.Description = pointy.String("")
}

if data.AutoEnrollmentEnabled != nil {
currentDomain.AutoEnrollmentEnabled = data.AutoEnrollmentEnabled
} else {
currentDomain.AutoEnrollmentEnabled = pointy.Bool(false)
}

if err = db.Omit(clause.Associations).
Where("org_id = ? AND domain_uuid = ?", orgID, currentDomain.DomainUuid).
Updates(data).
Expand Down

0 comments on commit 19447cd

Please sign in to comment.