mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 02:40:26 -06:00
f85d072c17
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.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package datasourceproxy
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDataProxy(t *testing.T) {
|
|
t.Run("extractProxyPath", func(t *testing.T) {
|
|
testCases := []struct {
|
|
originalRawPath string
|
|
exp string
|
|
}{
|
|
{
|
|
"/api/datasources/proxy/1",
|
|
"",
|
|
},
|
|
{
|
|
"/api/datasources/proxy/1/some/thing",
|
|
"some/thing",
|
|
},
|
|
{
|
|
"/api/datasources/proxy/54/api/services/afsd%2Fafsd/operations",
|
|
"api/services/afsd%2Fafsd/operations",
|
|
},
|
|
{
|
|
"/api/datasources/proxy/uid/26MI0wZ7k",
|
|
"",
|
|
},
|
|
{
|
|
"/api/datasources/proxy/uid/26MI0wZ7k/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/services/afsd%2Fafsd/operations",
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
t.Run("Given raw path, should extract expected proxy path", func(t *testing.T) {
|
|
assert.Equal(t, tc.exp, extractProxyPath(tc.originalRawPath))
|
|
})
|
|
}
|
|
})
|
|
}
|