From 5a4e23a0eaeeb7396ea7362143eded2bc6ae7a13 Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Mon, 26 Oct 2020 13:01:46 +0000 Subject: [PATCH] Fix protobuf ImageType change --- protocol/common/message_test.go | 14 +++++++------- protocol/images/type.go | 12 ++++++------ protocol/message_validator.go | 2 +- protocol/message_validator_test.go | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/protocol/common/message_test.go b/protocol/common/message_test.go index 9ad7ebad2..eee5f461d 100644 --- a/protocol/common/message_test.go +++ b/protocol/common/message_test.go @@ -27,7 +27,7 @@ func TestPrepareContentImage(t *testing.T) { message.ContentType = protobuf.ChatMessage_IMAGE image := protobuf.ImageMessage{ Payload: payload, - Type: protobuf.ImageMessage_JPEG, + Type: protobuf.ImageType_JPEG, } message.Payload = &protobuf.ChatMessage_Image{Image: &image} @@ -36,27 +36,27 @@ func TestPrepareContentImage(t *testing.T) { } func TestGetImageMessageMIME(t *testing.T) { - jpeg := &protobuf.ImageMessage{Type: protobuf.ImageMessage_JPEG} + jpeg := &protobuf.ImageMessage{Type: protobuf.ImageType_JPEG} mime, err := getImageMessageMIME(jpeg) require.NoError(t, err) require.Equal(t, "jpeg", mime) - png := &protobuf.ImageMessage{Type: protobuf.ImageMessage_PNG} + png := &protobuf.ImageMessage{Type: protobuf.ImageType_PNG} mime, err = getImageMessageMIME(png) require.NoError(t, err) require.Equal(t, "png", mime) - webp := &protobuf.ImageMessage{Type: protobuf.ImageMessage_WEBP} + webp := &protobuf.ImageMessage{Type: protobuf.ImageType_WEBP} mime, err = getImageMessageMIME(webp) require.NoError(t, err) require.Equal(t, "webp", mime) - gif := &protobuf.ImageMessage{Type: protobuf.ImageMessage_GIF} + gif := &protobuf.ImageMessage{Type: protobuf.ImageType_GIF} mime, err = getImageMessageMIME(gif) require.NoError(t, err) require.Equal(t, "gif", mime) - unknown := &protobuf.ImageMessage{Type: protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE} + unknown := &protobuf.ImageMessage{Type: protobuf.ImageType_UNKNOWN_IMAGE_TYPE} _, err = getImageMessageMIME(unknown) require.Error(t, err) } @@ -92,7 +92,7 @@ func TestGetAudioMessageMIME(t *testing.T) { require.NoError(t, err) require.Equal(t, "amr", mime) - unknown := &protobuf.ImageMessage{Type: protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE} + unknown := &protobuf.ImageMessage{Type: protobuf.ImageType_UNKNOWN_IMAGE_TYPE} _, err = getImageMessageMIME(unknown) require.Error(t, err) } diff --git a/protocol/images/type.go b/protocol/images/type.go index b64ccb95d..1908980dd 100644 --- a/protocol/images/type.go +++ b/protocol/images/type.go @@ -5,17 +5,17 @@ import ( "github.com/status-im/status-go/protocol/protobuf" ) -func ImageType(buf []byte) protobuf.ImageMessage_ImageType { +func ImageType(buf []byte) protobuf.ImageType { switch images.GetFileType(buf){ case images.JPEG: - return protobuf.ImageMessage_JPEG + return protobuf.ImageType_JPEG case images.PNG: - return protobuf.ImageMessage_PNG + return protobuf.ImageType_PNG case images.GIF: - return protobuf.ImageMessage_GIF + return protobuf.ImageType_GIF case images.WEBP: - return protobuf.ImageMessage_WEBP + return protobuf.ImageType_WEBP default: - return protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE + return protobuf.ImageType_UNKNOWN_IMAGE_TYPE } } diff --git a/protocol/message_validator.go b/protocol/message_validator.go index 6abad5f77..228d2ba51 100644 --- a/protocol/message_validator.go +++ b/protocol/message_validator.go @@ -208,7 +208,7 @@ func ValidateReceivedChatMessage(message *protobuf.ChatMessage, whisperTimestamp if len(image.Payload) == 0 { return errors.New("image payload empty") } - if image.Type == protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE { + if image.Type == protobuf.ImageType_UNKNOWN_IMAGE_TYPE { return errors.New("image type unknown") } } diff --git a/protocol/message_validator_test.go b/protocol/message_validator_test.go index 5960268f9..1f27329a8 100644 --- a/protocol/message_validator_test.go +++ b/protocol/message_validator_test.go @@ -390,7 +390,7 @@ func (s *MessageValidatorSuite) TestValidatePlainTextMessage() { EnsName: "", Payload: &protobuf.ChatMessage_Image{ Image: &protobuf.ImageMessage{ - Type: protobuf.ImageMessage_UNKNOWN_IMAGE_TYPE, + Type: protobuf.ImageType_UNKNOWN_IMAGE_TYPE, Payload: []byte("some-payload"), }, },