MM-58275 Ensure image proxy site URL is updated when that changes (#27214)
* MM-58275 Ensure image proxy site URL is updated when that changes * Check if proxy settings changed using reflection
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
206ff6e697
Коммит
2bcaa42dc0
@@ -7,6 +7,8 @@ import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -115,3 +117,71 @@ func TestGetUnproxiedImageURL(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOnConfigChange(t *testing.T) {
|
||||
t.Run("should switch between backends", func(t *testing.T) {
|
||||
proxy := makeTestAtmosCamoProxy()
|
||||
|
||||
require.Equal(t, "https://mattermost.example.com", proxy.backend.(*AtmosCamoBackend).siteURL.String())
|
||||
|
||||
newConfig := proxy.ConfigService.Config().Clone()
|
||||
newConfig.ImageProxySettings.ImageProxyType = model.NewString(model.ImageProxyTypeLocal)
|
||||
|
||||
proxy.ConfigService.(*testutils.StaticConfigService).UpdateConfig(newConfig)
|
||||
|
||||
require.Equal(t, "https://mattermost.example.com", proxy.backend.(*LocalBackend).baseURL.String())
|
||||
|
||||
newConfig = proxy.ConfigService.Config().Clone()
|
||||
newConfig.ImageProxySettings.ImageProxyType = model.NewString(model.ImageProxyTypeAtmosCamo)
|
||||
|
||||
proxy.ConfigService.(*testutils.StaticConfigService).UpdateConfig(newConfig)
|
||||
|
||||
require.Equal(t, "https://mattermost.example.com", proxy.backend.(*AtmosCamoBackend).siteURL.String())
|
||||
})
|
||||
|
||||
t.Run("for local proxy, should update site URL when that changes", func(t *testing.T) {
|
||||
proxy := makeTestLocalProxy()
|
||||
|
||||
require.Equal(t, "https://mattermost.example.com", proxy.siteURL.String())
|
||||
require.Equal(t, "https://mattermost.example.com", proxy.backend.(*LocalBackend).baseURL.String())
|
||||
|
||||
newConfig := proxy.ConfigService.Config().Clone()
|
||||
newConfig.ServiceSettings.SiteURL = model.NewString("https://new.example.com")
|
||||
|
||||
proxy.ConfigService.(*testutils.StaticConfigService).UpdateConfig(newConfig)
|
||||
|
||||
require.Equal(t, "https://new.example.com", proxy.siteURL.String())
|
||||
require.Equal(t, "https://new.example.com", proxy.backend.(*LocalBackend).baseURL.String())
|
||||
})
|
||||
|
||||
t.Run("for atmos/camo proxy, should update site URL when that changes", func(t *testing.T) {
|
||||
proxy := makeTestAtmosCamoProxy()
|
||||
|
||||
require.Equal(t, "https://mattermost.example.com", proxy.siteURL.String())
|
||||
require.Equal(t, "https://mattermost.example.com", proxy.backend.(*AtmosCamoBackend).siteURL.String())
|
||||
|
||||
newConfig := proxy.ConfigService.Config().Clone()
|
||||
newConfig.ServiceSettings.SiteURL = model.NewString("https://new.example.com")
|
||||
|
||||
proxy.ConfigService.(*testutils.StaticConfigService).UpdateConfig(newConfig)
|
||||
|
||||
require.Equal(t, "https://new.example.com", proxy.siteURL.String())
|
||||
require.Equal(t, "https://new.example.com", proxy.backend.(*AtmosCamoBackend).siteURL.String())
|
||||
})
|
||||
|
||||
t.Run("for atmos/camo proxy, should update additional options when those change", func(t *testing.T) {
|
||||
proxy := makeTestAtmosCamoProxy()
|
||||
|
||||
require.Equal(t, "http://images.example.com", proxy.backend.(*AtmosCamoBackend).remoteURL.String())
|
||||
// require.Equal(t, "7e5f3fab20b94782b43cdb022a66985ef28ba355df2c5d5da3c9a05e4b697bac", proxy.backend.(*AtmosCamoBackend).remoteOptions)
|
||||
|
||||
newConfig := proxy.ConfigService.Config().Clone()
|
||||
newConfig.ImageProxySettings.RemoteImageProxyURL = model.NewString("https://new.example.com")
|
||||
newConfig.ImageProxySettings.RemoteImageProxyOptions = model.NewString("some other random hash")
|
||||
|
||||
proxy.ConfigService.(*testutils.StaticConfigService).UpdateConfig(newConfig)
|
||||
|
||||
require.Equal(t, "https://new.example.com", proxy.backend.(*AtmosCamoBackend).remoteURL.String())
|
||||
// require.Equal(t, "some other random hash", proxy.backend.(*AtmosCamoBackend).remoteOptions)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user