Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: uri root path checking #5778

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/pkg/describe/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,10 @@ func (u *accessURI) strings() []string {
protocol = "https://"
}
path := ""
if u.Path != "/" {
Copy link
Contributor

@dannyrandall dannyrandall Apr 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this misses a case with a path with multiple slashes, like ///foo. that should be solved by just changing the else if to an else (or drop the else like this)!

Suggested change
if u.Path != "/" {
path := u.Path
if !strings.HasPrefix(u.Path, "/") {
path = fmt.Sprintf("/%s", u.Path)
}

if !strings.HasPrefix(u.Path, "/") {
path = fmt.Sprintf("/%s", u.Path)
} else if u.Path != "/" {
path = u.Path
}
uris = append(uris, color.HighlightResource(protocol+dnsName+path))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user adds a path without the / prefix, the path variable here will still be "". I think we need to catch this case. Thanks!

}
Expand Down
26 changes: 26 additions & 0 deletions internal/pkg/describe/uri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,18 @@ func TestLBWebServiceURI_String(t *testing.T) {

wanted: "http://jobs.test.phonetool.com",
},
"http with /v2 path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "/v2",

wanted: "http://jobs.test.phonetool.com/v2",
},
"http with non-root path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "v2",

wanted: "http://jobs.test.phonetool.com/v2",
},
"cloudfront": {
accessDNSNames: []string{"abc.cloudfront.net"},
accessPath: "svc",
Expand Down Expand Up @@ -707,6 +719,20 @@ func TestLBWebServiceURI_String(t *testing.T) {

wanted: "https://jobs.test.phonetool.com",
},
"https with /v2 path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "/v2",
accessHTTPS: true,

wanted: "https://jobs.test.phonetool.com/v2",
},
"https with non-root path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "v2",
accessHTTPS: true,

wanted: "https://jobs.test.phonetool.com/v2",
},
}

for name, tc := range testCases {
Expand Down