Ejemplo n.º 1
0
func TestSqlStore1(t *testing.T) {
	utils.LoadConfig("config.json")
	utils.Cfg.SqlSettings.Trace = true

	store := NewSqlStore()
	store.Close()

	utils.LoadConfig("config.json")
}
Ejemplo n.º 2
0
func TestSqlStore3(t *testing.T) {
	defer func() {
		if r := recover(); r == nil {
			t.Fatal("should have been fatal")
		}
	}()

	utils.LoadConfig("config.json")
	utils.Cfg.SqlSettings.DataSource = "missing"
	store = NewSqlStore()

	utils.LoadConfig("config.json")
}
Ejemplo n.º 3
0
func main() {

	pwd, _ := os.Getwd()
	fmt.Println("Current working directory is set to " + pwd)

	var config = flag.String("config", "config.json", "path to config file")
	flag.Parse()

	utils.LoadConfig(*config)
	api.NewServer()
	api.InitApi()
	web.InitWeb()
	api.StartServer()

	// If we allow testing then listen for manual testing URL hits
	if utils.Cfg.ServiceSettings.AllowTesting {
		manualtesting.InitManualTesting()
	}

	// wait for kill signal before attempting to gracefully shutdown
	// the running service
	c := make(chan os.Signal)
	signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
	<-c

	api.StopServer()
}
Ejemplo n.º 4
0
func Setup() *TestHelper {
	if app.Srv == nil {
		utils.TranslationsPreInit()
		utils.LoadConfig("config.json")
		utils.InitTranslations(utils.Cfg.LocalizationSettings)
		utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
		*utils.Cfg.RateLimitSettings.Enable = false
		utils.Cfg.EmailSettings.SendEmailNotifications = true
		utils.Cfg.EmailSettings.SMTPServer = "dockerhost"
		utils.Cfg.EmailSettings.SMTPPort = "2500"
		utils.Cfg.EmailSettings.FeedbackEmail = "*****@*****.**"
		utils.DisableDebugLogForTest()
		app.NewServer()
		app.InitStores()
		InitRouter()
		app.StartServer()
		InitApi()
		utils.EnableDebugLogForTest()
		app.Srv.Store.MarkSystemRanUnitTests()

		*utils.Cfg.TeamSettings.EnableOpenServer = true
	}

	return &TestHelper{}
}
Ejemplo n.º 5
0
func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
	if !c.HasSystemAdminPermissions("getConfig") {
		return
	}

	cfg := model.ConfigFromJson(r.Body)
	if cfg == nil {
		c.SetInvalidParam("saveConfig", "config")
		return
	}

	if len(cfg.ServiceSettings.ListenAddress) == 0 {
		c.SetInvalidParam("saveConfig", "config")
		return
	}

	if cfg.TeamSettings.MaxUsersPerTeam == 0 {
		c.SetInvalidParam("saveConfig", "config")
		return
	}

	// TODO run some cleanup validators

	utils.SaveConfig(utils.CfgFileName, cfg)
	utils.LoadConfig(utils.CfgFileName)
	json := utils.Cfg.ToJson()
	w.Write([]byte(json))
}
Ejemplo n.º 6
0
func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
	if !c.HasSystemAdminPermissions("getConfig") {
		return
	}

	cfg := model.ConfigFromJson(r.Body)
	if cfg == nil {
		c.SetInvalidParam("saveConfig", "config")
		return
	}

	cfg.SetDefaults()
	utils.Desanitize(cfg)

	if err := cfg.IsValid(); err != nil {
		c.Err = err
		return
	}

	if err := utils.ValidateLdapFilter(cfg); err != nil {
		c.Err = err
		return
	}

	c.LogAudit("")

	utils.SaveConfig(utils.CfgFileName, cfg)
	utils.LoadConfig(utils.CfgFileName)

	rdata := map[string]string{}
	rdata["status"] = "OK"
	w.Write([]byte(model.MapToJson(rdata)))
}
Ejemplo n.º 7
0
func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
	if !c.HasSystemAdminPermissions("getConfig") {
		return
	}

	cfg := model.ConfigFromJson(r.Body)
	if cfg == nil {
		c.SetInvalidParam("saveConfig", "config")
		return
	}

	cfg.SetDefaults()

	if err := cfg.IsValid(); err != nil {
		c.Err = err
		return
	}

	c.LogAudit("")

	utils.SaveConfig(utils.CfgFileName, cfg)
	utils.LoadConfig(utils.CfgFileName)
	json := utils.Cfg.ToJson()
	w.Write([]byte(json))
}
Ejemplo n.º 8
0
func Setup() {
	if store == nil {
		utils.LoadConfig("config.json")
		store = NewSqlStore()

		store.MarkSystemRanUnitTests()
	}
}
Ejemplo n.º 9
0
func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) {
	utils.LoadConfig(utils.CfgFileName)

	// start/restart email batching job if necessary
	InitEmailBatching()

	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
	ReturnStatusOK(w)
}
Ejemplo n.º 10
0
func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) {
	if !c.HasSystemAdminPermissions("reloadConfig") {
		return
	}

	utils.LoadConfig(utils.CfgFileName)
	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
	ReturnStatusOK(w)
}
Ejemplo n.º 11
0
func Setup() {
	if Srv == nil {
		utils.LoadConfig("config.json")
		NewServer()
		StartServer()
		InitApi()
		Client = model.NewClient("http://localhost:" + utils.Cfg.ServiceSettings.Port + "/api/v1")
	}
}
Ejemplo n.º 12
0
func main() {

	parseCmds()

	utils.InitTranslations()
	utils.LoadConfig(flagConfigFile)

	if flagRunCmds {
		utils.ConfigureCmdLineLog()
	}

	pwd, _ := os.Getwd()
	l4g.Info(utils.T("mattermost.current_version"), model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash)
	l4g.Info(utils.T("mattermost.entreprise_enabled"), model.BuildEnterpriseReady)
	l4g.Info(utils.T("mattermost.working_dir"), pwd)
	l4g.Info(utils.T("mattermost.config_file"), utils.FindConfigFile(flagConfigFile))

	api.NewServer()
	api.InitApi()
	web.InitWeb()

	if model.BuildEnterpriseReady == "true" {
		api.LoadLicense()
	}

	if !utils.IsLicensed && len(utils.Cfg.SqlSettings.DataSourceReplicas) > 1 {
		l4g.Critical(utils.T("store.sql.read_replicas_not_licensed.critical"))
		time.Sleep(time.Second)
		panic(fmt.Sprintf(utils.T("store.sql.read_replicas_not_licensed.critical")))
	}

	if flagRunCmds {
		runCmds()
	} else {
		api.StartServer()

		// If we allow testing then listen for manual testing URL hits
		if utils.Cfg.ServiceSettings.EnableTesting {
			manualtesting.InitManualTesting()
		}

		setDiagnosticId()
		runSecurityAndDiagnosticsJobAndForget()

		if einterfaces.GetComplianceInterface() != nil {
			einterfaces.GetComplianceInterface().StartComplianceDailyJob()
		}

		// wait for kill signal before attempting to gracefully shutdown
		// the running service
		c := make(chan os.Signal)
		signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
		<-c

		api.StopServer()
	}
}
Ejemplo n.º 13
0
func Setup() {
	if store == nil {
		utils.LoadConfig("config.json")
		utils.InitTranslations(utils.Cfg.LocalizationSettings)
		store = NewSqlStore()

		store.MarkSystemRanUnitTests()
	}
}
Ejemplo n.º 14
0
func doLoadConfig(filename string) (err string) {
	defer func() {
		if r := recover(); r != nil {
			err = r.(string)
		}
	}()
	utils.LoadConfig(filename)
	return ""
}
Ejemplo n.º 15
0
func doLoadConfig(filename string) (err string) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Sprintf("%v", r)
		}
	}()
	utils.LoadConfig(filename)
	return ""
}
Ejemplo n.º 16
0
func Setup() {
	if Srv == nil {
		utils.LoadConfig("config.json")
		utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
		NewServer()
		StartServer()
		InitApi()
		Client = model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)
	}
}
Ejemplo n.º 17
0
func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
	cfg := model.ConfigFromJson(r.Body)
	if cfg == nil {
		c.SetInvalidParam("saveConfig", "config")
		return
	}

	cfg.SetDefaults()
	utils.Desanitize(cfg)

	if err := cfg.IsValid(); err != nil {
		c.Err = err
		return
	}

	if err := utils.ValidateLdapFilter(cfg); err != nil {
		c.Err = err
		return
	}

	if *utils.Cfg.ClusterSettings.Enable {
		c.Err = model.NewLocAppError("saveConfig", "ent.cluster.save_config.error", nil, "")
		return
	}

	c.LogAudit("")

	//oldCfg := utils.Cfg
	utils.SaveConfig(utils.CfgFileName, cfg)
	utils.LoadConfig(utils.CfgFileName)

	if einterfaces.GetMetricsInterface() != nil {
		if *utils.Cfg.MetricsSettings.Enable {
			einterfaces.GetMetricsInterface().StartServer()
		} else {
			einterfaces.GetMetricsInterface().StopServer()
		}
	}

	// Future feature is to sync the configuration files
	// if einterfaces.GetClusterInterface() != nil {
	// 	err := einterfaces.GetClusterInterface().ConfigChanged(cfg, oldCfg, true)
	// 	if err != nil {
	// 		c.Err = err
	// 		return
	// 	}
	// }

	// start/restart email batching job if necessary
	InitEmailBatching()

	rdata := map[string]string{}
	rdata["status"] = "OK"
	w.Write([]byte(model.MapToJson(rdata)))
}
Ejemplo n.º 18
0
func Setup() {
	if api.Srv == nil {
		utils.LoadConfig("config.json")
		api.NewServer()
		api.StartServer()
		api.InitApi()
		InitWeb()
		URL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress
		ApiClient = model.NewClient(URL)
	}
}
Ejemplo n.º 19
0
func Setup() {
	if Srv == nil {
		utils.LoadConfig("config.json")
		utils.InitTranslations()
		utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
		NewServer()
		StartServer()
		InitApi()
		Client = model.NewClient("http://localhost" + utils.Cfg.ServiceSettings.ListenAddress)

		Srv.Store.MarkSystemRanUnitTests()
	}
}
Ejemplo n.º 20
0
func Setup() {
	if api.Srv == nil {
		utils.LoadConfig("config.json")
		utils.InitTranslations()
		api.NewServer()
		api.StartServer()
		api.InitApi()
		InitWeb()
		URL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress
		ApiClient = model.NewClient(URL)

		api.Srv.Store.MarkSystemRanUnitTests()
	}
}
Ejemplo n.º 21
0
func TestRedis(t *testing.T) {
	utils.LoadConfig("config.json")

	c := RedisClient()

	if c == nil {
		t.Fatal("should have a valid redis connection")
	}

	pubsub := c.PubSub()
	defer pubsub.Close()

	m := model.NewMessage(model.NewId(), model.NewId(), model.NewId(), model.ACTION_TYPING)
	m.Add("RootId", model.NewId())

	err := pubsub.Subscribe(m.TeamId)
	if err != nil {
		t.Fatal(err)
	}

	// should be the subscribe success message
	// lets gobble that up
	if _, err := pubsub.Receive(); err != nil {
		t.Fatal(err)
	}

	PublishAndForget(m)

	fmt.Println("here1")

	if msg, err := pubsub.Receive(); err != nil {
		t.Fatal(err)
	} else {

		rmsg := GetMessageFromPayload(msg)

		if m.TeamId != rmsg.TeamId {
			t.Fatal("Ids do not match")
		}

		if m.Props["RootId"] != rmsg.Props["RootId"] {
			t.Fatal("Ids do not match")
		}
	}

	RedisClose()
}
Ejemplo n.º 22
0
func main() {

	parseCmds()

	utils.LoadConfig(flagConfigFile)
	utils.InitTranslations()

	if flagRunCmds {
		utils.ConfigureCmdLineLog()
	}

	pwd, _ := os.Getwd()
	l4g.Info(utils.T("mattermost.current_version"), model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash)
	l4g.Info(utils.T("mattermost.entreprise_enabled"), model.BuildEnterpriseReady)
	l4g.Info(utils.T("mattermost.working_dir"), pwd)
	l4g.Info(utils.T("mattermost.config_file"), utils.FindConfigFile(flagConfigFile))

	api.NewServer()
	api.InitApi()
	web.InitWeb()

	if model.BuildEnterpriseReady == "true" {
		utils.LoadLicense()
	}

	if flagRunCmds {
		runCmds()
	} else {
		api.StartServer()

		// If we allow testing then listen for manual testing URL hits
		if utils.Cfg.ServiceSettings.EnableTesting {
			manualtesting.InitManualTesting()
		}

		setDiagnosticId()
		runSecurityAndDiagnosticsJobAndForget()

		// wait for kill signal before attempting to gracefully shutdown
		// the running service
		c := make(chan os.Signal)
		signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
		<-c

		api.StopServer()
	}
}
Ejemplo n.º 23
0
func Setup() {
	if api.Srv == nil {
		utils.TranslationsPreInit()
		utils.LoadConfig("config.json")
		utils.InitTranslations(utils.Cfg.LocalizationSettings)
		api.NewServer(false)
		api.StartServer()
		api.InitApi()
		InitWeb()
		URL = "http://localhost" + utils.Cfg.ServiceSettings.ListenAddress
		ApiClient = model.NewClient(URL)

		api.Srv.Store.MarkSystemRanUnitTests()

		*utils.Cfg.TeamSettings.EnableOpenServer = true
	}
}
Ejemplo n.º 24
0
func Setup() *TestHelper {
	if Srv == nil {
		utils.LoadConfig("config.json")
		utils.InitTranslations(utils.Cfg.LocalizationSettings)
		utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
		utils.DisableDebugLogForTest()
		NewServer()
		StartServer()
		InitApi()
		utils.EnableDebugLogForTest()
		Srv.Store.MarkSystemRanUnitTests()

		*utils.Cfg.TeamSettings.EnableOpenServer = true
	}

	return &TestHelper{}
}
Ejemplo n.º 25
0
func main() {

	parseCmds()

	utils.LoadConfig(flagConfigFile)

	if flagRunCmds {
		utils.ConfigureCmdLineLog()
	}

	pwd, _ := os.Getwd()
	l4g.Info("Current version is %v (%v/%v/%v)", model.CurrentVersion, model.BuildNumber, model.BuildDate, model.BuildHash)
	l4g.Info("Enterprise Enabled: %t", model.BuildEnterpriseReady)
	l4g.Info("Current working directory is %v", pwd)
	l4g.Info("Loaded config file from %v", utils.FindConfigFile(flagConfigFile))

	api.NewServer()
	api.InitApi()
	web.InitWeb()

	utils.LoadLicense()

	if flagRunCmds {
		runCmds()
	} else {
		api.StartServer()

		// If we allow testing then listen for manual testing URL hits
		if utils.Cfg.ServiceSettings.EnableTesting {
			manualtesting.InitManualTesting()
		}

		setDiagnosticId()
		runSecurityAndDiagnosticsJobAndForget()

		// wait for kill signal before attempting to gracefully shutdown
		// the running service
		c := make(chan os.Signal)
		signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
		<-c

		api.StopServer()
	}
}
Ejemplo n.º 26
0
func SetupEnterprise() *TestHelper {
	if Srv == nil {
		utils.LoadConfig("config.json")
		utils.InitTranslations()
		utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
		utils.DisableDebugLogForTest()
		utils.License.Features.SetDefaults()
		NewServer()
		StartServer()
		utils.InitHTML()
		InitApi()
		utils.EnableDebugLogForTest()
		Srv.Store.MarkSystemRanUnitTests()

		*utils.Cfg.TeamSettings.EnableOpenServer = true
	}

	return &TestHelper{}
}
Ejemplo n.º 27
0
func SetupEnterprise() *TestHelper {
	if app.Srv == nil {
		utils.TranslationsPreInit()
		utils.LoadConfig("config.json")
		utils.InitTranslations(utils.Cfg.LocalizationSettings)
		utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
		*utils.Cfg.RateLimitSettings.Enable = false
		utils.DisableDebugLogForTest()
		utils.License.Features.SetDefaults()
		app.NewServer()
		app.InitStores()
		InitRouter()
		app.StartServer()
		utils.InitHTML()
		InitApi()
		utils.EnableDebugLogForTest()
		app.Srv.Store.MarkSystemRanUnitTests()

		*utils.Cfg.TeamSettings.EnableOpenServer = true
	}

	return &TestHelper{}
}
Ejemplo n.º 28
0
func main() {

	parseCmds()

	utils.LoadConfig(flagConfigFile)

	if flagRunCmds {
		utils.ConfigureCmdLineLog()
	}

	pwd, _ := os.Getwd()
	l4g.Info("Current working directory is %v", pwd)
	l4g.Info("Loaded config file from %v", utils.FindConfigFile(flagConfigFile))

	api.NewServer()
	api.InitApi()
	web.InitWeb()

	if flagRunCmds {
		runCmds()
	} else {
		api.StartServer()

		// If we allow testing then listen for manual testing URL hits
		if utils.Cfg.ServiceSettings.AllowTesting {
			manualtesting.InitManualTesting()
		}

		// wait for kill signal before attempting to gracefully shutdown
		// the running service
		c := make(chan os.Signal)
		signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
		<-c

		api.StopServer()
	}
}
Ejemplo n.º 29
0
func Setup() {
	if store == nil {
		utils.LoadConfig("config.json")
		store = NewSqlStore()
	}
}