From 0432f995ec27de9ee6cc2f5847d4a17fcc095a26 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 18 May 2018 08:37:43 -0700 Subject: MM-9983 Requiring SiteURL to be set. (#8769) * Requiring SiteURL to be set. * Modifying to make tests pass. * Fixing test. --- cmd/mattermost/commands/server.go | 16 +++++++++++++++- cmd/mattermost/commands/server_test.go | 10 +++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'cmd') diff --git a/cmd/mattermost/commands/server.go b/cmd/mattermost/commands/server.go index 9d0e5a917..299005b6a 100644 --- a/cmd/mattermost/commands/server.go +++ b/cmd/mattermost/commands/server.go @@ -6,6 +6,8 @@ package commands import ( "fmt" "net" + "net/http" + "net/url" "os" "os/signal" "syscall" @@ -129,7 +131,19 @@ func runServer(configFileLocation string, disableConfigWatch bool, usedPlatform // Enable developer settings if this is a "dev" build 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) diff --git a/cmd/mattermost/commands/server_test.go b/cmd/mattermost/commands/server_test.go index 0f825e316..a0c7c6948 100644 --- a/cmd/mattermost/commands/server_test.go +++ b/cmd/mattermost/commands/server_test.go @@ -11,6 +11,7 @@ import ( "testing" "github.com/mattermost/mattermost-server/jobs" + "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/utils" "github.com/stretchr/testify/require" ) @@ -20,6 +21,7 @@ type ServerTestHelper struct { disableConfigWatch bool interruptChan chan os.Signal originalInterval int + oldBuildNumber string } func SetupServerTest() *ServerTestHelper { @@ -41,14 +43,20 @@ func SetupServerTest() *ServerTestHelper { interruptChan: interruptChan, originalInterval: originalInterval, } + + // Run in dev mode so SiteURL gets set + th.oldBuildNumber = model.BuildNumber + model.BuildNumber = "dev" + return th } func (th *ServerTestHelper) TearDownServerTest() { jobs.DEFAULT_WATCHER_POLLING_INTERVAL = th.originalInterval + model.BuildNumber = th.oldBuildNumber } -func TestRunServerSuccess(t *testing.T) { +func TestRunServerSiteURL(t *testing.T) { th := SetupServerTest() defer th.TearDownServerTest() -- cgit v1.2.3-1-g7c22 From 88a8703766c422d69d061854269b926c9d3ae4b1 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 18 May 2018 10:34:37 -0700 Subject: Fixing CMD docs. (#8827) --- cmd/mattermost/commands/root.go | 2 +- cmd/mattermost/commands/user.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'cmd') diff --git a/cmd/mattermost/commands/root.go b/cmd/mattermost/commands/root.go index 7ae439161..725f394f6 100644 --- a/cmd/mattermost/commands/root.go +++ b/cmd/mattermost/commands/root.go @@ -15,7 +15,7 @@ func Run(args []string) error { } var RootCmd = &cobra.Command{ - Use: "platform", + Use: "mattermost", Short: "Open source, self-hosted Slack-alternative", Long: `Mattermost offers workplace messaging across web, PC and phones with archiving, search and integration with your existing systems. Documentation available at https://docs.mattermost.com`, } diff --git a/cmd/mattermost/commands/user.go b/cmd/mattermost/commands/user.go index ebcebcce8..373fe7463 100644 --- a/cmd/mattermost/commands/user.go +++ b/cmd/mattermost/commands/user.go @@ -170,7 +170,7 @@ func init() { MigrateAuthCmd.Flags().Bool("auto", false, "Automatically migrate all users. Assumes the usernames and emails are identical between Mattermost and SAML services. (saml only)") MigrateAuthCmd.Flags().Bool("dryRun", false, "Run a simulation of the migration process without changing the database.") MigrateAuthCmd.SetUsageTemplate(`Usage: - platform user migrate_auth [from_auth] [to_auth] [migration-options] [flags] + mattermost user migrate_auth [from_auth] [to_auth] [migration-options] [flags] Examples: {{.Example}} @@ -194,7 +194,7 @@ Global Flags: {{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}} `) MigrateAuthCmd.SetHelpTemplate(`Usage: - platform user migrate_auth [from_auth] [to_auth] [migration-options] [flags] + mattermost user migrate_auth [from_auth] [to_auth] [migration-options] [flags] Examples: {{.Example}} -- cgit v1.2.3-1-g7c22