Ensuring Channels Properly Close Themselves

This commit is contained in:
Sarah Jamie Lewis 2018-01-13 15:57:37 -05:00
parent 5d9f2ce9e3
commit cf46554922
3 changed files with 21 additions and 3 deletions

View File

@ -139,7 +139,10 @@ func (cc *ChatChannel) Packet(data []byte) {
} else if ack := res.GetChatAcknowledge(); ack != nil { } else if ack := res.GetChatAcknowledge(); ack != nil {
cc.Handler.ChatMessageAck(ack.GetMessageId(), ack.GetAccepted()) cc.Handler.ChatMessageAck(ack.GetMessageId(), ack.GetAccepted())
} }
// XXX?
} }
// We ignore invalid packets.
return
} }
// Close the channel if it is being misused
cc.channel.CloseChannel()
} }

View File

@ -155,8 +155,8 @@ func (crc *ContactRequestChannel) Packet(data []byte) {
err := proto.Unmarshal(data, response) err := proto.Unmarshal(data, response)
if err == nil { if err == nil {
crc.handleStatus(response.GetStatus().String()) crc.handleStatus(response.GetStatus().String())
return
} }
} }
crc.channel.SendMessage([]byte{}) // Whatever happens we close the channel
crc.channel.CloseChannel()
} }

View File

@ -139,7 +139,12 @@ func TestContactRequestPacket(t *testing.T) {
contactRequestChannel.OpenOutboundResult(nil, cr) contactRequestChannel.OpenOutboundResult(nil, cr)
ackp := messageBuilder.ReplyToContactRequest(1, "Accepted") ackp := messageBuilder.ReplyToContactRequest(1, "Accepted")
closed := false
channel.CloseChannel = func() { closed = true }
contactRequestChannel.Packet(ackp) contactRequestChannel.Packet(ackp)
if closed == false {
t.Errorf("Channel Should Have Been Closed")
}
} }
func TestContactRequestRejected(t *testing.T) { func TestContactRequestRejected(t *testing.T) {
@ -160,7 +165,12 @@ func TestContactRequestRejected(t *testing.T) {
contactRequestChannel.OpenOutboundResult(nil, cr) contactRequestChannel.OpenOutboundResult(nil, cr)
ackp := messageBuilder.ReplyToContactRequest(1, "Rejected") ackp := messageBuilder.ReplyToContactRequest(1, "Rejected")
closed := false
channel.CloseChannel = func() { closed = true }
contactRequestChannel.Packet(ackp) contactRequestChannel.Packet(ackp)
if closed == false {
t.Errorf("Channel Should Have Been Closed")
}
} }
func TestContactRequestError(t *testing.T) { func TestContactRequestError(t *testing.T) {
@ -181,7 +191,12 @@ func TestContactRequestError(t *testing.T) {
contactRequestChannel.OpenOutboundResult(nil, cr) contactRequestChannel.OpenOutboundResult(nil, cr)
ackp := messageBuilder.ReplyToContactRequest(1, "Error") ackp := messageBuilder.ReplyToContactRequest(1, "Error")
closed := false
channel.CloseChannel = func() { closed = true }
contactRequestChannel.Packet(ackp) contactRequestChannel.Packet(ackp)
if closed == false {
t.Errorf("Channel Should Have Been Closed")
}
} }
func BuildOpenChannel(nickname string, message string) *Protocol_Data_Control.OpenChannel { func BuildOpenChannel(nickname string, message string) *Protocol_Data_Control.OpenChannel {