MCPcopy
hub / github.com/tinode/chat / TestHandleBroadcastInfoBogusNotification

Function TestHandleBroadcastInfoBogusNotification

server/topic_test.go:765–811  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

763}
764
765func TestHandleBroadcastInfoBogusNotification(t *testing.T) {
766 topicName := "usrP2P"
767 numUsers := 2
768 helper := TopicTestHelper{}
769 helper.setUp(t, numUsers, types.TopicCatP2P, topicName, true)
770 defer helper.tearDown()
771 // Pretend we have 10 messages.
772 helper.topic.lastID = 10
773 // uid1 notifies uid2 that uid1 has read messages up to seqid 11.
774 readId := 11
775 from := helper.uids[0]
776 to := helper.uids[1]
777
778 msg := &ClientComMessage{
779 AsUser: from.UserId(),
780 Original: to.UserId(),
781 Note: &MsgClientNote{
782 Topic: to.UserId(),
783 What: "read",
784 SeqId: readId,
785 },
786 sess: helper.sessions[0],
787 }
788 helper.topic.handleClientMsg(msg)
789 helper.finish()
790
791 // Check for errors from testHubLoop
792 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
793 t.Fatal(errorMsgs[0].Ctrl.Text)
794 }
795
796 // Read id should not be updated.
797 if actualReadId := helper.topic.perUser[from].readID; actualReadId != 0 {
798 t.Errorf("perUser[%s].readID: expected 0, found %d.", from.UserId(), actualReadId)
799 }
800 // Server messages.
801 for i, r := range helper.results {
802 if numMessages := len(r.messages); numMessages != 0 {
803 t.Errorf("User %d is not expected to receive any messages, %d received.", i, numMessages)
804 }
805 }
806
807 // Nothing should be routed through the hub.
808 if len(helper.hubMessages) != 0 {
809 t.Errorf("Hubhelper.route did not expect any messages, however %d received.", len(helper.hubMessages))
810 }
811}
812
813func TestHandleBroadcastInfoFilterOutRecvWithoutRPermission(t *testing.T) {
814 topicName := "usrP2P"

Callers

nothing calls this directly

Calls 5

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
handleClientMsgMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…