From 35da1c7e678f2cd72c6e8746a1314f9a00c6b6e8 Mon Sep 17 00:00:00 2001 From: in-void Date: Tue, 7 Feb 2023 11:38:28 +0100 Subject: [PATCH] fix validation icons requests image dimension --- internal/api/icons/app/command/icons.go | 2 +- tests/icons/icons_requests_test.go | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/internal/api/icons/app/command/icons.go b/internal/api/icons/app/command/icons.go index dfee8ed..2293417 100644 --- a/internal/api/icons/app/command/icons.go +++ b/internal/api/icons/app/command/icons.go @@ -50,7 +50,7 @@ func processB64PngImage(b64Img string) (image.Image, io.Reader, error) { func validateImage(img image.Image) error { imageWidth := img.Bounds().Dx() - imageHeight := img.Bounds().Dx() + imageHeight := img.Bounds().Dy() validDimensions := []*image.Point{ {X: 120, Y: 120}, diff --git a/tests/icons/icons_requests_test.go b/tests/icons/icons_requests_test.go index 3ec4945..38a9621 100644 --- a/tests/icons/icons_requests_test.go +++ b/tests/icons/icons_requests_test.go @@ -33,6 +33,34 @@ func (s *IconsRequestsTestSuite) TestCreateIconRequest() { assert.Equal(s.T(), "desc", iconRequest.Description) } +func (s *IconsRequestsTestSuite) TestCreateIconRequestWithNotAllowedIconDimensions() { + img := faker.New().Image().Image(120, 60) + + pngImg, err := ioutil.ReadFile(img.Name()) + + if err != nil { + s.T().Error(err) + } + + iconBase64Encoded := base64.StdEncoding.EncodeToString(pngImg) + + payload := []byte(` + { + "caller_id":"some-caller-uniq-name", + "service_name":"some-service", + "issuers": ["fb"], + "description":"desc", + "light_icon":"` + iconBase64Encoded + `" + } + `) + + var iconRequest *queries.IconRequestPresenter + + response := tests.DoPost("mobile/icons/requests", payload, &iconRequest) + + assert.Equal(s.T(), 400, response.StatusCode) +} + func (s *IconsRequestsTestSuite) TestDeleteIconRequest() { iconRequest := createIconRequest(s.T(), "service")