Skip to content

Commit 147ca37

Browse files
committedAug 1, 2017
Unauthenticated client accepts target without '//'
- When importing an installation or configuring authentication a bare hostname can be provided (defaulting to HTTPS) [#149483797]
1 parent 004557c commit 147ca37

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎network/unauthenticated_client.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"net/http"
88
"net/url"
9+
"strings"
910
"time"
1011
)
1112

@@ -38,7 +39,13 @@ func NewUnauthenticatedClient(target string, insecureSkipVerify bool, requestTim
3839
}
3940

4041
func (c UnauthenticatedClient) Do(request *http.Request) (*http.Response, error) {
41-
targetURL, err := url.Parse(c.target)
42+
43+
candidateURL := c.target
44+
if !strings.Contains(candidateURL, "//") {
45+
candidateURL = fmt.Sprintf("//%s", candidateURL)
46+
}
47+
48+
targetURL, err := url.Parse(candidateURL)
4249
if err != nil {
4350
return nil, fmt.Errorf("could not parse target url: %s", err)
4451
}

‎network/unauthenticated_client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var _ = Describe("UnauthenticatedClient", func() {
6868
Expect(err).NotTo(HaveOccurred())
6969

7070
noScheme.Scheme = ""
71-
finalURL := noScheme.String()
71+
finalURL := strings.Replace(noScheme.String(), "//", "", 1)
7272

7373
client := network.NewUnauthenticatedClient(finalURL, true, time.Duration(30)*time.Second)
7474
Expect(err).NotTo(HaveOccurred())
@@ -89,7 +89,7 @@ var _ = Describe("UnauthenticatedClient", func() {
8989
It("returns an error", func() {
9090
client := network.NewUnauthenticatedClient("%%%", false, time.Duration(30)*time.Second)
9191
_, err := client.Do(&http.Request{})
92-
Expect(err).To(MatchError("could not parse target url: parse %%%: invalid URL escape \"%%%\""))
92+
Expect(err).To(MatchError("could not parse target url: parse //%%%: invalid URL escape \"%%%\""))
9393
})
9494
})
9595

0 commit comments

Comments
 (0)