mirror of
https://github.com/elyby/chrly.git
synced 2024-11-23 05:33:18 +05:30
Add rough sentry reporting to catch panic in the mojang textures decoder
This commit is contained in:
parent
33b286cba0
commit
8001eab9db
6
Gopkg.lock
generated
6
Gopkg.lock
generated
@ -265,7 +265,7 @@
|
|||||||
version = "v0.1.1"
|
version = "v0.1.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
digest = "1:381bcbeb112a51493d9d998bbba207a529c73dbb49b3fd789e48c63fac1f192c"
|
digest = "1:cc4eb6813da8d08694e557fcafae8fcc24f47f61a0717f952da130ca9a486dfc"
|
||||||
name = "github.com/stretchr/testify"
|
name = "github.com/stretchr/testify"
|
||||||
packages = [
|
packages = [
|
||||||
"assert",
|
"assert",
|
||||||
@ -274,8 +274,8 @@
|
|||||||
"suite",
|
"suite",
|
||||||
]
|
]
|
||||||
pruneopts = ""
|
pruneopts = ""
|
||||||
revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053"
|
revision = "3ebf1ddaeb260c4b1ae502a01c7844fa8c1fa0e9"
|
||||||
version = "v1.3.0"
|
version = "v1.5.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
@ -3,6 +3,7 @@ package mojang
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -24,7 +25,7 @@ type SignedTexturesResponse struct {
|
|||||||
decodedTextures *TexturesProp
|
decodedTextures *TexturesProp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *SignedTexturesResponse) DecodeTextures() *TexturesProp {
|
func (t *SignedTexturesResponse) DecodeTextures() (*TexturesProp, error) {
|
||||||
if t.decodedTextures == nil {
|
if t.decodedTextures == nil {
|
||||||
var texturesProp string
|
var texturesProp string
|
||||||
for _, prop := range t.Props {
|
for _, prop := range t.Props {
|
||||||
@ -35,14 +36,18 @@ func (t *SignedTexturesResponse) DecodeTextures() *TexturesProp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if texturesProp == "" {
|
if texturesProp == "" {
|
||||||
return nil
|
return nil, errors.New("unable to find the textures property")
|
||||||
|
}
|
||||||
|
|
||||||
|
decodedTextures, err := DecodeTextures(texturesProp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
decodedTextures, _ := DecodeTextures(texturesProp)
|
|
||||||
t.decodedTextures = decodedTextures
|
t.decodedTextures = decodedTextures
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.decodedTextures
|
return t.decodedTextures, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Property struct {
|
type Property struct {
|
||||||
|
@ -20,7 +20,8 @@ func TestSignedTexturesResponse(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
textures := obj.DecodeTextures()
|
textures, err := obj.DecodeTextures()
|
||||||
|
testify.Nil(t, err)
|
||||||
testify.Equal(t, "3e3ee6c35afa48abb61e8cd8c42fc0d9", textures.ProfileID)
|
testify.Equal(t, "3e3ee6c35afa48abb61e8cd8c42fc0d9", textures.ProfileID)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -30,7 +31,8 @@ func TestSignedTexturesResponse(t *testing.T) {
|
|||||||
Name: "mock",
|
Name: "mock",
|
||||||
Props: []*Property{},
|
Props: []*Property{},
|
||||||
}
|
}
|
||||||
textures := obj.DecodeTextures()
|
textures, err := obj.DecodeTextures()
|
||||||
|
testify.Errorf(t, err, "unable to find the textures property")
|
||||||
testify.Nil(t, textures)
|
testify.Nil(t, textures)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func (ctx *Skinsystem) skinHandler(response http.ResponseWriter, request *http.R
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
texturesProp := mojangTextures.DecodeTextures()
|
texturesProp, _ := mojangTextures.DecodeTextures()
|
||||||
skin := texturesProp.Textures.Skin
|
skin := texturesProp.Textures.Skin
|
||||||
if skin == nil {
|
if skin == nil {
|
||||||
response.WriteHeader(http.StatusNotFound)
|
response.WriteHeader(http.StatusNotFound)
|
||||||
@ -104,7 +104,7 @@ func (ctx *Skinsystem) capeHandler(response http.ResponseWriter, request *http.R
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
texturesProp := mojangTextures.DecodeTextures()
|
texturesProp, _ := mojangTextures.DecodeTextures()
|
||||||
cape := texturesProp.Textures.Cape
|
cape := texturesProp.Textures.Cape
|
||||||
if cape == nil {
|
if cape == nil {
|
||||||
response.WriteHeader(http.StatusNotFound)
|
response.WriteHeader(http.StatusNotFound)
|
||||||
@ -162,7 +162,7 @@ func (ctx *Skinsystem) texturesHandler(response http.ResponseWriter, request *ht
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
texturesProp := mojangTextures.DecodeTextures()
|
texturesProp, _ := mojangTextures.DecodeTextures()
|
||||||
if texturesProp == nil {
|
if texturesProp == nil {
|
||||||
ctx.Emit("skinsystem:error", errors.New("unable to find textures property"))
|
ctx.Emit("skinsystem:error", errors.New("unable to find textures property"))
|
||||||
apiServerError(response)
|
apiServerError(response)
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package mojangtextures
|
package mojangtextures
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/getsentry/raven-go"
|
||||||
|
|
||||||
"github.com/elyby/chrly/api/mojang"
|
"github.com/elyby/chrly/api/mojang"
|
||||||
|
|
||||||
"github.com/tevino/abool"
|
"github.com/tevino/abool"
|
||||||
@ -75,9 +78,22 @@ func (s *InMemoryTexturesStorage) GetTextures(uuid string) (*mojang.SignedTextur
|
|||||||
func (s *InMemoryTexturesStorage) StoreTextures(uuid string, textures *mojang.SignedTexturesResponse) {
|
func (s *InMemoryTexturesStorage) StoreTextures(uuid string, textures *mojang.SignedTexturesResponse) {
|
||||||
var timestamp int64
|
var timestamp int64
|
||||||
if textures != nil {
|
if textures != nil {
|
||||||
decoded := textures.DecodeTextures()
|
decoded, err := textures.DecodeTextures()
|
||||||
if decoded == nil {
|
if err != nil {
|
||||||
panic("unable to decode textures")
|
tags := map[string]string{
|
||||||
|
"textures.id": textures.Id,
|
||||||
|
"textures.name": textures.Name,
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, prop := range textures.Props {
|
||||||
|
tags[fmt.Sprintf("textures.props[%d].name", i)] = prop.Name
|
||||||
|
tags[fmt.Sprintf("textures.props[%d].value", i)] = prop.Value
|
||||||
|
tags[fmt.Sprintf("textures.props[%d].signature", i)] = prop.Signature
|
||||||
|
}
|
||||||
|
|
||||||
|
raven.CaptureErrorAndWait(err, tags)
|
||||||
|
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
timestamp = decoded.Timestamp
|
timestamp = decoded.Timestamp
|
||||||
|
@ -116,7 +116,7 @@ func TestInMemoryTexturesStorage_StoreTextures(t *testing.T) {
|
|||||||
Props: []*mojang.Property{},
|
Props: []*mojang.Property{},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.PanicsWithValue(t, "unable to decode textures", func() {
|
assert.PanicsWithError(t, "unable to find the textures property", func() {
|
||||||
storage := NewInMemoryTexturesStorage()
|
storage := NewInMemoryTexturesStorage()
|
||||||
storage.StoreTextures("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", toStore)
|
storage.StoreTextures("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", toStore)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user