mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 18:36:30 +02:00
urlutil: improve error message for urls with port in path (#2377)
This commit is contained in:
parent
fbf44261c1
commit
8a74fae2e7
3 changed files with 6 additions and 1 deletions
|
@ -18,6 +18,7 @@ import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/internal/httputil"
|
"github.com/pomerium/pomerium/internal/httputil"
|
||||||
|
"github.com/pomerium/pomerium/internal/urlutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JWTClaimHeaders are headers to add to a request based on IDP claims.
|
// JWTClaimHeaders are headers to add to a request based on IDP claims.
|
||||||
|
@ -215,7 +216,7 @@ func ParseWeightedURL(dst string) (*WeightedURL, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.Parse(to)
|
u, err := urlutil.ParseAndValidateURL(to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", to, err)
|
return nil, fmt.Errorf("%s: %w", to, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ func ParseAndValidateURL(rawurl string) (*url.URL, error) {
|
||||||
}
|
}
|
||||||
u, err := url.Parse(rawurl)
|
u, err := url.Parse(rawurl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "first path segment in URL cannot contain colon") {
|
||||||
|
err = fmt.Errorf("%w, have you specified protocol (ex: https)", err)
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := ValidateURL(u); err != nil {
|
if err := ValidateURL(u); err != nil {
|
||||||
|
|
|
@ -48,6 +48,7 @@ func TestParseAndValidateURL(t *testing.T) {
|
||||||
{"bad hostname", "https://", nil, true},
|
{"bad hostname", "https://", nil, true},
|
||||||
{"bad parse", "https://^", nil, true},
|
{"bad parse", "https://^", nil, true},
|
||||||
{"empty string error", "", nil, true},
|
{"empty string error", "", nil, true},
|
||||||
|
{"path segment", "192.168.0.1:1234/path", nil, true},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue