Skip to content

Commit

Permalink
convert pagerduty resources to use super-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-r-warren committed Jul 8, 2024
1 parent 803a827 commit fda04f7
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func (s *handlerSuite) TestPagerdutyIntegrationsV3Create_badBody() {
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("POST", "/api/pagerduty-integrations/v3", gin.H{
s.NewSuperAdminRequest("POST", "/api/pagerduty-integrations/v3", gin.H{
"pagerdutyID": 123,
}),
&got)
Expand All @@ -22,7 +22,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationsV3Create_badBody() {
func (s *handlerSuite) TestPagerdutyIntegrationsV3Create_sqlValidation() {
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("POST", "/api/pagerduty-integrations/v3", PagerdutyIntegrationV3Create{}),
s.NewSuperAdminRequest("POST", "/api/pagerduty-integrations/v3", PagerdutyIntegrationV3Create{}),
&got)
s.Equal(http.StatusBadRequest, code)
s.Equal(errors.BadRequest, got.Type)
Expand All @@ -47,7 +47,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationsV3Create_suitability() {
func (s *handlerSuite) TestPagerdutyIntegrationsV3Create() {
var got PagerdutyIntegrationV3
code := s.HandleRequest(
s.NewSuitableRequest("POST", "/api/pagerduty-integrations/v3", PagerdutyIntegrationV3Create{
s.NewSuperAdminRequest("POST", "/api/pagerduty-integrations/v3", PagerdutyIntegrationV3Create{
PagerdutyID: "pagerduty-id",
PagerdutyIntegrationV3Edit: PagerdutyIntegrationV3Edit{
Name: utils.PointerTo("pagerduty-integration-name"),
Expand All @@ -67,7 +67,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationsV3Create_duplicate() {
pdi := s.TestData.PagerdutyIntegration_ManuallyTriggeredTerraIncident()
var got PagerdutyIntegrationV3
code := s.HandleRequest(
s.NewSuitableRequest("POST", "/api/pagerduty-integrations/v3", PagerdutyIntegrationV3Create{
s.NewSuperAdminRequest("POST", "/api/pagerduty-integrations/v3", PagerdutyIntegrationV3Create{
PagerdutyID: pdi.PagerdutyID,
PagerdutyIntegrationV3Edit: PagerdutyIntegrationV3Edit{
Name: utils.PointerTo("pagerduty-integration-name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
func (s *handlerSuite) TestPagerdutyIntegrationV3Delete_badSelector() {
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("DELETE", "/api/pagerduty-integrations/v3/something/with/slashes", nil),
s.NewSuperAdminRequest("DELETE", "/api/pagerduty-integrations/v3/something/with/slashes", nil),
&got)
s.Equal(http.StatusBadRequest, code)
s.Equal(errors.BadRequest, got.Type)
Expand All @@ -18,7 +18,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationV3Delete_badSelector() {
func (s *handlerSuite) TestPagerdutyIntegrationV3Delete_notFound() {
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("DELETE", "/api/pagerduty-integrations/v3/pd-id/blahblahblah", nil),
s.NewSuperAdminRequest("DELETE", "/api/pagerduty-integrations/v3/pd-id/blahblahblah", nil),
&got)
s.Equal(http.StatusNotFound, code)
s.Equal(errors.NotFound, got.Type)
Expand All @@ -38,7 +38,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationV3Delete() {
pdi := s.TestData.PagerdutyIntegration_ManuallyTriggeredTerraIncident()
var got PagerdutyIntegrationV3
code := s.HandleRequest(
s.NewSuitableRequest("DELETE", fmt.Sprintf("/api/pagerduty-integrations/v3/%d", pdi.ID), nil),
s.NewSuperAdminRequest("DELETE", fmt.Sprintf("/api/pagerduty-integrations/v3/%d", pdi.ID), nil),
&got)
s.Equal(http.StatusOK, code)
s.Equal(pdi.ID, got.ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (s *handlerSuite) TestPagerdutyIntegrationV3Edit_badSelector() {
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("PATCH", "/api/pagerduty-integrations/v3/something/with/slashes", nil),
s.NewSuperAdminRequest("PATCH", "/api/pagerduty-integrations/v3/something/with/slashes", nil),
&got)
s.Equal(http.StatusBadRequest, code)
s.Equal(errors.BadRequest, got.Type)
Expand All @@ -20,7 +20,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationV3Edit_badSelector() {
func (s *handlerSuite) TestPagerdutyIntegrationV3Edit_badBody() {
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("PATCH", "/api/pagerduty-integrations/v3/123", gin.H{
s.NewSuperAdminRequest("PATCH", "/api/pagerduty-integrations/v3/123", gin.H{
"key": 123,
}),
&got)
Expand All @@ -31,7 +31,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationV3Edit_badBody() {
func (s *handlerSuite) TestPagerdutyIntegrationV3Edit_notFound() {
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("PATCH", "/api/pagerduty-integrations/v3/pd-id/blahblahblah", PagerdutyIntegrationV3Edit{
s.NewSuperAdminRequest("PATCH", "/api/pagerduty-integrations/v3/pd-id/blahblahblah", PagerdutyIntegrationV3Edit{
Key: utils.PointerTo("pagerduty-integration-key"),
}),
&got)
Expand All @@ -43,7 +43,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationV3Edit_sqlValidation() {
pdi := s.TestData.PagerdutyIntegration_ManuallyTriggeredTerraIncident()
var got errors.ErrorResponse
code := s.HandleRequest(
s.NewRequest("PATCH", fmt.Sprintf("/api/pagerduty-integrations/v3/%d", pdi.ID), PagerdutyIntegrationV3Edit{
s.NewSuperAdminRequest("PATCH", fmt.Sprintf("/api/pagerduty-integrations/v3/%d", pdi.ID), PagerdutyIntegrationV3Edit{
Key: utils.PointerTo(""),
}),
&got)
Expand All @@ -68,7 +68,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationV3Edit() {
pdi := s.TestData.PagerdutyIntegration_ManuallyTriggeredTerraIncident()
var got PagerdutyIntegrationV3
code := s.HandleRequest(
s.NewSuitableRequest("PATCH", fmt.Sprintf("/api/pagerduty-integrations/v3/%d", pdi.ID), PagerdutyIntegrationV3Edit{
s.NewSuperAdminRequest("PATCH", fmt.Sprintf("/api/pagerduty-integrations/v3/%d", pdi.ID), PagerdutyIntegrationV3Edit{
Key: utils.PointerTo("a key"),
Name: utils.PointerTo("a name"),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (s *handlerSuite) TestPagerdutyIntegrationsV3List_badOffset() {
}

func (s *handlerSuite) TestPagerdutyIntegrationsV3List() {
s.SetSuitableTestUserForDB()
s.SetSelfSuperAdminForDB()
pdi1 := models.PagerdutyIntegration{
PagerdutyID: "some-pd-id-1",
Name: utils.PointerTo("some-name-1"),
Expand Down
4 changes: 2 additions & 2 deletions sherlock/internal/models/pagerduty_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type PagerdutyIntegration struct {
func (p *PagerdutyIntegration) errorIfForbidden(tx *gorm.DB) error {
if user, err := GetCurrentUserForDB(tx); err != nil {
return err
} else if err = user.ErrIfNotSuitable(); err != nil {
return fmt.Errorf("(%s) suitability required: %w", errors.Forbidden, err)
} else if err = user.ErrIfNotSuperAdmin(); err != nil {
return fmt.Errorf("(%s) super-admin required: %w", errors.Forbidden, err)
} else {
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions sherlock/internal/models/pagerduty_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func (s *modelSuite) TestPagerdutyIntegrationPagerdutyIDValidationSql() {
s.SetSuitableTestUserForDB()
s.SetSelfSuperAdminForDB()
err := s.DB.Create(&PagerdutyIntegration{
Name: utils.PointerTo("some-name"),
Key: utils.PointerTo("some-key"),
Expand All @@ -16,7 +16,7 @@ func (s *modelSuite) TestPagerdutyIntegrationPagerdutyIDValidationSql() {
}

func (s *modelSuite) TestPagerdutyIntegrationNameValidationSql() {
s.SetSuitableTestUserForDB()
s.SetSelfSuperAdminForDB()
err := s.DB.Create(&PagerdutyIntegration{
PagerdutyID: "some-pagerduty-id",
Key: utils.PointerTo("some-key"),
Expand All @@ -26,7 +26,7 @@ func (s *modelSuite) TestPagerdutyIntegrationNameValidationSql() {
}

func (s *modelSuite) TestPagerdutyIntegrationKeyValidationSql() {
s.SetSuitableTestUserForDB()
s.SetSelfSuperAdminForDB()
err := s.DB.Create(&PagerdutyIntegration{
PagerdutyID: "some-pagerduty-id",
Name: utils.PointerTo("some-name"),
Expand All @@ -36,7 +36,7 @@ func (s *modelSuite) TestPagerdutyIntegrationKeyValidationSql() {
}

func (s *modelSuite) TestPagerdutyIntegrationTypeValidationSql() {
s.SetSuitableTestUserForDB()
s.SetSelfSuperAdminForDB()
err := s.DB.Create(&PagerdutyIntegration{
PagerdutyID: "some-pagerduty-id",
Name: utils.PointerTo("some-name"),
Expand Down Expand Up @@ -76,15 +76,15 @@ func (s *modelSuite) TestPagerdutyIntegrationDeleteForbidden() {
func (s *modelSuite) TestPagerdutyIntegrationDeleteWhileUsed() {
i := s.TestData.PagerdutyIntegration_ManuallyTriggeredTerraIncident()
s.TestData.Environment_Prod()
s.SetSuitableTestUserForDB()
s.SetSelfSuperAdminForDB()
s.ErrorContains(s.DB.
Delete(&i).
Error, errors.BadRequest)
}

func (s *modelSuite) TestPagerdutyIntegrationUniqueness() {
pdi := s.TestData.PagerdutyIntegration_ManuallyTriggeredTerraIncident()
s.SetSuitableTestUserForDB()
s.SetSelfSuperAdminForDB()
s.ErrorContains(s.DB.Create(&PagerdutyIntegration{
PagerdutyID: pdi.PagerdutyID,
Name: utils.PointerTo("some-name"),
Expand Down
2 changes: 1 addition & 1 deletion sherlock/internal/models/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func (td *testDataImpl) PagerdutyIntegration_ManuallyTriggeredTerraIncident() Pa
Key: utils.PointerTo("some secret key"),
Type: utils.PointerTo("service"),
}
td.h.SetSuitableTestUserForDB()
td.h.SetSelfSuperAdminForDB()
td.create(&td.pagerdutyIntegration_manuallyTriggeredTerraIncident)
}
return td.pagerdutyIntegration_manuallyTriggeredTerraIncident
Expand Down

0 comments on commit fda04f7

Please sign in to comment.