Этот коммит содержится в:
Chris
2017-10-16 08:09:43 -07:00
коммит произвёл Joram Wilander
родитель adb2b1d6ed
Коммит 34285d8cca
15 изменённых файлов: 302 добавлений и 61 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package api
import (
"fmt"
"net"
"time"
@@ -69,6 +70,10 @@ func setupTestHelper(enterprise bool) *TestHelper {
var options []app.Option
if testStore != nil {
options = append(options, app.StoreOverride(testStore))
options = append(options, app.ConfigOverride(func(cfg *model.Config) {
cfg.ServiceSettings.ListenAddress = new(string)
*cfg.ServiceSettings.ListenAddress = ":0"
}))
}
th := &TestHelper{
@@ -153,8 +158,9 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper {
func (me *TestHelper) waitForConnectivity() {
for i := 0; i < 1000; i++ {
_, err := net.Dial("tcp", "localhost"+*utils.Cfg.ServiceSettings.ListenAddress)
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%v", me.App.Srv.ListenAddr.Port))
if err == nil {
conn.Close()
return
}
time.Sleep(time.Millisecond * 20)
@@ -163,11 +169,11 @@ func (me *TestHelper) waitForConnectivity() {
}
func (me *TestHelper) CreateClient() *model.Client {
return model.NewClient("http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress)
return model.NewClient(fmt.Sprintf("http://localhost:%v", me.App.Srv.ListenAddr.Port))
}
func (me *TestHelper) CreateWebSocketClient() (*model.WebSocketClient, *model.AppError) {
return model.NewWebSocketClient("ws://localhost"+*utils.Cfg.ServiceSettings.ListenAddress, me.BasicClient.AuthToken)
return model.NewWebSocketClient(fmt.Sprintf("ws://localhost:%v", me.App.Srv.ListenAddr.Port), me.BasicClient.AuthToken)
}
func (me *TestHelper) CreateTeam(client *model.Client) *model.Team {

Просмотреть файл

@@ -4,6 +4,7 @@
package api
import (
"fmt"
"strings"
"testing"
"time"
@@ -257,7 +258,7 @@ func TestTestCommand(t *testing.T) {
*utils.Cfg.ServiceSettings.AllowedUntrustedInternalConnections = "localhost"
cmd1 := &model.Command{
URL: "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test",
URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V3 + "/teams/command_test",
Method: model.COMMAND_METHOD_POST,
Trigger: "testcommand",
}
@@ -290,7 +291,7 @@ func TestTestCommand(t *testing.T) {
}
cmd2 := &model.Command{
URL: "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress + model.API_URL_SUFFIX_V3 + "/teams/command_test",
URL: fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port) + model.API_URL_SUFFIX_V3 + "/teams/command_test",
Method: model.COMMAND_METHOD_GET,
Trigger: "test2",
}

Просмотреть файл

@@ -516,10 +516,7 @@ func TestGetPublicFileOld(t *testing.T) {
store.Must(th.App.Srv.Store.FileInfo().AttachToPost(fileId, th.BasicPost.Id))
// reconstruct old style of link
siteURL := *utils.Cfg.ServiceSettings.SiteURL
if siteURL == "" {
siteURL = "http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress
}
siteURL := fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port)
link := generatePublicLinkOld(siteURL, th.BasicTeam.Id, channel.Id, th.BasicUser.Id, fileId+"/test.png")
// Wait a bit for files to ready

Просмотреть файл

@@ -1153,20 +1153,31 @@ func TestEmailMention(t *testing.T) {
if !strings.ContainsAny(resultsMailbox[len(resultsMailbox)-1].To[0], th.BasicUser2.Email) {
t.Fatal("Wrong To recipient")
} else {
for i := 0; i < 5; i++ {
if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser2.Email, resultsMailbox[len(resultsMailbox)-1].ID); err == nil {
if strings.Contains(resultsEmail.Body.Text, post1.Message) {
break
} else if i == 4 {
t.Log(resultsEmail.Body.Text)
t.Fatal("Received wrong Message")
for i := 0; i < 30; i++ {
for j := len(resultsMailbox) - 1; j >= 0; j-- {
isUser := false
for _, to := range resultsMailbox[j].To {
if to == "<"+th.BasicUser2.Email+">" {
isUser = true
}
}
if !isUser {
continue
}
if resultsEmail, err := utils.GetMessageFromMailbox(th.BasicUser2.Email, resultsMailbox[j].ID); err == nil {
if strings.Contains(resultsEmail.Body.Text, post1.Message) {
return
} else if i == 4 {
t.Log(resultsEmail.Body.Text)
t.Fatal("Received wrong Message")
}
}
time.Sleep(100 * time.Millisecond)
}
time.Sleep(100 * time.Millisecond)
}
t.Fatal("Didn't receive message")
}
}
}
func TestFuzzyPosts(t *testing.T) {

Просмотреть файл

@@ -4,6 +4,7 @@
package api
import (
"fmt"
//"encoding/json"
//"net/http"
"net/http"
@@ -323,7 +324,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
url := "ws://localhost" + *utils.Cfg.ServiceSettings.ListenAddress
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_V3+"/users/websocket", http.Header{
@@ -335,7 +336,7 @@ func TestWebsocketOriginSecurity(t *testing.T) {
// We are not a browser so we can spoof this just fine
_, _, err = websocket.DefaultDialer.Dial(url+model.API_URL_SUFFIX_V3+"/users/websocket", http.Header{
"Origin": []string{"http://localhost" + *utils.Cfg.ServiceSettings.ListenAddress},
"Origin": []string{fmt.Sprintf("http://localhost:%v", th.App.Srv.ListenAddr.Port)},
})
if err != nil {
t.Fatal(err)