summaryrefslogtreecommitdiffstats
path: root/api4/command_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2018-07-06 21:07:42 +0800
committerJoram Wilander <jwawilander@gmail.com>2018-07-06 09:07:42 -0400
commit9e5ec7d09d4c51e278f17f25fb6c0f3484b50a3b (patch)
tree592ab1107b664fdd0f21017973decfe6798fa7ed /api4/command_test.go
parenta92f5addccad0f77079308ff853a8251db5f2d09 (diff)
downloadchat-9e5ec7d09d4c51e278f17f25fb6c0f3484b50a3b.tar.gz
chat-9e5ec7d09d4c51e278f17f25fb6c0f3484b50a3b.tar.bz2
chat-9e5ec7d09d4c51e278f17f25fb6c0f3484b50a3b.zip
[MM-10754] Remove unnecessary command_test route (#9050)
* remove unnecessary command_test route * replaced localhost with ts.URL
Diffstat (limited to 'api4/command_test.go')
-rw-r--r--api4/command_test.go96
1 files changed, 81 insertions, 15 deletions
diff --git a/api4/command_test.go b/api4/command_test.go
index 0d37d7440..96025c063 100644
--- a/api4/command_test.go
+++ b/api4/command_test.go
@@ -4,7 +4,6 @@
package api4
import (
- "fmt"
"net/http"
"net/http/httptest"
"net/url"
@@ -423,7 +422,7 @@ func TestExecuteInvalidCommand(t *testing.T) {
getCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: th.BasicTeam.Id,
- URL: fmt.Sprintf("%s/%s/teams/command_test", ts.URL, model.API_URL_SUFFIX_V4),
+ URL: ts.URL,
Method: model.COMMAND_METHOD_GET,
Trigger: "getcommand",
}
@@ -501,7 +500,7 @@ func TestExecuteGetCommand(t *testing.T) {
getCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: th.BasicTeam.Id,
- URL: fmt.Sprintf("%s/%s/teams/command_test", ts.URL, model.API_URL_SUFFIX_V4),
+ URL: ts.URL,
Method: model.COMMAND_METHOD_GET,
Trigger: "getcommand",
Token: token,
@@ -556,16 +555,16 @@ func TestExecutePostCommand(t *testing.T) {
}))
defer ts.Close()
- getCmd := &model.Command{
+ postCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: th.BasicTeam.Id,
- URL: fmt.Sprintf("%s/%s/teams/command_test", ts.URL, model.API_URL_SUFFIX_V4),
+ URL: ts.URL,
Method: model.COMMAND_METHOD_POST,
Trigger: "postcommand",
Token: token,
}
- if _, err := th.App.CreateCommand(getCmd); err != nil {
+ if _, err := th.App.CreateCommand(postCmd); err != nil {
t.Fatal("failed to create get command")
}
@@ -592,14 +591,29 @@ func TestExecuteCommandAgainstChannelOnAnotherTeam(t *testing.T) {
})
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ })
+
+ expectedCommandResponse := &model.CommandResponse{
+ Text: "test post command response",
+ ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
+ Type: "custom_test",
+ Props: map[string]interface{}{"someprop": "somevalue"},
+ }
+
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(expectedCommandResponse.ToJson()))
+ }))
+ defer ts.Close()
// create a slash command on some other team where we have permission to do so
team2 := th.CreateTeam()
postCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: team2.Id,
- URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V4 + "/teams/command_test",
+ URL: ts.URL,
Method: model.COMMAND_METHOD_POST,
Trigger: "postcommand",
}
@@ -627,14 +641,29 @@ func TestExecuteCommandAgainstChannelUserIsNotIn(t *testing.T) {
})
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ })
+
+ expectedCommandResponse := &model.CommandResponse{
+ Text: "test post command response",
+ ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
+ Type: "custom_test",
+ Props: map[string]interface{}{"someprop": "somevalue"},
+ }
+
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(expectedCommandResponse.ToJson()))
+ }))
+ defer ts.Close()
// create a slash command on some other team where we have permission to do so
team2 := th.CreateTeam()
postCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: team2.Id,
- URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V4 + "/teams/command_test",
+ URL: ts.URL,
Method: model.COMMAND_METHOD_POST,
Trigger: "postcommand",
}
@@ -667,14 +696,32 @@ func TestExecuteCommandInDirectMessageChannel(t *testing.T) {
})
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ })
- // create a slash command on some other team where we have permission to do so
+ // create a team that the user isn't a part of
team2 := th.CreateTeam()
+
+ expectedCommandResponse := &model.CommandResponse{
+ Text: "test post command response",
+ ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
+ Type: "custom_test",
+ Props: map[string]interface{}{"someprop": "somevalue"},
+ }
+
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ require.Equal(t, http.MethodPost, r.Method)
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(expectedCommandResponse.ToJson()))
+ }))
+ defer ts.Close()
+
+ // create a slash command on some other team where we have permission to do so
postCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: team2.Id,
- URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V4 + "/teams/command_test",
+ URL: ts.URL,
Method: model.COMMAND_METHOD_POST,
Trigger: "postcommand",
}
@@ -709,16 +756,35 @@ func TestExecuteCommandInTeamUserIsNotOn(t *testing.T) {
})
}()
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableCommands = true })
- th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost" })
+ th.App.UpdateConfig(func(cfg *model.Config) {
+ *cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost 127.0.0.1"
+ })
// create a team that the user isn't a part of
team2 := th.CreateTeam()
+ expectedCommandResponse := &model.CommandResponse{
+ Text: "test post command response",
+ ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
+ Type: "custom_test",
+ Props: map[string]interface{}{"someprop": "somevalue"},
+ }
+
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ require.Equal(t, http.MethodPost, r.Method)
+ r.ParseForm()
+ require.Equal(t, team2.Name, r.FormValue("team_domain"))
+
+ w.Header().Set("Content-Type", "application/json")
+ w.Write([]byte(expectedCommandResponse.ToJson()))
+ }))
+ defer ts.Close()
+
// create a slash command on that team
postCmd := &model.Command{
CreatorId: th.BasicUser.Id,
TeamId: team2.Id,
- URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V4 + "/teams/command_test",
+ URL: ts.URL,
Method: model.COMMAND_METHOD_POST,
Trigger: "postcommand",
}