Skip to content

Commit

Permalink
Merge pull request #484 from traPtitech/issue/466
Browse files Browse the repository at this point in the history
fix #466
  • Loading branch information
wtks authored Mar 4, 2019
2 parents 2915f22 + c5c9df7 commit ce81640
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions router/pin_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -74,6 +98,7 @@ func TestHandlers_GetPin(t *testing.T) {
String().
Equal(pin.String())
})

}

func TestHandlers_DeletePin(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion utils/imagemagick/imagemagick.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ce81640

Please sign in to comment.