Skip to content

Commit 792753b

Browse files
acosta11davewalterPaul Warren
committed
Add documentation and validation for api endpoint
- to prevent users from providing a scheme/protocol Co-authored-by: Dave Walter <[email protected]> Co-authored-by: Paul Warren <[email protected]>
1 parent fa18fe9 commit 792753b

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ include_v3
112112

113113
#### The full set of config parameters is explained below:
114114
##### Required parameters:
115-
* `api`: Cloud Controller API endpoint.
115+
* `api`: Cloud Controller API endpoint, without scheme (HTTP/S) specified.
116116
* `admin_user`: Name of a user in your CF instance with admin credentials. This admin user must have the `doppler.firehose` scope.
117117
* `admin_password`: Password of the admin user above.
118-
* `apps_domain`: A shared domain that tests can use to create subdomains that will route to applications also created in the tests.
118+
* `apps_domain`: A shared domain that tests can use to create subdomains that will route to applications also created in the tests, without scheme (HTTP/S) specified.
119119
* `skip_ssl_validation`: Set to true if using an invalid (e.g. self-signed) cert for traffic routed to your CF instance; this is generally always true for BOSH-Lite deployments of CF.
120120

121121
##### Optional parameters:

helpers/config/config_struct.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,13 @@ func validateApiEndpoint(config *config) error {
467467
return fmt.Errorf("* Invalid configuration: 'api' must be a valid Cloud Controller endpoint but was blank")
468468
}
469469

470+
// Use URL parse to check endpoint, but we do not want users to provide a scheme/protocol
470471
u, err := url.Parse(config.GetApiEndpoint())
471472
if err != nil {
472-
return fmt.Errorf("* Invalid configuration: 'api' must be a valid URL but was set to '%s'", config.GetApiEndpoint())
473+
return fmt.Errorf("* Invalid configuration: 'api' must be a valid domain but was set to '%s'", config.GetApiEndpoint())
474+
}
475+
if u.Scheme != "" {
476+
return fmt.Errorf("* Invalid configuration: 'api' must not contain a scheme/protocol but was set to '%s' in '%s'", u.Scheme, config.GetApiEndpoint())
473477
}
474478

475479
host := u.Host

helpers/config/config_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,19 @@ var _ = Describe("Config", func() {
689689
It("returns an error", func() {
690690
_, err := cfg.NewCatsConfig(tmpFilePath)
691691
Expect(err).To(HaveOccurred())
692-
Expect(err).To(MatchError("* Invalid configuration: 'api' must be a valid URL but was set to '_bogus%%%'"))
692+
Expect(err).To(MatchError("* Invalid configuration: 'api' must be a valid domain but was set to '_bogus%%%'"))
693+
})
694+
})
695+
696+
Context("when the url contains https://", func() {
697+
BeforeEach(func() {
698+
testCfg.ApiEndpoint = ptrToString("https://api.bosh-lite.com")
699+
})
700+
701+
It("returns an error", func() {
702+
_, err := cfg.NewCatsConfig(tmpFilePath)
703+
Expect(err).To(HaveOccurred())
704+
Expect(err).To(MatchError("* Invalid configuration: 'api' must not contain a scheme/protocol but was set to 'https' in 'https://api.bosh-lite.com'"))
693705
})
694706
})
695707

0 commit comments

Comments
 (0)