[v9.4.x] Plugins: Fix Cache-Control header response for public/plugins/* assets API (#64255)

resolve conflicts
This commit is contained in:
Will Browne
2023-03-06 18:20:54 +00:00
committed by GitHub
parent 5a6471c01f
commit 2d0324ec70
2 changed files with 54 additions and 1 deletions
+52
View File
@@ -19,6 +19,7 @@ import (
"github.com/grafana/grafana/pkg/services/sqlstore"
"github.com/grafana/grafana/pkg/services/user"
"github.com/grafana/grafana/pkg/services/user/userimpl"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tests/testinfra"
)
@@ -116,6 +117,57 @@ func TestIntegrationPlugins(t *testing.T) {
})
}
func TestIntegrationPluginAssets(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
type testCase struct {
desc string
url string
env string
expStatus int
expCacheControl string
}
t.Run("Assets", func(t *testing.T) {
testCases := []testCase{
{
desc: "should return no-cache settings for Dev env",
env: setting.Dev,
url: "http://%s/public/plugins/testdata/img/testdata.svg",
expStatus: http.StatusOK,
expCacheControl: "max-age=0, must-revalidate, no-cache",
},
{
desc: "should return cache settings for Prod env",
env: setting.Prod,
url: "http://%s/public/plugins/testdata/img/testdata.svg",
expStatus: http.StatusOK,
expCacheControl: "public, max-age=3600",
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
dir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{
AppModeProduction: tc.env == setting.Prod,
})
grafanaListedAddr, _ := testinfra.StartGrafana(t, dir, cfgPath)
url := fmt.Sprintf(tc.url, grafanaListedAddr)
// nolint:gosec
resp, err := http.Get(url)
t.Cleanup(func() {
require.NoError(t, resp.Body.Close())
})
require.NoError(t, err)
require.Equal(t, tc.expStatus, resp.StatusCode)
require.Equal(t, tc.expCacheControl, resp.Header.Get("Cache-Control"))
})
}
})
}
func createUser(t *testing.T, store *sqlstore.SQLStore, cmd user.CreateUserCommand) {
t.Helper()