diff --git a/db/redis/redis.go b/db/redis/redis.go index 154b791..6336551 100644 --- a/db/redis/redis.go +++ b/db/redis/redis.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/getsentry/raven-go" "github.com/mediocregopher/radix.v2/pool" "github.com/mediocregopher/radix.v2/redis" "github.com/mediocregopher/radix.v2/util" @@ -204,6 +205,19 @@ func findMojangUuidByUsername(username string, conn util.Cmder) (string, bool, e data, _ := response.Str() parts := strings.Split(data, ":") + // Temporary debug statement to investigate https://github.com/elyby/chrly/issues/28 + if len(parts) < 2 { + raven.Capture(raven.NewPacketWithExtra( + "mojangUsernameToUuid hash contains corrupted data", + raven.Extra{ + "rawValue": "hello world", + "username": "this is username", + }, + ), map[string]string{}) + + return "", false, nil + } + timestamp, _ := strconv.ParseInt(parts[1], 10, 64) storedAt := time.Unix(timestamp, 0) if storedAt.Add(time.Hour * 24 * 30).Before(now()) { diff --git a/db/redis/redis_integration_test.go b/db/redis/redis_integration_test.go index 0e8dd0e..3073c84 100644 --- a/db/redis/redis_integration_test.go +++ b/db/redis/redis_integration_test.go @@ -360,17 +360,33 @@ func (suite *redisTestSuite) TestGetUuid() { } func (suite *redisTestSuite) TestStoreUuid() { - now = func() time.Time { - return time.Date(2020, 04, 21, 02, 10, 16, 0, time.UTC) - } + suite.RunSubTest("store uuid", func() { + now = func() time.Time { + return time.Date(2020, 04, 21, 02, 10, 16, 0, time.UTC) + } - err := suite.Redis.StoreUuid("Mock", "d3ca513eb3e14946b58047f2bd3530fd") - suite.Require().Nil(err) + err := suite.Redis.StoreUuid("Mock", "d3ca513eb3e14946b58047f2bd3530fd") + suite.Require().Nil(err) - resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock") - suite.Require().False(resp.IsType(redis.Nil)) - str, _ := resp.Str() - suite.Require().Equal(str, "d3ca513eb3e14946b58047f2bd3530fd:1587435016") + resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock") + suite.Require().False(resp.IsType(redis.Nil)) + str, _ := resp.Str() + suite.Require().Equal(str, "d3ca513eb3e14946b58047f2bd3530fd:1587435016") + }) + + suite.RunSubTest("store empty uuid", func() { + now = func() time.Time { + return time.Date(2020, 04, 21, 02, 10, 16, 0, time.UTC) + } + + err := suite.Redis.StoreUuid("Mock", "") + suite.Require().Nil(err) + + resp := suite.cmd("HGET", "hash:mojang-username-to-uuid", "mock") + suite.Require().False(resp.IsType(redis.Nil)) + str, _ := resp.Str() + suite.Require().Equal(str, ":1587435016") + }) } func (suite *redisTestSuite) TestPing() {