summaryrefslogtreecommitdiffstats
path: root/api/websocket_test.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-02-14 17:25:40 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-02-14 17:25:40 -0500
commit2e0cf56e86656e791e20fb31566881e8fb748649 (patch)
treeeafcd53a66f7cc15eb9e207766d0446e8ed37b81 /api/websocket_test.go
parentb86e0daf83c8b7d42f06dcc975542c28fe9ecc69 (diff)
downloadchat-2e0cf56e86656e791e20fb31566881e8fb748649.tar.gz
chat-2e0cf56e86656e791e20fb31566881e8fb748649.tar.bz2
chat-2e0cf56e86656e791e20fb31566881e8fb748649.zip
Fixing websocket auth then sending challenge (#5406)
Diffstat (limited to 'api/websocket_test.go')
-rw-r--r--api/websocket_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/api/websocket_test.go b/api/websocket_test.go
index 6b8937d81..ab2959b03 100644
--- a/api/websocket_test.go
+++ b/api/websocket_test.go
@@ -251,6 +251,69 @@ func TestWebSocketEvent(t *testing.T) {
}
}
+func TestCreateDirectChannelWithSocket(t *testing.T) {
+ th := Setup().InitBasic()
+ Client := th.BasicClient
+ user2 := th.BasicUser2
+
+ users := make([]*model.User, 0)
+ users = append(users, user2)
+
+ for i := 0; i < 10; i++ {
+ users = append(users, th.CreateUser(Client))
+ }
+
+ WebSocketClient, err := th.CreateWebSocketClient()
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer WebSocketClient.Close()
+ WebSocketClient.Listen()
+
+ time.Sleep(300 * time.Millisecond)
+ if resp := <-WebSocketClient.ResponseChannel; resp.Status != model.STATUS_OK {
+ t.Fatal("should have responded OK to authentication challenge")
+ }
+
+ wsr := <-WebSocketClient.EventChannel
+ if wsr.Event != model.WEBSOCKET_EVENT_HELLO {
+ t.Fatal("missing hello")
+ }
+
+ stop := make(chan bool)
+ count := 0
+
+ go func() {
+ for {
+ select {
+ case wsr := <-WebSocketClient.EventChannel:
+ if wsr.Event == model.WEBSOCKET_EVENT_DIRECT_ADDED {
+ count = count + 1
+ }
+
+ case <-stop:
+ return
+ }
+ }
+ }()
+
+ for _, user := range users {
+ time.Sleep(100 * time.Millisecond)
+ if _, err := Client.CreateDirectChannel(user.Id); err != nil {
+ t.Fatal("failed to create DM channel")
+ }
+ }
+
+ time.Sleep(5000 * time.Millisecond)
+
+ stop <- true
+
+ if count != len(users) {
+ t.Fatal("We didn't get the proper amount of direct_added messages")
+ }
+
+}
+
func TestWebsocketOriginSecurity(t *testing.T) {
Setup().InitBasic()
url := "ws://localhost" + utils.Cfg.ServiceSettings.ListenAddress