Datasources: Fix Proxy by UID Failing for UIDs with a Hyphen (#61723)

Fix Proxy by UID Failing for UIDs with a Hyphen

Hyphens are allowed in short IDs but not picked up by the
proxyPathRegexp. This caused the end of the uid to be proxied as part of
the path to the backing datasource which would usually cause a 404.
This commit is contained in:
Chris Marchbanks 2023-01-24 09:15:52 -07:00 committed by GitHub
parent 239d94205a
commit f85d072c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -132,7 +132,7 @@ func (p *DataSourceProxyService) proxyDatasourceRequest(c *models.ReqContext, ds
proxy.HandleRequest() proxy.HandleRequest()
} }
var proxyPathRegexp = regexp.MustCompile(`^\/api\/datasources\/proxy\/([\d]+|uid\/[\w]+)\/?`) var proxyPathRegexp = regexp.MustCompile(`^\/api\/datasources\/proxy\/([\d]+|uid\/[\w-]+)\/?`)
func extractProxyPath(originalRawPath string) string { func extractProxyPath(originalRawPath string) string {
return proxyPathRegexp.ReplaceAllString(originalRawPath, "") return proxyPathRegexp.ReplaceAllString(originalRawPath, "")

View File

@ -32,6 +32,14 @@ func TestDataProxy(t *testing.T) {
"/api/datasources/proxy/uid/26MI0wZ7k/some/thing", "/api/datasources/proxy/uid/26MI0wZ7k/some/thing",
"some/thing", "some/thing",
}, },
{
"/api/datasources/proxy/uid/pUWo-no4k/search",
"search",
},
{
"/api/datasources/proxy/uid/pUWo_no4k/search",
"search",
},
{ {
"/api/datasources/proxy/uid/26MI0wZ7k/api/services/afsd%2Fafsd/operations", "/api/datasources/proxy/uid/26MI0wZ7k/api/services/afsd%2Fafsd/operations",
"api/services/afsd%2Fafsd/operations", "api/services/afsd%2Fafsd/operations",