MM-9983 Requiring SiteURL to be set. (#8769)
* Requiring SiteURL to be set. * Modifying to make tests pass. * Fixing test.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d5e1f7e298
Коммит
0432f995ec
@@ -6,6 +6,8 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -129,7 +131,19 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform
|
|||||||
|
|
||||||
// Enable developer settings if this is a "dev" build
|
// Enable developer settings if this is a "dev" build
|
||||||
if model.BuildNumber == "dev" {
|
if model.BuildNumber == "dev" {
|
||||||
a.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableDeveloper = true })
|
a.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.EnableDeveloper = true
|
||||||
|
if *cfg.ServiceSettings.SiteURL == "" {
|
||||||
|
*cfg.ServiceSettings.SiteURL = "http://localhost:8065"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SiteURL should be set at this point. Either by a user or by the dev mode above
|
||||||
|
// This is here instead of in config.IsValid because there are many tests that make the assumption
|
||||||
|
// that the default config is valid. Which it is not.
|
||||||
|
if _, err := url.ParseRequestURI(*a.Config().ServiceSettings.SiteURL); err != nil {
|
||||||
|
return model.NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
resetStatuses(a)
|
resetStatuses(a)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/jobs"
|
"github.com/mattermost/mattermost-server/jobs"
|
||||||
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -20,6 +21,7 @@ type ServerTestHelper struct {
|
|||||||
disableConfigWatch bool
|
disableConfigWatch bool
|
||||||
interruptChan chan os.Signal
|
interruptChan chan os.Signal
|
||||||
originalInterval int
|
originalInterval int
|
||||||
|
oldBuildNumber string
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetupServerTest() *ServerTestHelper {
|
func SetupServerTest() *ServerTestHelper {
|
||||||
@@ -41,14 +43,20 @@ func SetupServerTest() *ServerTestHelper {
|
|||||||
interruptChan: interruptChan,
|
interruptChan: interruptChan,
|
||||||
originalInterval: originalInterval,
|
originalInterval: originalInterval,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run in dev mode so SiteURL gets set
|
||||||
|
th.oldBuildNumber = model.BuildNumber
|
||||||
|
model.BuildNumber = "dev"
|
||||||
|
|
||||||
return th
|
return th
|
||||||
}
|
}
|
||||||
|
|
||||||
func (th *ServerTestHelper) TearDownServerTest() {
|
func (th *ServerTestHelper) TearDownServerTest() {
|
||||||
jobs.DEFAULT_WATCHER_POLLING_INTERVAL = th.originalInterval
|
jobs.DEFAULT_WATCHER_POLLING_INTERVAL = th.originalInterval
|
||||||
|
model.BuildNumber = th.oldBuildNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunServerSuccess(t *testing.T) {
|
func TestRunServerSiteURL(t *testing.T) {
|
||||||
th := SetupServerTest()
|
th := SetupServerTest()
|
||||||
defer th.TearDownServerTest()
|
defer th.TearDownServerTest()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"ServiceSettings": {
|
"ServiceSettings": {
|
||||||
"SiteURL": "http://localhost:8065",
|
"SiteURL": "",
|
||||||
"WebsocketURL": "",
|
"WebsocketURL": "",
|
||||||
"LicenseFileLocation": "",
|
"LicenseFileLocation": "",
|
||||||
"ListenAddress": ":8065",
|
"ListenAddress": ":8065",
|
||||||
|
|||||||
@@ -5228,7 +5228,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.config.is_valid.site_url.app_error",
|
"id": "model.config.is_valid.site_url.app_error",
|
||||||
"translation": "Site URL must be a valid URL and start with http:// or https://"
|
"translation": "Site URL must be set, a valid URL, and start with http:// or https://"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "model.config.is_valid.site_url_email_batching.app_error",
|
"id": "model.config.is_valid.site_url_email_batching.app_error",
|
||||||
|
|||||||
@@ -1870,18 +1870,10 @@ func (o *Config) SetDefaults() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *Config) IsValid() *AppError {
|
func (o *Config) IsValid() *AppError {
|
||||||
if len(*o.ServiceSettings.SiteURL) == 0 && *o.EmailSettings.EnableEmailBatching {
|
|
||||||
return NewAppError("Config.IsValid", "model.config.is_valid.site_url_email_batching.app_error", nil, "", http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
if *o.ClusterSettings.Enable && *o.EmailSettings.EnableEmailBatching {
|
if *o.ClusterSettings.Enable && *o.EmailSettings.EnableEmailBatching {
|
||||||
return NewAppError("Config.IsValid", "model.config.is_valid.cluster_email_batching.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Config.IsValid", "model.config.is_valid.cluster_email_batching.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*o.ServiceSettings.SiteURL) == 0 && *o.ServiceSettings.AllowCookiesForSubdomains {
|
|
||||||
return NewAppError("Config.IsValid", "Allowing cookies for subdomains requires SiteURL to be set.", nil, "", http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := o.TeamSettings.isValid(); err != nil {
|
if err := o.TeamSettings.isValid(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -2187,12 +2179,6 @@ func (ss *ServiceSettings) isValid() *AppError {
|
|||||||
return NewAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Config.IsValid", "model.config.is_valid.login_attempts.app_error", nil, "", http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*ss.SiteURL) != 0 {
|
|
||||||
if _, err := url.ParseRequestURI(*ss.SiteURL); err != nil {
|
|
||||||
return NewAppError("Config.IsValid", "model.config.is_valid.site_url.app_error", nil, "", http.StatusBadRequest)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(*ss.WebsocketURL) != 0 {
|
if len(*ss.WebsocketURL) != 0 {
|
||||||
if _, err := url.ParseRequestURI(*ss.WebsocketURL); err != nil {
|
if _, err := url.ParseRequestURI(*ss.WebsocketURL); err != nil {
|
||||||
return NewAppError("Config.IsValid", "model.config.is_valid.websocket_url.app_error", nil, "", http.StatusBadRequest)
|
return NewAppError("Config.IsValid", "model.config.is_valid.websocket_url.app_error", nil, "", http.StatusBadRequest)
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ func TestConfigDefaultFileSettingsS3SSE(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigDefaultSiteURL(t *testing.T) {
|
||||||
|
c1 := Config{}
|
||||||
|
c1.SetDefaults()
|
||||||
|
|
||||||
|
assert.Equal(t, "", *c1.ServiceSettings.SiteURL, "SiteURL should be empty by default.")
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing.T) {
|
func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing.T) {
|
||||||
c1 := Config{}
|
c1 := Config{}
|
||||||
c1.SetDefaults()
|
c1.SetDefaults()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user