Skip to content
Snippets Groups Projects
Commit c0c35349 authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

fixed the messages_test.go and removed the emoji filtering becasue the lib requires 1.18

parent 1d29bc16
No related branches found
No related tags found
5 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!371[Channel RSAtoPrivate] Implement Reverse Asymmetric in Client/Broadcast,!354Channels impl,!340Project/channels
......@@ -44,9 +44,9 @@ func (al *adminListener) Listen(payload []byte,
// check the round to ensure the message is not a replay
if id.Round(cm.RoundID) != round.ID {
jww.WARN.Printf("The round message %s send on %d referenced "+
jww.WARN.Printf("The round message %s send on %s referenced "+
"(%d) was not the same as the round the message was found on (%d)",
msgID, al.chID, cm.RoundID, round.ID, al.chID)
msgID, al.chID, cm.RoundID, round.ID)
return
}
......
package channels
import (
"github.com/forPelevin/gomoji"
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
)
var InvalidReaction = errors.New("The reaction is not valid, " +
......@@ -10,13 +10,6 @@ var InvalidReaction = errors.New("The reaction is not valid, " +
// ValidateReaction checks that the reaction only contains a single Emoji
func ValidateReaction(reaction string) error {
if len(gomoji.RemoveEmojis(reaction)) > 0 {
return InvalidReaction
}
if len(gomoji.FindAll(reaction)) != 1 {
return InvalidReaction
}
jww.WARN.Printf("Reaction Validation Not Yet Implemented")
return nil
}
......@@ -30,7 +30,7 @@ func NewUserMessageInternal(ursMsg *UserMessage) (*UserMessageInternal, error) {
return &UserMessageInternal{
userMessage: ursMsg,
channelMessage: channelMessage,
messageID: channel.MakeMessageID(channelMessage.Payload),
messageID: channel.MakeMessageID(ursMsg.Message),
}, nil
}
......
......@@ -8,14 +8,18 @@
package channels
import (
"bytes"
"github.com/golang/protobuf/proto"
"gitlab.com/elixxir/crypto/channel"
"reflect"
"testing"
)
func TestUserMessageInternal_GetChannelMessage(t *testing.T) {
channelMsg := &ChannelMessage{
Payload: []byte("ban_badUSer"),
Lease: 69,
RoundID: 42,
PayloadType: 7,
Payload: []byte("ban_badUSer"),
}
serialized, err := proto.Marshal(channelMsg)
......@@ -33,10 +37,121 @@ func TestUserMessageInternal_GetChannelMessage(t *testing.T) {
internal, _ := NewUserMessageInternal(usrMsg)
received := internal.GetChannelMessage()
if !bytes.Equal(received.Payload, channelMsg.Payload) {
if !reflect.DeepEqual(received.Payload, channelMsg.Payload) ||
received.Lease != channelMsg.Lease ||
received.RoundID != channelMsg.RoundID ||
received.PayloadType != channelMsg.PayloadType {
t.Fatalf("GetChannelMessage did not return expected data."+
"\nExpected: %v"+
"\nReceived: %v", channelMsg, received)
}
}
func TestUserMessageInternal_GetUserMessage(t *testing.T) {
channelMsg := &ChannelMessage{
Lease: 69,
RoundID: 42,
PayloadType: 7,
Payload: []byte("ban_badUSer"),
}
serialized, err := proto.Marshal(channelMsg)
if err != nil {
t.Fatalf("Marshal error: %v", err)
}
usrMsg := &UserMessage{
Message: serialized,
ValidationSignature: []byte("sig"),
Signature: []byte("sig2"),
Username: "hunter2",
ECCPublicKey: []byte("key"),
UsernameLease: 666,
}
internal, _ := NewUserMessageInternal(usrMsg)
received := internal.GetUserMessage()
if !reflect.DeepEqual(received.Message, usrMsg.Message) ||
received.Username != usrMsg.Username ||
received.UsernameLease != usrMsg.UsernameLease ||
!reflect.DeepEqual(received.Signature, usrMsg.Signature) ||
!reflect.DeepEqual(received.ValidationSignature, usrMsg.ValidationSignature) ||
!reflect.DeepEqual(received.ECCPublicKey, usrMsg.ECCPublicKey) {
t.Fatalf("GetUserMessage did not return expected data."+
"\nExpected: %v"+
"\nReceived: %v", usrMsg, received)
}
}
func TestUserMessageInternal_GetMessageID(t *testing.T) {
channelMsg := &ChannelMessage{
Lease: 69,
RoundID: 42,
PayloadType: 7,
Payload: []byte("ban_badUSer"),
}
serialized, err := proto.Marshal(channelMsg)
if err != nil {
t.Fatalf("Marshal error: %v", err)
}
usrMsg := &UserMessage{
Message: serialized,
ValidationSignature: []byte("sig"),
Signature: []byte("sig2"),
Username: "hunter2",
ECCPublicKey: []byte("key"),
UsernameLease: 666,
}
internal, _ := NewUserMessageInternal(usrMsg)
received := internal.GetMessageID()
expected := channel.MakeMessageID(usrMsg.Message)
if !reflect.DeepEqual(expected, received) {
t.Fatalf("GetMessageID did not return expected data."+
"\nExpected: %v"+
"\nReceived: %v", expected, received)
}
}
// Ensures the serialization hasn't changed, changing the message IDs. The
// protocol is tolerant of this because only the sender seralizes, but
// it would be good to know when this changes. If this test breaks, report it,
// but it should be safe to update the expected
func TestUserMessageInternal_GetMessageID_Consistency(t *testing.T) {
expected := "ChMsgID-cfw4O6M47N9pqdtTcQjm/SSVqehTPGQd7cAMrNP9bcc="
channelMsg := &ChannelMessage{
Lease: 69,
RoundID: 42,
PayloadType: 7,
Payload: []byte("ban_badUSer"),
}
serialized, err := proto.Marshal(channelMsg)
if err != nil {
t.Fatalf("Marshal error: %v", err)
}
usrMsg := &UserMessage{
Message: serialized,
ValidationSignature: []byte("sig"),
Signature: []byte("sig2"),
Username: "hunter2",
ECCPublicKey: []byte("key"),
UsernameLease: 666,
}
internal, _ := NewUserMessageInternal(usrMsg)
received := internal.GetMessageID()
if expected != received.String() {
t.Fatalf("GetMessageID did not return expected data."+
"\nExpected: %v"+
"\nReceived: %v", expected, received)
}
}
......@@ -48,7 +48,7 @@ func (gul *userListener) Listen(payload []byte,
if id.Round(cm.RoundID) != round.ID {
jww.WARN.Printf("The round message %s send on %d referenced "+
"(%d) was not the same as the round the message was found on (%d)",
msgID, gul.chID, cm.RoundID, round.ID, gul.chID)
msgID, gul.chID, cm.RoundID, round.ID)
return
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment