package web import ( "fmt" "io" "net/http" "strings" "testing" "github.com/grafana/grafana/pkg/tests/testinfra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) // TestIndexView tests the Grafana index view. func TestIndexView(t *testing.T) { t.Run("CSP enabled", func(t *testing.T) { grafDir, cfgPath := testinfra.CreateGrafDir(t, testinfra.GrafanaOpts{ EnableCSP: true, }) sqlStore := testinfra.SetUpDatabase(t, grafDir) addr := testinfra.StartGrafana(t, grafDir, cfgPath, sqlStore) // nolint:bodyclose resp, html := makeRequest(t, addr) assert.Regexp(t, "script-src 'unsafe-eval' 'strict-dynamic' 'nonce-[^']+';object-src 'none';font-src 'self';style-src 'self' 'unsafe-inline';img-src 'self' data:;base-uri 'self';connect-src 'self' grafana.com;manifest-src 'self';media-src 'none';form-action 'self';", resp.Header.Get("Content-Security-Policy")) assert.Regexp(t, `