mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Adding APIs to reload config, recycle db connections and ping server (#3096)
* Adding APIs to reload config, recycle db connections and ping server * Fixing unit test * Adding unit tests
This commit is contained in:
61
api/admin.go
61
api/admin.go
@@ -10,11 +10,13 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/store"
|
||||
"github.com/mattermost/platform/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
)
|
||||
@@ -26,9 +28,9 @@ func InitAdmin() {
|
||||
BaseRoutes.Admin.Handle("/audits", ApiUserRequired(getAllAudits)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/config", ApiUserRequired(getConfig)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/save_config", ApiUserRequired(saveConfig)).Methods("POST")
|
||||
BaseRoutes.Admin.Handle("/reload_config", ApiUserRequired(reloadConfig)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/test_email", ApiUserRequired(testEmail)).Methods("POST")
|
||||
BaseRoutes.Admin.Handle("/client_props", ApiAppHandler(getClientConfig)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/log_client", ApiAppHandler(logClient)).Methods("POST")
|
||||
BaseRoutes.Admin.Handle("/recycle_db_conn", ApiUserRequired(recycleDatabaseConnection)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/analytics/{id:[A-Za-z0-9]+}/{name:[A-Za-z0-9_]+}", ApiUserRequired(getAnalytics)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/analytics/{name:[A-Za-z0-9_]+}", ApiUserRequired(getAnalytics)).Methods("GET")
|
||||
BaseRoutes.Admin.Handle("/save_compliance_report", ApiUserRequired(saveComplianceReport)).Methods("POST")
|
||||
@@ -94,32 +96,6 @@ func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.MapToJson(utils.ClientCfg)))
|
||||
}
|
||||
|
||||
func logClient(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m := model.MapFromJson(r.Body)
|
||||
|
||||
lvl := m["level"]
|
||||
msg := m["message"]
|
||||
|
||||
if len(msg) > 400 {
|
||||
msg = msg[0:399]
|
||||
}
|
||||
|
||||
if lvl == "ERROR" {
|
||||
err := &model.AppError{}
|
||||
err.Message = msg
|
||||
err.Where = "client"
|
||||
c.LogError(err)
|
||||
}
|
||||
|
||||
rm := make(map[string]string)
|
||||
rm["SUCCESS"] = "true"
|
||||
w.Write([]byte(model.MapToJson(rm)))
|
||||
}
|
||||
|
||||
func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.HasSystemAdminPermissions("getConfig") {
|
||||
return
|
||||
@@ -134,6 +110,16 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.HasSystemAdminPermissions("getConfig") {
|
||||
return
|
||||
@@ -168,6 +154,25 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.MapToJson(rdata)))
|
||||
}
|
||||
|
||||
func recycleDatabaseConnection(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.HasSystemAdminPermissions("recycleDatabaseConnection") {
|
||||
return
|
||||
}
|
||||
|
||||
oldStore := Srv.Store
|
||||
|
||||
l4g.Warn(utils.T("api.admin.recycle_db_start.warn"))
|
||||
Srv.Store = store.NewSqlStore()
|
||||
|
||||
time.Sleep(20 * time.Second)
|
||||
oldStore.Close()
|
||||
|
||||
l4g.Warn(utils.T("api.admin.recycle_db_end.warn"))
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if !c.HasSystemAdminPermissions("testEmail") {
|
||||
return
|
||||
|
||||
@@ -39,20 +39,6 @@ func TestGetAllAudits(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetClientProperties(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if result, err := th.BasicClient.GetClientProperties(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
props := result.Data.(map[string]string)
|
||||
|
||||
if len(props["Version"]) == 0 {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetConfig(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
|
||||
@@ -102,6 +88,21 @@ func TestGetConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReloadConfig(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
|
||||
if _, err := th.BasicClient.ReloadConfig(); err == nil {
|
||||
t.Fatal("Shouldn't have permissions")
|
||||
}
|
||||
|
||||
if _, err := th.SystemAdminClient.ReloadConfig(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
func TestSaveConfig(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
|
||||
@@ -118,6 +119,18 @@ func TestSaveConfig(t *testing.T) {
|
||||
*utils.Cfg.TeamSettings.EnableOpenServer = true
|
||||
}
|
||||
|
||||
func TestRecycleDatabaseConnection(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
|
||||
if _, err := th.BasicClient.RecycleDatabaseConnection(); err == nil {
|
||||
t.Fatal("Shouldn't have permissions")
|
||||
}
|
||||
|
||||
if _, err := th.SystemAdminClient.RecycleDatabaseConnection(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmailTest(t *testing.T) {
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
|
||||
|
||||
10
api/api.go
10
api/api.go
@@ -40,6 +40,8 @@ type Routes struct {
|
||||
|
||||
Admin *mux.Router // 'api/v3/admin'
|
||||
|
||||
General *mux.Router // 'api/v3/general'
|
||||
|
||||
Preferences *mux.Router // 'api/v3/preferences'
|
||||
|
||||
License *mux.Router // 'api/v3/license'
|
||||
@@ -67,6 +69,7 @@ func InitApi() {
|
||||
BaseRoutes.Hooks = BaseRoutes.NeedTeam.PathPrefix("/hooks").Subrouter()
|
||||
BaseRoutes.OAuth = BaseRoutes.ApiRoot.PathPrefix("/oauth").Subrouter()
|
||||
BaseRoutes.Admin = BaseRoutes.ApiRoot.PathPrefix("/admin").Subrouter()
|
||||
BaseRoutes.General = BaseRoutes.ApiRoot.PathPrefix("/general").Subrouter()
|
||||
BaseRoutes.Preferences = BaseRoutes.ApiRoot.PathPrefix("/preferences").Subrouter()
|
||||
BaseRoutes.License = BaseRoutes.ApiRoot.PathPrefix("/license").Subrouter()
|
||||
BaseRoutes.Public = BaseRoutes.ApiRoot.PathPrefix("/public").Subrouter()
|
||||
@@ -79,6 +82,7 @@ func InitApi() {
|
||||
InitFile()
|
||||
InitCommand()
|
||||
InitAdmin()
|
||||
InitGeneral()
|
||||
InitOAuth()
|
||||
InitWebhook()
|
||||
InitPreference()
|
||||
@@ -100,3 +104,9 @@ func HandleEtag(etag string, w http.ResponseWriter, r *http.Request) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func ReturnStatusOK(w http.ResponseWriter) {
|
||||
m := make(map[string]string)
|
||||
m[model.STATUS] = model.STATUS_OK
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
}
|
||||
|
||||
56
api/general.go
Normal file
56
api/general.go
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
|
||||
"github.com/mattermost/platform/model"
|
||||
"github.com/mattermost/platform/utils"
|
||||
)
|
||||
|
||||
func InitGeneral() {
|
||||
l4g.Debug(utils.T("api.general.init.debug"))
|
||||
|
||||
BaseRoutes.General.Handle("/client_props", ApiAppHandler(getClientConfig)).Methods("GET")
|
||||
BaseRoutes.General.Handle("/log_client", ApiAppHandler(logClient)).Methods("POST")
|
||||
BaseRoutes.General.Handle("/ping", ApiAppHandler(ping)).Methods("GET")
|
||||
|
||||
}
|
||||
|
||||
func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.MapToJson(utils.ClientCfg)))
|
||||
}
|
||||
|
||||
func logClient(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m := model.MapFromJson(r.Body)
|
||||
|
||||
lvl := m["level"]
|
||||
msg := m["message"]
|
||||
|
||||
if len(msg) > 400 {
|
||||
msg = msg[0:399]
|
||||
}
|
||||
|
||||
if lvl == "ERROR" {
|
||||
err := &model.AppError{}
|
||||
err.Message = msg
|
||||
err.Id = msg
|
||||
err.Where = "client"
|
||||
c.LogError(err)
|
||||
}
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func ping(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
m := make(map[string]string)
|
||||
m["version"] = model.CurrentVersion
|
||||
m["server_time"] = fmt.Sprintf("%v", model.GetMillis())
|
||||
m["node_id"] = ""
|
||||
w.Write([]byte(model.MapToJson(m)))
|
||||
}
|
||||
40
api/general_test.go
Normal file
40
api/general_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetClientProperties(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if props, err := th.BasicClient.GetClientProperties(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if len(props["Version"]) == 0 {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLogClient(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if ret, _ := th.BasicClient.LogClient("this is a test"); !ret {
|
||||
t.Fatal("failed to log")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPing(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
if m, err := th.BasicClient.GetPing(); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if len(m["version"]) == 0 {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
}
|
||||
12
i18n/en.json
12
i18n/en.json
@@ -47,6 +47,10 @@
|
||||
"id": "September",
|
||||
"translation": "September"
|
||||
},
|
||||
{
|
||||
"id": "api.general.init.debug",
|
||||
"translation": "Initializing general api routes"
|
||||
},
|
||||
{
|
||||
"id": "api.admin.file_read_error",
|
||||
"translation": "Error reading log file"
|
||||
@@ -63,6 +67,14 @@
|
||||
"id": "api.admin.init.debug",
|
||||
"translation": "Initializing admin api routes"
|
||||
},
|
||||
{
|
||||
"id": "api.admin.recycle_db_start.warn",
|
||||
"translation": "Attempting to recycle the database connection"
|
||||
},
|
||||
{
|
||||
"id": "api.admin.recycle_db_end.warn",
|
||||
"translation": "Finished recycling the database connection"
|
||||
},
|
||||
{
|
||||
"id": "api.admin.test_email.body",
|
||||
"translation": "<br/><br/><br/>It appears your Mattermost email is setup correctly!"
|
||||
|
||||
130
model/client.go
130
model/client.go
@@ -28,6 +28,8 @@ const (
|
||||
HEADER_AUTH = "Authorization"
|
||||
HEADER_REQUESTED_WITH = "X-Requested-With"
|
||||
HEADER_REQUESTED_WITH_XML = "XMLHttpRequest"
|
||||
STATUS = "status"
|
||||
STATUS_OK = "OK"
|
||||
|
||||
API_URL_SUFFIX_V1 = "/api/v1"
|
||||
API_URL_SUFFIX_V3 = "/api/v3"
|
||||
@@ -41,18 +43,21 @@ type Result struct {
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
Url string // The location of the server like "http://localhost:8065"
|
||||
ApiUrl string // The api location of the server like "http://localhost:8065/api/v3"
|
||||
HttpClient *http.Client // The http client
|
||||
AuthToken string
|
||||
AuthType string
|
||||
TeamId string
|
||||
Url string // The location of the server like "http://localhost:8065"
|
||||
ApiUrl string // The api location of the server like "http://localhost:8065/api/v3"
|
||||
HttpClient *http.Client // The http client
|
||||
AuthToken string
|
||||
AuthType string
|
||||
TeamId string
|
||||
RequestId string
|
||||
Etag string
|
||||
ServerVersion string
|
||||
}
|
||||
|
||||
// NewClient constructs a new client with convienence methods for talking to
|
||||
// the server.
|
||||
func NewClient(url string) *Client {
|
||||
return &Client{url, url + API_URL_SUFFIX, &http.Client{}, "", "", ""}
|
||||
return &Client{url, url + API_URL_SUFFIX, &http.Client{}, "", "", "", "", "", ""}
|
||||
}
|
||||
|
||||
func (c *Client) SetOAuthToken(token string) {
|
||||
@@ -94,6 +99,10 @@ func (c *Client) GetChannelNameRoute(channelName string) string {
|
||||
return fmt.Sprintf("/teams/%v/channels/name/%v", c.GetTeamId(), channelName)
|
||||
}
|
||||
|
||||
func (c *Client) GetGeneralRoute() string {
|
||||
return "/general"
|
||||
}
|
||||
|
||||
func (c *Client) DoPost(url, data, contentType string) (*http.Response, *AppError) {
|
||||
rq, _ := http.NewRequest("POST", c.Url+url, strings.NewReader(data))
|
||||
rq.Header.Set("Content-Type", contentType)
|
||||
@@ -155,6 +164,7 @@ func getCookie(name string, resp *http.Response) *http.Cookie {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Must is a convenience function used for testing.
|
||||
func (c *Client) Must(result *Result, err *AppError) *Result {
|
||||
if err != nil {
|
||||
l4g.Close()
|
||||
@@ -165,6 +175,76 @@ func (c *Client) Must(result *Result, err *AppError) *Result {
|
||||
return result
|
||||
}
|
||||
|
||||
// CheckStatusOK is a convenience function for checking the return of Web Service
|
||||
// call that return the a map of status=OK.
|
||||
func (c *Client) CheckStatusOK(r *http.Response) bool {
|
||||
m := MapFromJson(r.Body)
|
||||
if m != nil && m[STATUS] == STATUS_OK {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *Client) fillInExtraProperties(r *http.Response) {
|
||||
c.RequestId = r.Header.Get(HEADER_REQUEST_ID)
|
||||
c.Etag = r.Header.Get(HEADER_ETAG_SERVER)
|
||||
c.ServerVersion = r.Header.Get(HEADER_VERSION_ID)
|
||||
}
|
||||
|
||||
func (c *Client) clearExtraProperties() {
|
||||
c.RequestId = ""
|
||||
c.Etag = ""
|
||||
c.ServerVersion = ""
|
||||
}
|
||||
|
||||
// General Routes Section
|
||||
|
||||
// GetClientProperties returns properties needed by the client to show/hide
|
||||
// certian features. It returns a map of strings.
|
||||
func (c *Client) GetClientProperties() (map[string]string, *AppError) {
|
||||
c.clearExtraProperties()
|
||||
if r, err := c.DoApiGet(c.GetGeneralRoute()+"/client_props", "", ""); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
c.fillInExtraProperties(r)
|
||||
return MapFromJson(r.Body), nil
|
||||
}
|
||||
}
|
||||
|
||||
// LogClient is a convenience Web Service call so clients can log messages into
|
||||
// the server-side logs. For example we typically log javascript error messages
|
||||
// into the server-side. It returns true if the logging was successful.
|
||||
func (c *Client) LogClient(message string) (bool, *AppError) {
|
||||
c.clearExtraProperties()
|
||||
m := make(map[string]string)
|
||||
m["level"] = "ERROR"
|
||||
m["message"] = message
|
||||
|
||||
if r, err := c.DoApiPost(c.GetGeneralRoute()+"/log_client", MapToJson(m)); err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
c.fillInExtraProperties(r)
|
||||
return c.CheckStatusOK(r), nil
|
||||
}
|
||||
}
|
||||
|
||||
// GetPing returns a map of strings with server time, server version, and node Id.
|
||||
// Systems that want to check on health status of the server should check the
|
||||
// url /api/v3/ping for a 200 status response.
|
||||
func (c *Client) GetPing() (map[string]string, *AppError) {
|
||||
c.clearExtraProperties()
|
||||
if r, err := c.DoApiGet(c.GetGeneralRoute()+"/ping", "", ""); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
c.fillInExtraProperties(r)
|
||||
return MapFromJson(r.Body), nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Team Routes Section
|
||||
|
||||
func (c *Client) SignupTeam(email string, displayName string) (*Result, *AppError) {
|
||||
m := make(map[string]string)
|
||||
m["email"] = email
|
||||
@@ -596,15 +676,6 @@ func (c *Client) GetAllAudits() (*Result, *AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) GetClientProperties() (*Result, *AppError) {
|
||||
if r, err := c.DoApiGet("/admin/client_props", "", ""); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &Result{r.Header.Get(HEADER_REQUEST_ID),
|
||||
r.Header.Get(HEADER_ETAG_SERVER), MapFromJson(r.Body)}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) GetConfig() (*Result, *AppError) {
|
||||
if r, err := c.DoApiGet("/admin/config", "", ""); err != nil {
|
||||
return nil, err
|
||||
@@ -614,6 +685,20 @@ func (c *Client) GetConfig() (*Result, *AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
// ReloadConfig will reload the config.json file from disk. Properties
|
||||
// requiring a server restart will still need a server restart. You must
|
||||
// have the system admin role to call this method. It will return status=OK
|
||||
// if it's successfully reloaded the config file, otherwise check the returned error.
|
||||
func (c *Client) ReloadConfig() (bool, *AppError) {
|
||||
c.clearExtraProperties()
|
||||
if r, err := c.DoApiGet("/admin/reload_config", "", ""); err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
c.fillInExtraProperties(r)
|
||||
return c.CheckStatusOK(r), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) SaveConfig(config *Config) (*Result, *AppError) {
|
||||
if r, err := c.DoApiPost("/admin/save_config", config.ToJson()); err != nil {
|
||||
return nil, err
|
||||
@@ -623,6 +708,19 @@ func (c *Client) SaveConfig(config *Config) (*Result, *AppError) {
|
||||
}
|
||||
}
|
||||
|
||||
// RecycleDatabaseConnection will attempt to recycle the database connections.
|
||||
// You must have the system admin role to call this method. It will return status=OK
|
||||
// if it's successfully recycled the connections, otherwise check the returned error.
|
||||
func (c *Client) RecycleDatabaseConnection() (bool, *AppError) {
|
||||
c.clearExtraProperties()
|
||||
if r, err := c.DoApiGet("/admin/recycle_db_conn", "", ""); err != nil {
|
||||
return false, err
|
||||
} else {
|
||||
c.fillInExtraProperties(r)
|
||||
return c.CheckStatusOK(r), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) TestEmail(config *Config) (*Result, *AppError) {
|
||||
if r, err := c.DoApiPost("/admin/test_email", config.ToJson()); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -112,7 +112,7 @@ function preRenderSetup(callwhendone) {
|
||||
l.message = 'msg: ' + msg + ' row: ' + line + ' col: ' + column + ' stack: ' + stack + ' url: ' + url;
|
||||
|
||||
$.ajax({
|
||||
url: '/api/v3/admin/log_client',
|
||||
url: '/api/v3/general/log_client',
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
type: 'POST',
|
||||
|
||||
295
webapp/tests/client_admin.test.jsx
Normal file
295
webapp/tests/client_admin.test.jsx
Normal file
@@ -0,0 +1,295 @@
|
||||
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
var assert = require('assert');
|
||||
import TestHelper from './test_helper.jsx';
|
||||
|
||||
describe('Client.Admin', function() {
|
||||
this.timeout(10000);
|
||||
|
||||
it('Admin.reloadConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().reloadConfig(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.recycleDatabaseConnection', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().recycleDatabaseConnection(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getComplianceReports', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getComplianceReports(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.saveComplianceReports', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
|
||||
var job = {};
|
||||
job.desc = 'desc';
|
||||
job.emails = '';
|
||||
job.keywords = 'test';
|
||||
job.start_at = new Date();
|
||||
job.end_at = new Date();
|
||||
|
||||
TestHelper.basicClient().saveComplianceReports(
|
||||
job,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getLogs', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getLogs(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getServerAudits', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getServerAudits(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getConfig(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getAnalytics', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getAnalytics(
|
||||
'standard',
|
||||
null,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getTeamAnalytics', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getTeamAnalytics(
|
||||
TestHelper.basicTeam().id,
|
||||
'standard',
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.saveConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
var config = {};
|
||||
config.site_name = 'test';
|
||||
|
||||
TestHelper.basicClient().saveConfig(
|
||||
config,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.testEmail', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
var config = {};
|
||||
config.site_name = 'test';
|
||||
|
||||
TestHelper.basicClient().testEmail(
|
||||
config,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.adminResetMfa', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
|
||||
TestHelper.basicClient().adminResetMfa(
|
||||
TestHelper.basicUser().id,
|
||||
function() {
|
||||
done(new Error('should need a license'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.adminResetPassword', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
var user = TestHelper.basicUser();
|
||||
|
||||
TestHelper.basicClient().resetPassword(
|
||||
user.id,
|
||||
'new_password',
|
||||
function() {
|
||||
throw Error('shouldnt work');
|
||||
},
|
||||
function(err) {
|
||||
// this should fail since you're not a system admin
|
||||
assert.equal(err.id, 'api.context.invalid_param.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('License.getClientLicenceConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().getClientLicenceConfig(
|
||||
function(data) {
|
||||
assert.equal(data.IsLicensed, 'false');
|
||||
done();
|
||||
},
|
||||
function(err) {
|
||||
done(new Error(err.message));
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('License.removeLicenseFile', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().removeLicenseFile(
|
||||
function() {
|
||||
done(new Error('not enabled'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
/*it('License.uploadLicenseFile', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().uploadLicenseFile(
|
||||
'form data',
|
||||
function() {
|
||||
done(new Error('not enabled'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});*/
|
||||
|
||||
// TODO XXX FIX ME - this test depends on make dist
|
||||
|
||||
// it('General.getTranslations', function(done) {
|
||||
// TestHelper.initBasic(() => {
|
||||
// TestHelper.basicClient().getTranslations(
|
||||
// 'http://localhost:8065/static/i18n/es.json',
|
||||
// function(data) {
|
||||
// assert.equal(data['login.or'], 'o');
|
||||
// done();
|
||||
// },
|
||||
// function(err) {
|
||||
// done(new Error(err.message));
|
||||
// }
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import TestHelper from './test_helper.jsx';
|
||||
describe('Client.General', function() {
|
||||
this.timeout(10000);
|
||||
|
||||
it('Admin.getClientConfig', function(done) {
|
||||
it('General.getClientConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().getClientConfig(
|
||||
function(data) {
|
||||
@@ -21,213 +21,11 @@ describe('Client.General', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getComplianceReports', function(done) {
|
||||
it('General.getPing', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getComplianceReports(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.saveComplianceReports', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
|
||||
var job = {};
|
||||
job.desc = 'desc';
|
||||
job.emails = '';
|
||||
job.keywords = 'test';
|
||||
job.start_at = new Date();
|
||||
job.end_at = new Date();
|
||||
|
||||
TestHelper.basicClient().saveComplianceReports(
|
||||
job,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getLogs', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getLogs(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getServerAudits', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getServerAudits(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getConfig(
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getAnalytics', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getAnalytics(
|
||||
'standard',
|
||||
null,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.getTeamAnalytics', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().getTeamAnalytics(
|
||||
TestHelper.basicTeam().id,
|
||||
'standard',
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.saveConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
var config = {};
|
||||
config.site_name = 'test';
|
||||
|
||||
TestHelper.basicClient().saveConfig(
|
||||
config,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.testEmail', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
var config = {};
|
||||
config.site_name = 'test';
|
||||
|
||||
TestHelper.basicClient().testEmail(
|
||||
config,
|
||||
function() {
|
||||
done(new Error('should need system admin permissions'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.system_permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.logClientError', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
var config = {};
|
||||
config.site_name = 'test';
|
||||
TestHelper.basicClient().logClientError('this is a test');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.adminResetMfa', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
|
||||
TestHelper.basicClient().adminResetMfa(
|
||||
TestHelper.basicUser().id,
|
||||
function() {
|
||||
done(new Error('should need a license'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Admin.adminResetPassword', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
var user = TestHelper.basicUser();
|
||||
|
||||
TestHelper.basicClient().resetPassword(
|
||||
user.id,
|
||||
'new_password',
|
||||
function() {
|
||||
throw Error('shouldnt work');
|
||||
},
|
||||
function(err) {
|
||||
// this should fail since you're not a system admin
|
||||
assert.equal(err.id, 'api.context.invalid_param.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('License.getClientLicenceConfig', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().getClientLicenceConfig(
|
||||
TestHelper.basicClient().getPing(
|
||||
function(data) {
|
||||
assert.equal(data.IsLicensed, 'false');
|
||||
assert.equal(data.version.length > 0, true);
|
||||
done();
|
||||
},
|
||||
function(err) {
|
||||
@@ -237,54 +35,15 @@ describe('Client.General', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('License.removeLicenseFile', function(done) {
|
||||
it('General.logClientError', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().removeLicenseFile(
|
||||
function() {
|
||||
done(new Error('not enabled'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
var config = {};
|
||||
config.site_name = 'test';
|
||||
TestHelper.basicClient().logClientError('this is a test');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/*it('License.uploadLicenseFile', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
TestHelper.basicClient().uploadLicenseFile(
|
||||
'form data',
|
||||
function() {
|
||||
done(new Error('not enabled'));
|
||||
},
|
||||
function(err) {
|
||||
assert.equal(err.id, 'api.context.permissions.app_error');
|
||||
done();
|
||||
}
|
||||
);
|
||||
});
|
||||
});*/
|
||||
|
||||
// TODO XXX FIX ME - this test depends on make dist
|
||||
|
||||
// it('General.getTranslations', function(done) {
|
||||
// TestHelper.initBasic(() => {
|
||||
// TestHelper.basicClient().getTranslations(
|
||||
// 'http://localhost:8065/static/i18n/es.json',
|
||||
// function(data) {
|
||||
// assert.equal(data['login.or'], 'o');
|
||||
// done();
|
||||
// },
|
||||
// function(err) {
|
||||
// done(new Error(err.message));
|
||||
// }
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
|
||||
it('File.getFileInfo', function(done) {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error
|
||||
|
||||
@@ -106,7 +106,6 @@ describe('Client.Team', function() {
|
||||
TestHelper.initBasic(() => {
|
||||
TestHelper.basicClient().getAllTeamListings(
|
||||
function(data) {
|
||||
console.log(data);
|
||||
assert.equal(data != null, true);
|
||||
done();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user