From 0027d998555d47f9a75a896d8c6c85a8b4645ad0 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Fri, 7 Sep 2018 09:24:18 -0400 Subject: MM-11855 Add App.HTTPService to allow mocking of HTTP client (#9359) * MM-11855 Add App.HTTPService to allow mocking of HTTP client * Initialize HTTPService earlier --- app/app.go | 46 +++++++--------------------------------------- 1 file changed, 7 insertions(+), 39 deletions(-) (limited to 'app/app.go') diff --git a/app/app.go b/app/app.go index 2e0433d23..c3fcc7aec 100644 --- a/app/app.go +++ b/app/app.go @@ -7,12 +7,10 @@ import ( "crypto/ecdsa" "fmt" "html/template" - "net" "net/http" "path" "reflect" "strconv" - "strings" "sync" "sync/atomic" @@ -100,6 +98,8 @@ type App struct { diagnosticId string phase2PermissionsMigrationComplete bool + + HTTPService HTTPService } var appCount = 0 @@ -125,6 +125,9 @@ func New(options ...Option) (outApp *App, outErr error) { clientConfig: make(map[string]string), licenseListeners: map[string]func(){}, } + + app.HTTPService = MakeHTTPService(app) + defer func() { if outErr != nil { app.Shutdown() @@ -285,6 +288,8 @@ func (a *App) Shutdown() { mlog.Info("Server stopped") a.DisableConfigWatch() + + a.HTTPService.Close() } var accountMigrationInterface func(*App) einterfaces.AccountMigrationInterface @@ -505,43 +510,6 @@ func (a *App) HTMLTemplates() *template.Template { return nil } -func (a *App) HTTPClient(trustURLs bool) *http.Client { - insecure := a.Config().ServiceSettings.EnableInsecureOutgoingConnections != nil && *a.Config().ServiceSettings.EnableInsecureOutgoingConnections - - if trustURLs { - return utils.NewHTTPClient(insecure, nil, nil) - } - - allowHost := func(host string) bool { - if a.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { - return false - } - for _, allowed := range strings.Fields(*a.Config().ServiceSettings.AllowedUntrustedInternalConnections) { - if host == allowed { - return true - } - } - return false - } - - allowIP := func(ip net.IP) bool { - if !utils.IsReservedIP(ip) { - return true - } - if a.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { - return false - } - for _, allowed := range strings.Fields(*a.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 (a *App) Handle404(w http.ResponseWriter, r *http.Request) { err := model.NewAppError("Handle404", "api.context.404.app_error", nil, "", http.StatusNotFound) -- cgit v1.2.3-1-g7c22