Skip to content

Commit

Permalink
BED-4852 properly return 404 when deleting non-existent sso_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mvlipka committed Oct 15, 2024
1 parent bc3130d commit 00ab412
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/api/src/api/v2/auth/sso.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (s ManagementResource) DeleteSSOProvider(response http.ResponseWriter, requ
)

// Convert the incoming string url param to an int
if oidcProviderID, err := strconv.Atoi(rawSSOProviderID); err != nil {
if ssoProviderID, err := strconv.Atoi(rawSSOProviderID); err != nil {
api.WriteErrorResponse(request.Context(), api.BuildErrorResponse(http.StatusBadRequest, err.Error(), request), response)
} else if err = s.db.DeleteSSOProvider(request.Context(), oidcProviderID); errors.Is(err, database.ErrNotFound) {
} else if err = s.db.DeleteSSOProvider(request.Context(), ssoProviderID); errors.Is(err, database.ErrNotFound) {
// Handle error if requested record could not be found
api.WriteErrorResponse(request.Context(), api.BuildErrorResponse(http.StatusNotFound, err.Error(), request), response)
} else if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion cmd/api/src/database/sso_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ func (s *BloodhoundDB) DeleteSSOProvider(ctx context.Context, id int) error {
)

err := s.AuditableTransaction(ctx, auditEntry, func(tx *gorm.DB) error {
return CheckError(tx.Table(ssoProviderTableName).Where("id = ?", id).Delete(&model.SSOProvider{}))
result := tx.Table(ssoProviderTableName).Where("id = ?", id).Delete(&model.SSOProvider{})
if result.RowsAffected == 0 {
return ErrNotFound
}

return CheckError(result)
})

return err
Expand Down

0 comments on commit 00ab412

Please sign in to comment.