Skip to content

Commit 3e1e2bd

Browse files
authored
Merge pull request #1823 from kart2bc/config-valid
skip dns validation for http_proxy
2 parents e102c17 + fa13651 commit 3e1e2bd

File tree

4 files changed

+86
-7
lines changed

4 files changed

+86
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ include_app_syslog_tcp
105105
* `admin_password`: Password of the admin user above.
106106
* `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.
107107
* `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.
108+
* `skip_dns_validation`: Skip DNS validation for CF API and apps domain. Use true for proxy environments. Default:false
108109

109110
##### Optional parameters:
110111
`include_*` parameters are used to specify whether to skip tests based on how a deployment is configured.

helpers/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type CatsConfig interface {
3939
GetIncludeVolumeServices() bool
4040
GetShouldKeepUser() bool
4141
GetSkipSSLValidation() bool
42+
GetSkipDNSValidation() bool
4243
GetUseExistingUser() bool
4344

4445
GetAddExistingUserToExistingSpace() bool

helpers/config/config_struct.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type config struct {
4040
IsolationSegmentTCPDomain *string `json:"isolation_segment_tcp_domain"`
4141

4242
SkipSSLValidation *bool `json:"skip_ssl_validation"`
43+
SkipDNSValidation *bool `json:"skip_dns_validation"`
4344

4445
ArtifactsDirectory *string `json:"artifacts_directory"`
4546

@@ -556,6 +557,11 @@ func validateApiEndpoint(config *config) error {
556557
host = u.Path
557558
}
558559

560+
// Skip DNS validation if configured (useful for HTTP proxy environments)
561+
if config.GetSkipDNSValidation() {
562+
return nil
563+
}
564+
559565
if _, err = net.LookupHost(host); err != nil {
560566
return fmt.Errorf("* Invalid configuration for 'api' <%s>: %s", config.GetApiEndpoint(), err)
561567
}
@@ -580,6 +586,11 @@ func validateAppsDomain(config *config) error {
580586
host = u.Path
581587
}
582588

589+
// Skip DNS validation if configured (useful for HTTP proxy environments)
590+
if config.GetSkipDNSValidation() {
591+
return nil
592+
}
593+
583594
if _, err = net.LookupHost(madeUpAppHostname); err != nil {
584595
return fmt.Errorf("* Invalid configuration for 'apps_domain' <%s>: %s", config.GetAppsDomain(), err)
585596
}
@@ -866,6 +877,13 @@ func (c *config) GetSkipSSLValidation() bool {
866877
return *c.SkipSSLValidation
867878
}
868879

880+
func (c *config) GetSkipDNSValidation() bool {
881+
if c.SkipDNSValidation == nil {
882+
return false
883+
}
884+
return *c.SkipDNSValidation
885+
}
886+
869887
func (c *config) GetArtifactsDirectory() string {
870888
return *c.ArtifactsDirectory
871889
}

helpers/config/config_test.go

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ type testConfig struct {
2727
requiredConfig
2828

2929
// timeouts
30-
DefaultTimeout *int `json:"default_timeout,omitempty"`
31-
CfPushTimeout *int `json:"cf_push_timeout,omitempty"`
32-
LongCurlTimeout *int `json:"long_curl_timeout,omitempty"`
33-
BrokerStartTimeout *int `json:"broker_start_timeout,omitempty"`
34-
AsyncServiceOperationTimeout *int `json:"async_service_operation_timeout,omitempty"`
35-
DetectTimeout *int `json:"detect_timeout,omitempty"`
36-
SleepTimeout *int `json:"sleep_timeout,omitempty"`
30+
DefaultTimeout *int `json:"default_timeout,omitempty"`
31+
CfPushTimeout *int `json:"cf_push_timeout,omitempty"`
32+
LongCurlTimeout *int `json:"long_curl_timeout,omitempty"`
33+
BrokerStartTimeout *int `json:"broker_start_timeout,omitempty"`
34+
AsyncServiceOperationTimeout *int `json:"async_service_operation_timeout,omitempty"`
35+
DetectTimeout *int `json:"detect_timeout,omitempty"`
36+
SleepTimeout *int `json:"sleep_timeout,omitempty"`
37+
SkipDNSValidation *bool `json:"skip_dns_validation"`
3738

3839
TimeoutScale *float64 `json:"timeout_scale,omitempty"`
3940

@@ -124,6 +125,7 @@ type nullConfig struct {
124125
IsolationSegmentDomain *string `json:"isolation_segment_domain"`
125126

126127
SkipSSLValidation *bool `json:"skip_ssl_validation"`
128+
SkipDNSValidation *bool `json:"skip_dns_validation"`
127129

128130
ArtifactsDirectory *string `json:"artifacts_directory"`
129131

@@ -948,6 +950,63 @@ var _ = Describe("Config", func() {
948950
})
949951
})
950952

953+
Describe("GetSkipDNSValidation", func() {
954+
Context("when skip_dns_validation is not set", func() {
955+
It("returns false (default)", func() {
956+
config, err := cfg.NewCatsConfig(tmpFilePath)
957+
Expect(err).NotTo(HaveOccurred())
958+
Expect(config.GetSkipDNSValidation()).To(BeFalse())
959+
})
960+
})
961+
962+
Context("when skip_dns_validation is set to true", func() {
963+
BeforeEach(func() {
964+
testCfg.SkipDNSValidation = ptrToBool(true)
965+
})
966+
967+
It("returns true", func() {
968+
config, err := cfg.NewCatsConfig(tmpFilePath)
969+
Expect(err).NotTo(HaveOccurred())
970+
Expect(config.GetSkipDNSValidation()).To(BeTrue())
971+
})
972+
973+
Context("with unresolvable apps domain", func() {
974+
BeforeEach(func() {
975+
testCfg.AppsDomain = ptrToString("apps.domain.example.com")
976+
})
977+
978+
It("skips DNS lookup for apps domain", func() {
979+
config, err := cfg.NewCatsConfig(tmpFilePath)
980+
Expect(err).NotTo(HaveOccurred())
981+
Expect(config.GetAppsDomain()).To(Equal("apps.domain.example.com"))
982+
})
983+
})
984+
})
985+
986+
Context("when skip_dns_validation is set to false", func() {
987+
BeforeEach(func() {
988+
testCfg.SkipDNSValidation = ptrToBool(false)
989+
})
990+
991+
It("returns false", func() {
992+
config, err := cfg.NewCatsConfig(tmpFilePath)
993+
Expect(err).NotTo(HaveOccurred())
994+
Expect(config.GetSkipDNSValidation()).To(BeFalse())
995+
})
996+
Context("with unresolvable apps domain", func() {
997+
BeforeEach(func() {
998+
testCfg.AppsDomain = ptrToString("domain.example.com.does-not-exist")
999+
})
1000+
1001+
It("performs DNS lookup for apps domain", func() {
1002+
_, err := cfg.NewCatsConfig(tmpFilePath)
1003+
Expect(err).To(HaveOccurred())
1004+
Expect(err.Error()).To(ContainSubstring("no such host"))
1005+
})
1006+
})
1007+
})
1008+
})
1009+
9511010
Describe("GetAdminUser", func() {
9521011
It("returns the admin user", func() {
9531012
c, err := cfg.NewCatsConfig(tmpFilePath)

0 commit comments

Comments
 (0)