Skip to content

Commit c3f61ca

Browse files
peterellisjonesPeter Ellis Jones
authored andcommitted
Make dynamic ASG test endpoint configurable
1 parent ead15c9 commit c3f61ca

4 files changed

Lines changed: 47 additions & 8 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ include_v3
196196

197197
* `infrastructure`: The name of the infrastructure for the environment that the tests will run against. Must be either "vms" or "kubernetes". Defaults to "vms".
198198

199+
* `dynamic_asg_test_config`: By default the Dynamic ASG test allows and blocks access to the Cloud Controller internal endpoint by toggling access for TCP requests on port 9024 to 10.0.0.0/8. To test dynamic ASGs against another endpoint and/or by toggling a different IP range, include `dynamic_asg_test_config` as an object with the following properties:
200+
* `endpoint_host`: Hostname or IP for test endpoint to allow/block
201+
* `endpoint_port`: Port for test endpoint to allow/block
202+
* `endpoint_path`: HTTP Path for test endpoint to allow/block
203+
* `endpoint_allow_ip_range`: IP range used for allowing and blocking access to the test endpoint. This can be a single IP address, a range like 192.0.2.0-192.0.2.50, or a CIDR block like 10.0.0.0/8.
204+
* `expected_response_regex`: Regex to match expected response body from test endpoint
205+
199206
#### Buildpack Names
200207
Many tests specify a buildpack when pushing an app, so that on diego the app staging process completes in less time. The default names for the buildpacks are as follows; if you have buildpacks with different names, you can override them by setting different names:
201208

