Skip to content

Commit

Permalink
Merge 4cca772 into 844ba7c
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Mar 9, 2017
2 parents 844ba7c + 4cca772 commit e4fdaef
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
15 changes: 15 additions & 0 deletions api4/system.go
Expand Up @@ -7,15 +7,30 @@ import (
"net/http"

l4g "github.com/alecthomas/log4go"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)

func InitSystem() {
l4g.Debug(utils.T("api.system.init.debug"))

BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET")
BaseRoutes.ApiRoot.Handle("/config", ApiSessionRequired(getConfig)).Methods("GET")
}

func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
ReturnStatusOK(w)
}

func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}

cfg := app.GetConfig()

w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Write([]byte(cfg.ToJson()))
}
50 changes: 49 additions & 1 deletion api4/system_test.go
@@ -1,7 +1,10 @@
package api4

import (
"strings"
"testing"

"github.com/mattermost/platform/model"
)

func TestGetPing(t *testing.T) {
Expand All @@ -10,9 +13,54 @@ func TestGetPing(t *testing.T) {
Client := th.Client

b, _ := Client.GetPing()
if b == false {
if b == false {
t.Fatal()
}
}

func TestGetConfig(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
Client := th.Client

_, resp := Client.GetConfig()
CheckForbiddenStatus(t, resp)

cfg, resp := th.SystemAdminClient.GetConfig()
CheckNoError(t, resp)

if len(cfg.TeamSettings.SiteName) == 0 {
t.Fatal()
}

if *cfg.LdapSettings.BindPassword != model.FAKE_SETTING && len(*cfg.LdapSettings.BindPassword) != 0 {
t.Fatal("did not sanitize properly")
}
if *cfg.FileSettings.PublicLinkSalt != model.FAKE_SETTING {
t.Fatal("did not sanitize properly")
}
if cfg.FileSettings.AmazonS3SecretAccessKey != model.FAKE_SETTING && len(cfg.FileSettings.AmazonS3SecretAccessKey) != 0 {
t.Fatal("did not sanitize properly")
}
if cfg.EmailSettings.InviteSalt != model.FAKE_SETTING {
t.Fatal("did not sanitize properly")
}
if cfg.EmailSettings.PasswordResetSalt != model.FAKE_SETTING {
t.Fatal("did not sanitize properly")
}
if cfg.EmailSettings.SMTPPassword != model.FAKE_SETTING && len(cfg.EmailSettings.SMTPPassword) != 0 {
t.Fatal("did not sanitize properly")
}
if cfg.GitLabSettings.Secret != model.FAKE_SETTING && len(cfg.GitLabSettings.Secret) != 0 {
t.Fatal("did not sanitize properly")
}
if cfg.SqlSettings.DataSource != model.FAKE_SETTING {
t.Fatal("did not sanitize properly")
}
if cfg.SqlSettings.AtRestEncryptKey != model.FAKE_SETTING {
t.Fatal("did not sanitize properly")
}
if !strings.Contains(strings.Join(cfg.SqlSettings.DataSourceReplicas, " "), model.FAKE_SETTING) && len(cfg.SqlSettings.DataSourceReplicas) != 0 {
t.Fatal("did not sanitize properly")
}
}
14 changes: 14 additions & 0 deletions model/client4.go
Expand Up @@ -122,6 +122,10 @@ func (c *Client4) GetPostsRoute() string {
return fmt.Sprintf("/posts")
}

func (c *Client4) GetConfigRoute() string {
return fmt.Sprintf("/config")
}

func (c *Client4) GetPostRoute(postId string) string {
return fmt.Sprintf(c.GetPostsRoute()+"/%v", postId)
}
Expand Down Expand Up @@ -925,6 +929,16 @@ func (c *Client4) GetPing() (bool, *Response) {
}
}

// GetConfig will retrieve the server config with some sanitized items.
func (c *Client4) GetConfig() (*Config, *Response) {
if r, err := c.DoApiGet(c.GetConfigRoute(), ""); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return ConfigFromJson(r.Body), BuildResponse(r)
}
}

// Webhooks Section

// CreateIncomingWebhook creates an incoming webhook for a channel.
Expand Down

0 comments on commit e4fdaef

Please sign in to comment.