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.
(cherry picked from commit f85d072c17)
Co-authored-by: Chris Marchbanks <csmarchbanks@gmail.com>
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))
|
|
})
|
|
}
|
|
})
|
|
}
|