Skip to content

Commit b66cf70

Browse files
tylerschultzzaksoup
authored andcommitted
Reinstate "Provide path to uaa client""
This reverts commit 3e04b06. Signed-off-by: Zachary Auerbach <zauerbach@pivotal.io>
1 parent 3e04b06 commit b66cf70

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

uaa/factory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (f Factory) httpClient(config Config) (Client, error) {
5656
Scheme: "https",
5757
Host: fmt.Sprintf("%s:%d", config.Host, config.Port),
5858
User: url.UserPassword(config.Client, config.ClientSecret),
59+
Path: config.Path,
5960
}
6061

6162
return NewClient(endpoint.String(), httpClient, f.logger), nil

uaa/factory_config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
type Config struct {
1515
Host string
1616
Port int
17+
Path string
1718

1819
Client string
1920
ClientSecret string
@@ -33,9 +34,11 @@ func NewConfigFromURL(url string) (Config, error) {
3334

3435
host := parsedURL.Host
3536
port := 443
37+
path := parsedURL.Path
3638

3739
if len(host) == 0 {
3840
host = url
41+
path = ""
3942
}
4043

4144
if strings.Contains(host, ":") {
@@ -58,7 +61,7 @@ func NewConfigFromURL(url string) (Config, error) {
5861
return Config{}, bosherr.Errorf("Expected to extract host from URL '%s'", url)
5962
}
6063

61-
return Config{Host: host, Port: port}, nil
64+
return Config{Host: host, Port: port, Path: path}, nil
6265
}
6366

6467
func (c Config) Validate() error {

uaa/factory_config_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ var _ = Describe("NewConfigFromURL", func() {
3232
Expect(config).To(Equal(Config{Host: "host", Port: 4443}))
3333
})
3434

35+
It("extracts path if path is provided", func() {
36+
config, err := NewConfigFromURL("httsp://host:4443/zakrules")
37+
Expect(err).ToNot(HaveOccurred())
38+
Expect(config).To(Equal(Config{Host: "host", Port: 4443, Path: "/zakrules"}))
39+
})
40+
3541
It("returns error if url is empty", func() {
3642
_, err := NewConfigFromURL("")
3743
Expect(err).To(HaveOccurred())

uaa/factory_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package uaa_test
22

33
import (
44
"crypto/tls"
5+
"fmt"
56
"net/http"
67

78
boshlog "github.com/cloudfoundry/bosh-utils/logger"
@@ -74,5 +75,44 @@ var _ = Describe("Factory", func() {
7475
_, err = uaa.ClientCredentialsGrant()
7576
Expect(err).ToNot(HaveOccurred())
7677
})
78+
79+
Context("when the server url has a context path", func() {
80+
It("properly follows that path", func() {
81+
server := ghttp.NewUnstartedServer()
82+
83+
cert, err := tls.X509KeyPair(validCert, validKey)
84+
Expect(err).ToNot(HaveOccurred())
85+
86+
server.HTTPTestServer.TLS = &tls.Config{
87+
Certificates: []tls.Certificate{cert},
88+
}
89+
90+
server.HTTPTestServer.StartTLS()
91+
92+
config, err := NewConfigFromURL(fmt.Sprintf("%s/test_path", server.URL()))
93+
Expect(err).ToNot(HaveOccurred())
94+
95+
config.Client = "client"
96+
config.ClientSecret = "client-secret"
97+
config.CACert = validCACert
98+
99+
logger := boshlog.NewLogger(boshlog.LevelNone)
100+
101+
uaa, err := NewFactory(logger).New(config)
102+
Expect(err).ToNot(HaveOccurred())
103+
104+
server.AppendHandlers(
105+
ghttp.CombineHandlers(
106+
ghttp.VerifyRequest("POST", "/test_path/oauth/token", "grant_type=client_credentials"),
107+
ghttp.VerifyBasicAuth("client", "client-secret"),
108+
ghttp.RespondWith(http.StatusOK, `{}`),
109+
),
110+
)
111+
112+
_, err = uaa.ClientCredentialsGrant()
113+
Expect(err).ToNot(HaveOccurred())
114+
115+
})
116+
})
77117
})
78118
})

0 commit comments

Comments
 (0)