helpers/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type CatsConfig interface {
8686
GetVolumeServiceCreateConfig() string
8787

8888
GetReporterConfig() reporterConfig
89+
GetDynamicASGTestConfig() dynamicASGTestConfig
8990

9091
AsyncServiceOperationTimeoutDuration() time.Duration
9192
BrokerStartTimeoutDuration() time.Duration

helpers/config/config_struct.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ type config struct {
114114

115115
NamePrefix *string `json:"name_prefix"`
116116

117-
ReporterConfig *reporterConfig `json:"reporter_config"`
117+
ReporterConfig *reporterConfig `json:"reporter_config"`
118+
DynamicASGTestConfig *dynamicASGTestConfig `json:"dynamic_asg_test_config"`
118119

119120
Infrastructure *string `json:"infrastructure"`
120121
}
@@ -125,6 +126,14 @@ type reporterConfig struct {
125126
CustomTags map[string]interface{} `json:"custom_tags"`
126127
}
127128

129+
type dynamicASGTestConfig struct {
130+
EndpointHost string `json:"endpoint_host"`
131+
EndpointPort int `json:"endpoint_port"`
132+
EndpointPath string `json:"endpoint_path"`
133+
EndpointAllowIPRange string `json:"endpoint_allow_ip_range"`
134+
ExpectedResponseRegex string `json:"expected_response_regex"`
135+
}
136+
128137
var defaults = config{}
129138

130139
func ptrToString(str string) *string {
@@ -198,6 +207,15 @@ func getDefaults() config {
198207
defaults.VolumeServiceCreateConfig = ptrToString("")
199208

200209
defaults.ReporterConfig = &reporterConfig{}
210+
defaults.DynamicASGTestConfig = &dynamicASGTestConfig{
211+
// By default run dynamic ASG test against internal
212+
// Cloud Controller endpoint (port 9024)
213+
ExpectedResponseRegex: "api_version",
214+
EndpointAllowIPRange: "10.0.0.0/0",
215+
EndpointHost: "cloud-controller-ng.service.cf.internal",
216+
EndpointPath: "/v2/info",
217+
EndpointPort: 9024,
218+
}
201219

202220
defaults.UseHttp = ptrToBool(false)
203221
defaults.UseExistingUser = ptrToBool(false)
@@ -1097,6 +1115,16 @@ func (c *config) GetReporterConfig() reporterConfig {
10971115
return reporterConfig{}
10981116
}
10991117

1118+
func (c *config) GetDynamicASGTestConfig() dynamicASGTestConfig {
1119+
dynamicASGTestConfigFromConfig := c.DynamicASGTestConfig
1120+
1121+
if dynamicASGTestConfigFromConfig != nil {
1122+
return *dynamicASGTestConfigFromConfig
1123+
}
1124+
1125+
return dynamicASGTestConfig{}
1126+
}
1127+
11001128
func (c *config) RunningOnK8s() bool {
11011129
return *c.Infrastructure == "kubernetes"
11021130
}

security_groups/dynamic_asgs.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io/ioutil"
77
"net/http"
8+
"strconv"
89
"time"
910

1011
. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
@@ -51,7 +52,9 @@ var _ = Describe("Dynamic ASGs", func() {
5152
})
5253

5354
It("applies ASGs wihout app restart", func() {
54-
proxyRequestURL := fmt.Sprintf("%s%s.%s/https_proxy/cloud-controller-ng.service.cf.internal:9024/v2/info", Config.Protocol(), appName, Config.GetAppsDomain())
55+
endpointHostPortPath := fmt.Sprintf("%s:%d%s", Config.GetDynamicASGTestConfig().EndpointHost, Config.GetDynamicASGTestConfig().EndpointPort, Config.GetDynamicASGTestConfig().EndpointPath)
56+
57+
proxyRequestURL := fmt.Sprintf("%s%s.%s/https_proxy/%s", Config.Protocol(), appName, Config.GetAppsDomain(), endpointHostPortPath)
5558

5659
client := &http.Client{
5760
Transport: &http.Transport{
@@ -61,7 +64,7 @@ var _ = Describe("Dynamic ASGs", func() {
6164
},
6265
}
6366

64-
By("checking that our app can't initially reach cloud controller over internal address")
67+
By(fmt.Sprintf("checking that our app can't initially reach %s", endpointHostPortPath))
6568
resp, err := client.Get(proxyRequestURL)
6669
Expect(err).NotTo(HaveOccurred())
6770

@@ -72,14 +75,14 @@ var _ = Describe("Dynamic ASGs", func() {
7275

7376
By("binding a new security group")
7477
dest := Destination{
75-
IP: "10.0.0.0/0",
76-
Ports: "9024", // internal cc port
78+
IP: Config.GetDynamicASGTestConfig().EndpointAllowIPRange,
79+
Ports: strconv.Itoa(Config.GetDynamicASGTestConfig().EndpointPort),
7780
Protocol: "tcp",
7881
}
7982
securityGroupName = createSecurityGroup(dest)
8083
bindSecurityGroup(securityGroupName, orgName, spaceName)
8184

82-
By("checking that our app can now reach cloud controller over internal address")
85+
By(fmt.Sprintf("checking that our app can now reach %s", endpointHostPortPath))
8386
Eventually(func() []byte {
8487
resp, err = client.Get(proxyRequestURL)
8588
Expect(err).NotTo(HaveOccurred())
@@ -88,12 +91,12 @@ var _ = Describe("Dynamic ASGs", func() {
8891
Expect(err).ToNot(HaveOccurred())
8992
resp.Body.Close()
9093
return respBytes
91-
}, 3*time.Minute).Should(MatchRegexp("api_version"))
94+
}, 3*time.Minute).Should(MatchRegexp(Config.GetDynamicASGTestConfig().ExpectedResponseRegex))
9295

9396
By("unbinding the security group")
9497
unbindSecurityGroup(securityGroupName, orgName, spaceName)
9598

96-
By("checking that our app can no longer reach cloud controller over internal address")
99+
By(fmt.Sprintf("checking that our app can no longer reach %s", endpointHostPortPath))
97100
Eventually(func() []byte {
98101
resp, err = client.Get(proxyRequestURL)
99102
Expect(err).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)