bind to localhost:0 for tests (#22839)
* bind to localhost:0 for tests Explicitly bind to `localhost:0` instead of just `:0` to avoid binding to all available interfaces and in turn avoid triggering firewall warnings on MacOS. * fix Playbooks to use dynamic port * TestMetrics: handle ipv4 localhost too * TestMetrics: linting
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7325c38c39
Коммит
4b7f6cb974
@@ -177,7 +177,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
|||||||
*cfg.PasswordSettings.Symbol = false
|
*cfg.PasswordSettings.Symbol = false
|
||||||
*cfg.PasswordSettings.Number = false
|
*cfg.PasswordSettings.Number = false
|
||||||
|
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
})
|
})
|
||||||
if err := th.Server.Start(); err != nil {
|
if err := th.Server.Start(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func TestAppRace(t *testing.T) {
|
|||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
a, err := New()
|
a, err := New()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
|
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = "localhost:0" })
|
||||||
serverErr := a.StartServer()
|
serverErr := a.StartServer()
|
||||||
require.NoError(t, serverErr)
|
require.NoError(t, serverErr)
|
||||||
a.Srv().Shutdown()
|
a.Srv().Shutdown()
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
|
||||||
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
|
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = "localhost:0" })
|
||||||
serverErr := th.Server.Start()
|
serverErr := th.Server.Start()
|
||||||
if serverErr != nil {
|
if serverErr != nil {
|
||||||
panic(serverErr)
|
panic(serverErr)
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
|||||||
*memoryConfig.AnnouncementSettings.AdminNoticesEnabled = false
|
*memoryConfig.AnnouncementSettings.AdminNoticesEnabled = false
|
||||||
*memoryConfig.AnnouncementSettings.UserNoticesEnabled = false
|
*memoryConfig.AnnouncementSettings.UserNoticesEnabled = false
|
||||||
*memoryConfig.MetricsSettings.Enable = true
|
*memoryConfig.MetricsSettings.Enable = true
|
||||||
*memoryConfig.ServiceSettings.ListenAddress = ":0"
|
*memoryConfig.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
*memoryConfig.MetricsSettings.ListenAddress = ":0"
|
*memoryConfig.MetricsSettings.ListenAddress = "localhost:0"
|
||||||
configStore.Set(memoryConfig)
|
configStore.Set(memoryConfig)
|
||||||
|
|
||||||
ps, err := New(ServiceConfig{
|
ps, err := New(ServiceConfig{
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ func TestMetrics(t *testing.T) {
|
|||||||
|
|
||||||
require.NotNil(t, th.Service.metrics)
|
require.NotNil(t, th.Service.metrics)
|
||||||
metricsAddr := strings.Replace(th.Service.metrics.listenAddr, "[::]", "http://localhost", 1)
|
metricsAddr := strings.Replace(th.Service.metrics.listenAddr, "[::]", "http://localhost", 1)
|
||||||
|
metricsAddr = strings.Replace(metricsAddr, "127.0.0.1", "http://localhost", 1)
|
||||||
|
|
||||||
resp, err := http.Get(metricsAddr)
|
resp, err := http.Get(metricsAddr)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func newServerWithConfig(t *testing.T, f func(cfg *model.Config)) (*Server, erro
|
|||||||
|
|
||||||
func TestStartServerSuccess(t *testing.T) {
|
func TestStartServerSuccess(t *testing.T) {
|
||||||
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ func TestStartServerPortUnavailable(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Listen on the next available port
|
// Listen on the next available port
|
||||||
listener, err := net.Listen("tcp", ":0")
|
listener, err := net.Listen("tcp", "localhost:0")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Attempt to listen on the port used above.
|
// Attempt to listen on the port used above.
|
||||||
@@ -104,7 +104,7 @@ func TestStartServerNoS3Bucket(t *testing.T) {
|
|||||||
AmazonS3PathPrefix: model.NewString(""),
|
AmazonS3PathPrefix: model.NewString(""),
|
||||||
AmazonS3SSL: model.NewBool(false),
|
AmazonS3SSL: model.NewBool(false),
|
||||||
}
|
}
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
_, _, err := store.Set(cfg)
|
_, _, err := store.Set(cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ func TestStartServerTLSSuccess(t *testing.T) {
|
|||||||
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
||||||
testDir, _ := fileutils.FindDir("tests")
|
testDir, _ := fileutils.FindDir("tests")
|
||||||
|
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
||||||
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
||||||
*cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem")
|
*cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem")
|
||||||
@@ -185,7 +185,7 @@ func TestStartServerTLSVersion(t *testing.T) {
|
|||||||
cfg := store.Get()
|
cfg := store.Get()
|
||||||
testDir, _ := fileutils.FindDir("tests")
|
testDir, _ := fileutils.FindDir("tests")
|
||||||
|
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
||||||
*cfg.ServiceSettings.TLSMinVer = "1.2"
|
*cfg.ServiceSettings.TLSMinVer = "1.2"
|
||||||
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
||||||
@@ -229,7 +229,7 @@ func TestStartServerTLSOverwriteCipher(t *testing.T) {
|
|||||||
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
||||||
testDir, _ := fileutils.FindDir("tests")
|
testDir, _ := fileutils.FindDir("tests")
|
||||||
|
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
||||||
cfg.ServiceSettings.TLSOverwriteCiphers = []string{
|
cfg.ServiceSettings.TLSOverwriteCiphers = []string{
|
||||||
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
|
||||||
@@ -328,7 +328,7 @@ func TestPanicLog(t *testing.T) {
|
|||||||
|
|
||||||
testDir, _ := fileutils.FindDir("tests")
|
testDir, _ := fileutils.FindDir("tests")
|
||||||
s.platform.UpdateConfig(func(cfg *model.Config) {
|
s.platform.UpdateConfig(func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
||||||
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
||||||
*cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem")
|
*cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem")
|
||||||
@@ -404,7 +404,7 @@ func TestSentry(t *testing.T) {
|
|||||||
SentryDSN = dsn.String()
|
SentryDSN = dsn.String()
|
||||||
|
|
||||||
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
*cfg.LogSettings.EnableSentry = false
|
*cfg.LogSettings.EnableSentry = false
|
||||||
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
||||||
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
||||||
@@ -448,7 +448,7 @@ func TestSentry(t *testing.T) {
|
|||||||
SentryDSN = dsn.String()
|
SentryDSN = dsn.String()
|
||||||
|
|
||||||
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
s, err := newServerWithConfig(t, func(cfg *model.Config) {
|
||||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
*cfg.ServiceSettings.ListenAddress = "localhost:0"
|
||||||
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
*cfg.ServiceSettings.ConnectionSecurity = "TLS"
|
||||||
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
*cfg.ServiceSettings.TLSKeyFile = path.Join(testDir, "tls_test_key.pem")
|
||||||
*cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem")
|
*cfg.ServiceSettings.TLSCertFile = path.Join(testDir, "tls_test_cert.pem")
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func setupTestHelper(dbStore store.Store, enterprise bool, includeCacheLayer boo
|
|||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 })
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.RateLimitSettings.Enable = false })
|
||||||
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
|
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
|
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = "localhost:0" })
|
||||||
serverErr := th.Server.Start()
|
serverErr := th.Server.Start()
|
||||||
if serverErr != nil {
|
if serverErr != nil {
|
||||||
panic(serverErr)
|
panic(serverErr)
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func setupTestHelper(tb testing.TB, includeCacheLayer bool) *TestHelper {
|
|||||||
|
|
||||||
a := app.New(app.ServerConnector(s.Channels()))
|
a := app.New(app.ServerConnector(s.Channels()))
|
||||||
prevListenAddress := *s.Config().ServiceSettings.ListenAddress
|
prevListenAddress := *s.Config().ServiceSettings.ListenAddress
|
||||||
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
|
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = "localhost:0" })
|
||||||
serverErr := s.Start()
|
serverErr := s.Start()
|
||||||
if serverErr != nil {
|
if serverErr != nil {
|
||||||
panic(serverErr)
|
panic(serverErr)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
unitTestListeningPort = ":0"
|
unitTestListeningPort = "localhost:0"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:golint,unused
|
//nolint:golint,unused
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -117,7 +118,7 @@ func Setup(t *testing.T) *TestEnvironment {
|
|||||||
config := configStore.Get()
|
config := configStore.Get()
|
||||||
// Force plugins to be disabled since we are in product mode
|
// Force plugins to be disabled since we are in product mode
|
||||||
config.PluginSettings.Enable = model.NewBool(false)
|
config.PluginSettings.Enable = model.NewBool(false)
|
||||||
config.ServiceSettings.ListenAddress = model.NewString("localhost:9056")
|
config.ServiceSettings.ListenAddress = model.NewString("localhost:0")
|
||||||
config.TeamSettings.MaxUsersPerTeam = model.NewInt(10000)
|
config.TeamSettings.MaxUsersPerTeam = model.NewInt(10000)
|
||||||
config.LocalizationSettings.SetDefaults()
|
config.LocalizationSettings.SetDefaults()
|
||||||
config.SqlSettings = *sqlSettings
|
config.SqlSettings = *sqlSettings
|
||||||
@@ -218,7 +219,7 @@ func (e *TestEnvironment) CreateClients() {
|
|||||||
require.Nil(e.T, appErr)
|
require.Nil(e.T, appErr)
|
||||||
e.RegularUserNotInTeam = notInTeam
|
e.RegularUserNotInTeam = notInTeam
|
||||||
|
|
||||||
siteURL := "http://localhost:9056"
|
siteURL := fmt.Sprintf("http://localhost:%v", e.A.Srv().ListenAddr.Port)
|
||||||
|
|
||||||
serverAdminClient := model.NewAPIv4Client(siteURL)
|
serverAdminClient := model.NewAPIv4Client(siteURL)
|
||||||
_, _, err := serverAdminClient.Login(admin.Email, userPassword)
|
_, _, err := serverAdminClient.Login(admin.Email, userPassword)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user