From 4aa63d8e6bd719cc3ddffb65f09df6e6a4aec69c Mon Sep 17 00:00:00 2001 From: takashi <30363887+wtks@users.noreply.github.com> Date: Mon, 4 Mar 2019 12:12:59 +0900 Subject: [PATCH 1/3] fix #466 --- router/pin.go | 3 +++ router/pin_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/router/pin.go b/router/pin.go index d5e7aa143..2f60cc2d8 100644 --- a/router/pin.go +++ b/router/pin.go @@ -73,6 +73,9 @@ func (h *Handlers) PostPin(c echo.Context) error { // GetPin GET /pins/:pinID func (h *Handlers) GetPin(c echo.Context) error { pin := getPinFromContext(c) + if pin.Message.ID == uuid.Nil { + return c.NoContent(http.StatusNotFound) + } return c.JSON(http.StatusOK, h.formatPin(pin)) } diff --git a/router/pin_test.go b/router/pin_test.go index 342710621..115cb5f03 100644 --- a/router/pin_test.go +++ b/router/pin_test.go @@ -1,6 +1,7 @@ package router import ( + "github.com/satori/go.uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traPtitech/traQ/repository" @@ -61,6 +62,29 @@ func TestHandlers_GetPin(t *testing.T) { Status(http.StatusUnauthorized) }) + t.Run("Not found", func(t *testing.T) { + t.Parallel() + e := makeExp(t, server) + e.GET("/api/1.0/pins/{pinID}", uuid.NewV4()). + WithCookie(sessions.CookieName, session). + Expect(). + Status(http.StatusNotFound) + }) + + t.Run("Not found (deleted message)", func(t *testing.T) { + t.Parallel() + + message := mustMakeMessage(t, repo, testUser.ID, channel.ID) + pin := mustMakePin(t, repo, message.ID, testUser.ID) + require.NoError(t, repo.DeleteMessage(message.ID)) + + e := makeExp(t, server) + e.GET("/api/1.0/pins/{pinID}", pin). + WithCookie(sessions.CookieName, session). + Expect(). + Status(http.StatusNotFound) + }) + t.Run("Successful1", func(t *testing.T) { t.Parallel() e := makeExp(t, server) @@ -74,6 +98,7 @@ func TestHandlers_GetPin(t *testing.T) { String(). Equal(pin.String()) }) + } func TestHandlers_DeletePin(t *testing.T) { From 34c612ade91f446253f024469079a0ac010df004 Mon Sep 17 00:00:00 2001 From: takashi <30363887+wtks@users.noreply.github.com> Date: Mon, 4 Mar 2019 13:18:50 +0900 Subject: [PATCH 2/3] fix #485 --- utils/imagemagick/imagemagick.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/imagemagick/imagemagick.go b/utils/imagemagick/imagemagick.go index bb4f89ed1..4ffad4649 100644 --- a/utils/imagemagick/imagemagick.go +++ b/utils/imagemagick/imagemagick.go @@ -58,7 +58,7 @@ func ResizeAnimationGIF(ctx context.Context, execPath string, src io.Reader, max if !expand { sizer += ">" } - cmd := exec.CommandContext(ctx, execPath, "-coalesce", "-resize", sizer, "-deconstruct", "-", "gif:-") + cmd := exec.CommandContext(ctx, execPath, "-", "-coalesce", "-repage", "0x0", "-resize", sizer, "-layers", "Optimize", "gif:-") b, err := cmdPipe(cmd, src) if err != nil { From c5c9df7b9d8a9dcb4fe3e9da9ecee7a1ceff6985 Mon Sep 17 00:00:00 2001 From: takashi <30363887+wtks@users.noreply.github.com> Date: Mon, 4 Mar 2019 13:22:49 +0900 Subject: [PATCH 3/3] fix --- router/middleware.go | 4 ++++ router/pin.go | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/router/middleware.go b/router/middleware.go index f9a141663..5b202e262 100644 --- a/router/middleware.go +++ b/router/middleware.go @@ -264,6 +264,10 @@ func (h *Handlers) ValidatePinID() echo.MiddlewareFunc { } } + if pin.Message.ID == uuid.Nil { + return c.NoContent(http.StatusNotFound) + } + if ok, err := h.Repo.IsChannelAccessibleToUser(userID, pin.Message.ChannelID); err != nil { c.Logger().Error(err) return c.NoContent(http.StatusInternalServerError) diff --git a/router/pin.go b/router/pin.go index 2f60cc2d8..d5e7aa143 100644 --- a/router/pin.go +++ b/router/pin.go @@ -73,9 +73,6 @@ func (h *Handlers) PostPin(c echo.Context) error { // GetPin GET /pins/:pinID func (h *Handlers) GetPin(c echo.Context) error { pin := getPinFromContext(c) - if pin.Message.ID == uuid.Nil { - return c.NoContent(http.StatusNotFound) - } return c.JSON(http.StatusOK, h.formatPin(pin)) }