diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2018-09-26 12:42:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-26 12:42:51 -0400 |
commit | 4e59a27293394b6d5529efd13ad711daebbc0eb3 (patch) | |
tree | 51094fc76cfc6295d136e4ebbefbc3cac19c650a /app | |
parent | 15d64fb201848002a25facc3bbffc9535a704df6 (diff) | |
download | chat-4e59a27293394b6d5529efd13ad711daebbc0eb3.tar.gz chat-4e59a27293394b6d5529efd13ad711daebbc0eb3.tar.bz2 chat-4e59a27293394b6d5529efd13ad711daebbc0eb3.zip |
Move HTTPService and ConfigService into services package (#9422)
* Move HTTPService and ConfigService into utils package
* Re-add StaticConfigService
* Move config and http services into their own packages
Diffstat (limited to 'app')
-rw-r--r-- | app/app.go | 5 | ||||
-rw-r--r-- | app/apptestlib.go | 25 | ||||
-rw-r--r-- | app/http_service.go | 67 |
3 files changed, 6 insertions, 91 deletions
diff --git a/app/app.go b/app/app.go index 1c0d56a3c..1cec749da 100644 --- a/app/app.go +++ b/app/app.go @@ -25,6 +25,7 @@ import ( "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/plugin" + "github.com/mattermost/mattermost-server/services/httpservice" "github.com/mattermost/mattermost-server/store" "github.com/mattermost/mattermost-server/store/sqlstore" "github.com/mattermost/mattermost-server/utils" @@ -101,7 +102,7 @@ type App struct { phase2PermissionsMigrationComplete bool - HTTPService HTTPService + HTTPService httpservice.HTTPService } var appCount = 0 @@ -128,7 +129,7 @@ func New(options ...Option) (outApp *App, outErr error) { licenseListeners: map[string]func(){}, } - app.HTTPService = MakeHTTPService(app) + app.HTTPService = httpservice.MakeHTTPService(app) app.CreatePushNotificationsHub() app.StartPushNotificationsHubWorkers() diff --git a/app/apptestlib.go b/app/apptestlib.go index c0d2cfaa2..dcc1fa941 100644 --- a/app/apptestlib.go +++ b/app/apptestlib.go @@ -7,7 +7,6 @@ import ( "io" "io/ioutil" "net/http" - "net/http/httptest" "os" "path/filepath" "time" @@ -21,6 +20,7 @@ import ( "github.com/mattermost/mattermost-server/store/sqlstore" "github.com/mattermost/mattermost-server/store/storetest" "github.com/mattermost/mattermost-server/utils" + "github.com/mattermost/mattermost-server/utils/testutils" ) type TestHelper struct { @@ -36,7 +36,7 @@ type TestHelper struct { tempConfigPath string tempWorkspace string - MockedHTTPService *MockedHTTPService + MockedHTTPService *testutils.MockedHTTPService } type persistentTestStore struct { @@ -168,7 +168,7 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper { } func (me *TestHelper) MockHTTPService(handler http.Handler) *TestHelper { - me.MockedHTTPService = MakeMockedHTTPService(handler) + me.MockedHTTPService = testutils.MakeMockedHTTPService(handler) me.App.HTTPService = me.MockedHTTPService return me @@ -514,22 +514,3 @@ func (me *FakeClusterInterface) sendClearRoleCacheMessage() { Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_ROLES, }) } - -type MockedHTTPService struct { - Server *httptest.Server -} - -func MakeMockedHTTPService(handler http.Handler) *MockedHTTPService { - return &MockedHTTPService{ - Server: httptest.NewServer(handler), - } -} - -func (h *MockedHTTPService) MakeClient(trustURLs bool) *http.Client { - return h.Server.Client() -} - -func (h *MockedHTTPService) Close() { - h.Server.CloseClientConnections() - h.Server.Close() -} diff --git a/app/http_service.go b/app/http_service.go deleted file mode 100644 index 71e72ab2f..000000000 --- a/app/http_service.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package app - -import ( - "net" - "net/http" - "strings" - - "github.com/mattermost/mattermost-server/utils" -) - -// Wraps the functionality for creating a new http.Client to encapsulate that and allow it to be mocked when testing -type HTTPService interface { - MakeClient(trustURLs bool) *http.Client - Close() -} - -type HTTPServiceImpl struct { - app *App -} - -func MakeHTTPService(app *App) HTTPService { - return &HTTPServiceImpl{app} -} - -func (h *HTTPServiceImpl) MakeClient(trustURLs bool) *http.Client { - insecure := h.app.Config().ServiceSettings.EnableInsecureOutgoingConnections != nil && *h.app.Config().ServiceSettings.EnableInsecureOutgoingConnections - - if trustURLs { - return utils.NewHTTPClient(insecure, nil, nil) - } - - allowHost := func(host string) bool { - if h.app.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { - return false - } - for _, allowed := range strings.Fields(*h.app.Config().ServiceSettings.AllowedUntrustedInternalConnections) { - if host == allowed { - return true - } - } - return false - } - - allowIP := func(ip net.IP) bool { - if !utils.IsReservedIP(ip) { - return true - } - if h.app.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { - return false - } - for _, allowed := range strings.Fields(*h.app.Config().ServiceSettings.AllowedUntrustedInternalConnections) { - if _, ipRange, err := net.ParseCIDR(allowed); err == nil && ipRange.Contains(ip) { - return true - } - } - return false - } - - return utils.NewHTTPClient(insecure, allowHost, allowIP) -} - -func (h *HTTPServiceImpl) Close() { - // Does nothing, but allows this to be overridden when mocking the service -} |