Skip to content

Commit

Permalink
Add documentation and validation for api endpoint
Browse files Browse the repository at this point in the history
- to prevent users from providing a scheme/protocol

Co-authored-by: Dave Walter <[email protected]>
Co-authored-by: Paul Warren <[email protected]>
  • Loading branch information
3 people committed Sep 25, 2020
1 parent fa18fe9 commit 792753b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ include_v3

#### The full set of config parameters is explained below:
##### Required parameters:
* `api`: Cloud Controller API endpoint.
* `api`: Cloud Controller API endpoint, without scheme (HTTP/S) specified.
* `admin_user`: Name of a user in your CF instance with admin credentials. This admin user must have the `doppler.firehose` scope.
* `admin_password`: Password of the admin user above.
* `apps_domain`: A shared domain that tests can use to create subdomains that will route to applications also created in the tests.
* `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.
* `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.

##### Optional parameters:
Expand Down
6 changes: 5 additions & 1 deletion helpers/config/config_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,13 @@ func validateApiEndpoint(config *config) error {
return fmt.Errorf("* Invalid configuration: 'api' must be a valid Cloud Controller endpoint but was blank")
}

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

host := u.Host
Expand Down
14 changes: 13 additions & 1 deletion helpers/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,19 @@ var _ = Describe("Config", func() {
It("returns an error", func() {
_, err := cfg.NewCatsConfig(tmpFilePath)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("* Invalid configuration: 'api' must be a valid URL but was set to '_bogus%%%'"))
Expect(err).To(MatchError("* Invalid configuration: 'api' must be a valid domain but was set to '_bogus%%%'"))
})
})

Context("when the url contains https://", func() {
BeforeEach(func() {
testCfg.ApiEndpoint = ptrToString("https://api.bosh-lite.com")
})

It("returns an error", func() {
_, err := cfg.NewCatsConfig(tmpFilePath)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("* Invalid configuration: 'api' must not contain a scheme/protocol but was set to 'https' in 'https://api.bosh-lite.com'"))
})
})

Expand Down

0 comments on commit 792753b

Please sign in to comment.