[MM-16751] golint model (#17896)
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
953eebdef4
Коммит
97ccf0bdf6
@@ -21,7 +21,7 @@ func TestWebSocketTrailingSlash(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
url := fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port)
|
||||
_, _, err := websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket/", nil)
|
||||
_, _, err := websocket.DefaultDialer.Dial(url+model.ApiUrlSuffix+"/websocket/", nil)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
@@ -36,11 +36,11 @@ func TestWebSocketEvent(t *testing.T) {
|
||||
WebSocketClient.Listen()
|
||||
|
||||
resp := <-WebSocketClient.ResponseChannel
|
||||
require.Equal(t, resp.Status, model.STATUS_OK, "should have responded OK to authentication challenge")
|
||||
require.Equal(t, resp.Status, model.StatusOk, "should have responded OK to authentication challenge")
|
||||
|
||||
omitUser := make(map[string]bool, 1)
|
||||
omitUser["somerandomid"] = true
|
||||
evt1 := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_TYPING, "", th.BasicChannel.Id, "", omitUser)
|
||||
evt1 := model.NewWebSocketEvent(model.WebsocketEventTyping, "", th.BasicChannel.Id, "", omitUser)
|
||||
evt1.Add("user_id", "somerandomid")
|
||||
th.App.Publish(evt1)
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestWebSocketEvent(t *testing.T) {
|
||||
for {
|
||||
select {
|
||||
case resp := <-WebSocketClient.EventChannel:
|
||||
if resp.EventType() == model.WEBSOCKET_EVENT_TYPING && resp.GetData()["user_id"].(string) == "somerandomid" {
|
||||
if resp.EventType() == model.WebsocketEventTyping && resp.GetData()["user_id"].(string) == "somerandomid" {
|
||||
eventHit = true
|
||||
}
|
||||
case <-stop:
|
||||
@@ -68,7 +68,7 @@ func TestWebSocketEvent(t *testing.T) {
|
||||
|
||||
require.True(t, eventHit, "did not receive typing event")
|
||||
|
||||
evt2 := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_TYPING, "", "somerandomid", "", nil)
|
||||
evt2 := model.NewWebSocketEvent(model.WebsocketEventTyping, "", "somerandomid", "", nil)
|
||||
th.App.Publish(evt2)
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestWebSocketEvent(t *testing.T) {
|
||||
for {
|
||||
select {
|
||||
case resp := <-WebSocketClient.EventChannel:
|
||||
if resp.EventType() == model.WEBSOCKET_EVENT_TYPING {
|
||||
if resp.EventType() == model.WebsocketEventTyping {
|
||||
eventHit = true
|
||||
}
|
||||
case <-stop:
|
||||
@@ -114,10 +114,10 @@ func TestCreateDirectChannelWithSocket(t *testing.T) {
|
||||
WebSocketClient.Listen()
|
||||
|
||||
resp := <-WebSocketClient.ResponseChannel
|
||||
require.Equal(t, resp.Status, model.STATUS_OK, "should have responded OK to authentication challenge")
|
||||
require.Equal(t, resp.Status, model.StatusOk, "should have responded OK to authentication challenge")
|
||||
|
||||
wsr := <-WebSocketClient.EventChannel
|
||||
require.Equal(t, wsr.EventType(), model.WEBSOCKET_EVENT_HELLO, "missing hello")
|
||||
require.Equal(t, wsr.EventType(), model.WebsocketEventHello, "missing hello")
|
||||
|
||||
stop := make(chan bool)
|
||||
count := 0
|
||||
@@ -126,7 +126,7 @@ func TestCreateDirectChannelWithSocket(t *testing.T) {
|
||||
for {
|
||||
select {
|
||||
case wsr := <-WebSocketClient.EventChannel:
|
||||
if wsr != nil && wsr.EventType() == model.WEBSOCKET_EVENT_DIRECT_ADDED {
|
||||
if wsr != nil && wsr.EventType() == model.WebsocketEventDirectAdded {
|
||||
count = count + 1
|
||||
}
|
||||
|
||||
@@ -156,42 +156,42 @@ func TestWebsocketOriginSecurity(t *testing.T) {
|
||||
url := fmt.Sprintf("ws://localhost:%v", th.App.Srv().ListenAddr.Port)
|
||||
|
||||
// Should fail because origin doesn't match
|
||||
_, _, err := websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
_, _, err := websocket.DefaultDialer.Dial(url+model.ApiUrlSuffix+"/websocket", http.Header{
|
||||
"Origin": []string{"http://www.evil.com"},
|
||||
})
|
||||
|
||||
require.Error(t, err, "Should have errored because Origin does not match host! SECURITY ISSUE!")
|
||||
|
||||
// We are not a browser so we can spoof this just fine
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.ApiUrlSuffix+"/websocket", http.Header{
|
||||
"Origin": []string{fmt.Sprintf("http://localhost:%v", th.App.Srv().ListenAddr.Port)},
|
||||
})
|
||||
require.NoError(t, err, err)
|
||||
|
||||
// Should succeed now because open CORS
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "*" })
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.ApiUrlSuffix+"/websocket", http.Header{
|
||||
"Origin": []string{"http://www.evil.com"},
|
||||
})
|
||||
require.NoError(t, err, err)
|
||||
|
||||
// Should succeed now because matching CORS
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "http://www.evil.com" })
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.ApiUrlSuffix+"/websocket", http.Header{
|
||||
"Origin": []string{"http://www.evil.com"},
|
||||
})
|
||||
require.NoError(t, err, err)
|
||||
|
||||
// Should fail because non-matching CORS
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "http://www.good.com" })
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.ApiUrlSuffix+"/websocket", http.Header{
|
||||
"Origin": []string{"http://www.evil.com"},
|
||||
})
|
||||
require.Error(t, err, "Should have errored because Origin contain AllowCorsFrom")
|
||||
|
||||
// Should fail because non-matching CORS
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowCorsFrom = "http://www.good.com" })
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX+"/websocket", http.Header{
|
||||
_, _, err = websocket.DefaultDialer.Dial(url+model.ApiUrlSuffix+"/websocket", http.Header{
|
||||
"Origin": []string{"http://www.good.co"},
|
||||
})
|
||||
require.Error(t, err, "Should have errored because Origin does not match host! SECURITY ISSUE!")
|
||||
@@ -210,9 +210,9 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
WebSocketClient.Listen()
|
||||
|
||||
resp := <-WebSocketClient.ResponseChannel
|
||||
require.Equal(t, resp.Status, model.STATUS_OK, "should have responded OK to authentication challenge")
|
||||
require.Equal(t, resp.Status, model.StatusOk, "should have responded OK to authentication challenge")
|
||||
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewRandomTeamName() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
team := model.Team{DisplayName: "Name", Name: "z-z-" + model.NewRandomTeamName() + "a", Email: "test@nowhere.com", Type: model.TeamOpen}
|
||||
rteam, _ := Client.CreateTeam(&team)
|
||||
|
||||
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@simulator.amazonses.com", Nickname: "Corey Hulen", Password: "passwd1"}
|
||||
@@ -242,7 +242,7 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
|
||||
require.Equal(t, resp.SeqReply, WebSocketClient.Sequence-1, "bad sequence number")
|
||||
|
||||
allowedValues := [4]string{model.STATUS_OFFLINE, model.STATUS_AWAY, model.STATUS_ONLINE, model.STATUS_DND}
|
||||
allowedValues := [4]string{model.StatusOffline, model.StatusAway, model.StatusOnline, model.StatusDnd}
|
||||
for _, status := range resp.Data {
|
||||
require.Containsf(t, allowedValues, status, "one of the statuses had an invalid value status=%v", status)
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
status, ok := resp.Data[th.BasicUser2.Id]
|
||||
require.True(t, ok, "should have had user status")
|
||||
|
||||
require.Equal(t, status, model.STATUS_ONLINE, "status should have been online status=%v", status)
|
||||
require.Equal(t, status, model.StatusOnline, "status should have been online status=%v", status)
|
||||
|
||||
WebSocketClient.GetStatusesByIds([]string{th.BasicUser2.Id})
|
||||
resp = <-WebSocketClient.ResponseChannel
|
||||
@@ -258,7 +258,7 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
|
||||
require.Equal(t, resp.SeqReply, WebSocketClient.Sequence-1, "bad sequence number")
|
||||
|
||||
allowedValues = [4]string{model.STATUS_OFFLINE, model.STATUS_AWAY, model.STATUS_ONLINE}
|
||||
allowedValues = [4]string{model.StatusOffline, model.StatusAway, model.StatusOnline}
|
||||
for _, status := range resp.Data {
|
||||
require.Containsf(t, allowedValues, status, "one of the statuses had an invalid value status")
|
||||
}
|
||||
@@ -266,7 +266,7 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
status, ok = resp.Data[th.BasicUser2.Id]
|
||||
require.True(t, ok, "should have had user status")
|
||||
|
||||
require.Equal(t, status, model.STATUS_ONLINE, "status should have been online status=%v", status)
|
||||
require.Equal(t, status, model.StatusOnline, "status should have been online status=%v", status)
|
||||
require.Equal(t, len(resp.Data), 1, "only 1 status should be returned")
|
||||
|
||||
WebSocketClient.GetStatusesByIds([]string{ruser2.Id, "junk"})
|
||||
@@ -314,11 +314,11 @@ func TestWebSocketStatuses(t *testing.T) {
|
||||
for {
|
||||
select {
|
||||
case resp := <-WebSocketClient.EventChannel:
|
||||
if resp.EventType() == model.WEBSOCKET_EVENT_STATUS_CHANGE && resp.GetData()["user_id"].(string) == th.BasicUser.Id {
|
||||
if resp.EventType() == model.WebsocketEventStatusChange && resp.GetData()["user_id"].(string) == th.BasicUser.Id {
|
||||
status := resp.GetData()["status"].(string)
|
||||
if status == model.STATUS_ONLINE {
|
||||
if status == model.StatusOnline {
|
||||
onlineHit = true
|
||||
} else if status == model.STATUS_AWAY {
|
||||
} else if status == model.StatusAway {
|
||||
awayHit = true
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user