grafana/pkg/services/datasourceproxy/datasourceproxy_test.go
Chris Marchbanks f85d072c17
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.
2023-01-24 17:15:52 +01:00

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))
})
}
})
}