func initiateBrokerConfig(serviceName, serviceBrokerAppName string) { brokerConfigJson := helpers.CurlApp(Config, serviceBrokerAppName, "/config") var brokerConfigMap customMap err := json.Unmarshal([]byte(brokerConfigJson), &brokerConfigMap) Expect(err).NotTo(HaveOccurred()) dashboardClientId := random_name.CATSRandomName("DASHBOARD-ID") serviceId := random_name.CATSRandomName("SVC-ID") services := brokerConfigMap.key("behaviors").key("catalog").key("body")["services"].([]interface{}) service := services[0].(map[string]interface{}) service["dashboard_client"].(map[string]interface{})["id"] = dashboardClientId service["name"] = serviceName service["id"] = serviceId plans := service["plans"].([]interface{}) for i, plan := range plans { servicePlanId := random_name.CATSRandomName(fmt.Sprintf("SVC-PLAN-ID-%d-", i)) plan.(map[string]interface{})["id"] = servicePlanId } changedJson, err := json.Marshal(brokerConfigMap) Expect(err).NotTo(HaveOccurred()) helpers.CurlApp(Config, serviceBrokerAppName, "/config", "-X", "POST", "-d", string(changedJson)) }
func AuthenticateUser(authorizationEndpoint string, username string, password string) (cookie string) { loginCsrfUri := fmt.Sprintf("%v/login", authorizationEndpoint) cookieFile, err := ioutil.TempFile("", random_name.CATSRandomName("CATS-CSRF-COOKIE")) Expect(err).ToNot(HaveOccurred()) cookiePath := cookieFile.Name() defer func() { cookieFile.Close() os.Remove(cookiePath) }() curl := helpers.Curl(Config, loginCsrfUri, `--insecure`, `-i`, `-v`, `-c`, cookiePath).Wait(Config.DefaultTimeoutDuration()) apiResponse := string(curl.Out.Contents()) csrfRegEx, _ := regexp.Compile(`name="X-Uaa-Csrf" value="(.*)"`) csrfToken := csrfRegEx.FindStringSubmatch(apiResponse)[1] loginUri := fmt.Sprintf("%v/login.do", authorizationEndpoint) usernameEncoded := url.QueryEscape(username) passwordEncoded := url.QueryEscape(password) csrfTokenEncoded := url.QueryEscape(csrfToken) loginCredentials := fmt.Sprintf("username=%v&password=%v&X-Uaa-Csrf=%v", usernameEncoded, passwordEncoded, csrfTokenEncoded) curl = helpers.Curl(Config, loginUri, `--data`, loginCredentials, `--insecure`, `-i`, `-v`, `-b`, cookiePath).Wait(Config.DefaultTimeoutDuration()) Expect(curl).To(Exit(0)) apiResponse = string(curl.Out.Contents()) jsessionRegEx, _ := regexp.Compile(`JSESSIONID([^;]*)`) vcapidRegEx, _ := regexp.Compile(`__VCAP_ID__([^;]*)`) sessionId := jsessionRegEx.FindString(apiResponse) vcapId := vcapidRegEx.FindString(apiResponse) cookie = fmt.Sprintf("%v;%v", sessionId, vcapId) return }
func createDummyBuildpack() string { buildpack := random_name.CATSRandomName("BPK") buildpackZip := assets.NewAssets().SecurityGroupBuildpack workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() { Expect(cf.Cf("create-buildpack", buildpack, buildpackZip, "999").Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) }) return buildpack }
func createSecurityGroup(allowedDestinations ...Destination) string { file, _ := ioutil.TempFile(os.TempDir(), "CATS-sg-rules") defer os.Remove(file.Name()) Expect(json.NewEncoder(file).Encode(allowedDestinations)).To(Succeed()) rulesPath := file.Name() securityGroupName := random_name.CATSRandomName("SG") workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() { Expect(cf.Cf("create-security-group", securityGroupName, rulesPath).Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) }) return securityGroupName }
. "github.com/cloudfoundry/cf-acceptance-tests/helpers/services" ) var _ = ServicesDescribe("Purging service offerings", func() { var broker ServiceBroker var appName, instanceName, asyncInstanceName string AfterEach(func() { app_helpers.AppReport(broker.Name, Config.DefaultTimeoutDuration()) broker.Destroy() }) Context("for public brokers", func() { BeforeEach(func() { broker = NewServiceBroker( random_name.CATSRandomName("BRKR"), assets.NewAssets().ServiceBroker, TestSetup, ) broker.Push(Config) broker.Configure() workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() { broker.Create() broker.PublicizePlans() }) appName = random_name.CATSRandomName("APP") instanceName = random_name.CATSRandomName("SVIN") asyncInstanceName = random_name.CATSRandomName("SVIN") }) AfterEach(func() {
. "github.com/onsi/gomega/gexec" "github.com/cloudfoundry-incubator/cf-test-helpers/cf" "github.com/cloudfoundry-incubator/cf-test-helpers/helpers" "github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers" "github.com/cloudfoundry/cf-acceptance-tests/helpers/assets" "github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name" "github.com/cloudfoundry/cf-acceptance-tests/helpers/v3_helpers" ) var _ = AppsDescribe("Uploading and Downloading droplets", func() { var helloWorldAppName string var out bytes.Buffer BeforeEach(func() { helloWorldAppName = random_name.CATSRandomName("APP") Expect(cf.Cf("push", helloWorldAppName, "--no-start", "-b", Config.GetRubyBuildpackName(), "-m", DEFAULT_MEMORY_LIMIT, "-p", assets.NewAssets().HelloWorld, "-d", Config.GetAppsDomain()).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) app_helpers.SetBackend(helloWorldAppName) Expect(cf.Cf("start", helloWorldAppName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) }) AfterEach(func() { app_helpers.AppReport(helloWorldAppName, Config.DefaultTimeoutDuration()) Expect(cf.Cf("delete", helloWorldAppName, "-f", "-r").Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) }) It("Users can manage droplet bits for an app", func() { By("Downloading the droplet for the app")
. "github.com/onsi/gomega" . "github.com/onsi/gomega/gbytes" . "github.com/onsi/gomega/gexec" ) var _ = AppsDescribe("Logging", func() { var logWriterAppName string var listenerAppName string var logs *Session var interrupt chan struct{} var serviceName string Describe("Syslog drains", func() { BeforeEach(func() { interrupt = make(chan struct{}, 1) serviceName = random_name.CATSRandomName("SVIN") listenerAppName = random_name.CATSRandomName("APP") logWriterAppName = random_name.CATSRandomName("APP") Eventually(cf.Cf("push", listenerAppName, "--no-start", "--health-check-type", "port", "-b", Config.GetGoBuildpackName(), "-m", DEFAULT_MEMORY_LIMIT, "-p", assets.NewAssets().SyslogDrainListener, "-d", Config.GetAppsDomain(), "-f", assets.NewAssets().SyslogDrainListener+"/manifest.yml"), Config.DefaultTimeoutDuration()).Should(Exit(0), "Failed to push app") Eventually(cf.Cf("push", logWriterAppName, "--no-start", "-b", Config.GetRubyBuildpackName(), "-m", DEFAULT_MEMORY_LIMIT, "-p", assets.NewAssets().RubySimple, "-d", Config.GetAppsDomain()), Config.DefaultTimeoutDuration()).Should(Exit(0), "Failed to push app") app_helpers.SetBackend(listenerAppName) app_helpers.SetBackend(logWriterAppName) Expect(cf.Cf("start", listenerAppName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) Expect(cf.Cf("start", logWriterAppName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) }) AfterEach(func() { logs.Kill()
var _ = RoutingDescribe("Context Paths", func() { var ( app1 string helloRoutingAsset = assets.NewAssets().HelloRouting app2 string app2Path = "/app2" app3 string app3Path = "/app3/long/sub/path" hostname string ) BeforeEach(func() { domain := Config.GetAppsDomain() app1 = random_name.CATSRandomName("APP") PushApp(app1, helloRoutingAsset, Config.GetRubyBuildpackName(), Config.GetAppsDomain(), Config.CfPushTimeoutDuration(), DEFAULT_MEMORY_LIMIT) app2 = random_name.CATSRandomName("APP") PushApp(app2, helloRoutingAsset, Config.GetRubyBuildpackName(), Config.GetAppsDomain(), Config.CfPushTimeoutDuration(), DEFAULT_MEMORY_LIMIT) app3 = random_name.CATSRandomName("APP") PushApp(app3, helloRoutingAsset, Config.GetRubyBuildpackName(), Config.GetAppsDomain(), Config.CfPushTimeoutDuration(), DEFAULT_MEMORY_LIMIT) hostname = app1 MapRouteToApp(app2, domain, hostname, app2Path, Config.DefaultTimeoutDuration()) MapRouteToApp(app3, domain, hostname, app3Path, Config.DefaultTimeoutDuration()) }) AfterEach(func() { AppReport(app1, Config.DefaultTimeoutDuration()) AppReport(app2, Config.DefaultTimeoutDuration())
var revertExtendedEnv = func(groupType, envVarName string) { envMap := fetchEnvironmentVariables(groupType) delete(envMap, envVarName) jsonObj := marshalUpdatedEnv(envMap) apiUrl := fmt.Sprintf("/v2/config/environment_variable_groups/%s", groupType) Expect(cf.Cf("curl", apiUrl, "-X", "PUT", "-d", string(jsonObj)).Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) } Context("Staging environment variable groups", func() { var appName string var buildpackName string var envVarName string BeforeEach(func() { appName = random_name.CATSRandomName("APP") envVarName = fmt.Sprintf("CATS_STAGING_TEST_VAR_%s", strconv.Itoa(int(time.Now().UnixNano()))) }) AfterEach(func() { app_helpers.AppReport(appName, Config.DefaultTimeoutDuration()) workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() { revertExtendedEnv("staging", envVarName) if buildpackName != "" { Expect(cf.Cf("delete-buildpack", buildpackName, "-f").Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) } }) Expect(cf.Cf("delete", appName, "-f", "-r").Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) })
"github.com/cloudfoundry/cf-acceptance-tests/helpers/skip_messages" ) var _ = ServicesDescribe("SSO Lifecycle", func() { var broker ServiceBroker var oauthConfig OAuthConfig var apiEndpoint string redirectUri := `http://example.com` BeforeEach(func() { if !Config.GetIncludeSSO() { Skip(skip_messages.SkipSSOMessage) } broker = NewServiceBroker( random_name.CATSRandomName("BRKR"), assets.NewAssets().ServiceBroker, TestSetup, ) broker.Push(Config) broker.Service.DashboardClient.RedirectUri = redirectUri broker.Configure() oauthConfig = OAuthConfig{} oauthConfig.ClientId = broker.Service.DashboardClient.ID oauthConfig.ClientSecret = broker.Service.DashboardClient.Secret oauthConfig.RedirectUri = redirectUri oauthConfig.RequestedScopes = `openid,cloud_controller_service_permissions.read` apiEndpoint = Config.Protocol() + Config.GetApiEndpoint() SetOauthEndpoints(apiEndpoint, &oauthConfig, Config)
} waitForAsyncOperationToComplete := func(broker ServiceBroker, instanceName string) { Eventually(func() *Session { serviceDetails := cf.Cf("service", instanceName).Wait(Config.DefaultTimeoutDuration()) Expect(serviceDetails).To(Exit(0), "failed getting service instance details") return serviceDetails }, Config.AsyncServiceOperationTimeoutDuration(), ASYNC_OPERATION_POLL_INTERVAL).Should(Say("succeeded")) } type Params struct{ Param1 string } Context("Synchronous operations", func() { BeforeEach(func() { broker = NewServiceBroker( random_name.CATSRandomName("BRKR"), assets.NewAssets().ServiceBroker, TestSetup, ) broker.Push(Config) broker.Configure() broker.Create() broker.PublicizePlans() }) AfterEach(func() { app_helpers.AppReport(broker.Name, Config.DefaultTimeoutDuration()) broker.Destroy() })
"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name" . "github.com/cloudfoundry/cf-acceptance-tests/helpers/services" ) var _ = ServicesDescribe("Service Broker Lifecycle", func() { var broker ServiceBroker Describe("public brokers", func() { var acls *Session var output []byte var oldServiceName string var oldPlanName string BeforeEach(func() { broker = NewServiceBroker( random_name.CATSRandomName("BRKR"), assets.NewAssets().ServiceBroker, TestSetup, ) TestSetup.RegularUserContext().TargetSpace() broker.Push(Config) broker.Configure() workflowhelpers.AsUser(TestSetup.AdminUserContext(), TestSetup.ShortTimeout(), func() { broker.Create() }) }) Describe("Updating the catalog", func() { BeforeEach(func() { broker.PublicizePlans()
func NewServiceBroker(name string, path string, TestSetup *workflowhelpers.ReproducibleTestSuiteSetup) ServiceBroker { b := ServiceBroker{} b.Path = path b.Name = name b.Service.Name = random_name.CATSRandomName("SVC") b.Service.ID = random_name.CATSRandomName("SVC-ID") b.SyncPlans = []Plan{ {Name: random_name.CATSRandomName("SVC-PLAN"), ID: random_name.CATSRandomName("SVC-PLAN-ID")}, {Name: random_name.CATSRandomName("SVC-PLAN"), ID: random_name.CATSRandomName("SVC-PLAN-ID")}, } b.AsyncPlans = []Plan{ {Name: random_name.CATSRandomName("SVC-PLAN"), ID: random_name.CATSRandomName("SVC-PLAN-ID")}, {Name: random_name.CATSRandomName("SVC-PLAN"), ID: random_name.CATSRandomName("SVC-PLAN-ID")}, } b.Service.DashboardClient.ID = random_name.CATSRandomName("DASHBOARD-ID") b.Service.DashboardClient.Secret = random_name.CATSRandomName("DASHBOARD-SECRET") b.Service.DashboardClient.RedirectUri = random_name.CATSRandomName("DASHBOARD-URI") b.TestSetup = TestSetup return b }
} }) Context("when a route binds to a service", func() { Context("when service broker returns a route service url", func() { var ( serviceInstanceName string brokerName string appName string routeServiceName string golangAsset = assets.NewAssets().Golang loggingRouteServiceAsset = assets.NewAssets().LoggingRouteService ) BeforeEach(func() { routeServiceName = random_name.CATSRandomName("APP") brokerName = random_name.CATSRandomName("BRKR") serviceInstanceName = random_name.CATSRandomName("SVIN") appName = random_name.CATSRandomName("APP") serviceName := random_name.CATSRandomName("SVC") brokerAppName := random_name.CATSRandomName("APP") createServiceBroker(brokerName, brokerAppName, serviceName) createServiceInstance(serviceInstanceName, serviceName) PushAppNoStart(appName, golangAsset, Config.GetGoBuildpackName(), Config.GetAppsDomain(), Config.CfPushTimeoutDuration(), DEFAULT_MEMORY_LIMIT) EnableDiego(appName, Config.DefaultTimeoutDuration()) StartApp(appName, Config.CfPushTimeoutDuration()) PushApp(routeServiceName, loggingRouteServiceAsset, Config.GetGoBuildpackName(), Config.GetAppsDomain(), Config.CfPushTimeoutDuration(), DEFAULT_MEMORY_LIMIT)
} func getStagingOutput(appName string) func() *Session { return func() *Session { appLogsSession := cf.Cf("logs", "--recent", appName) Expect(appLogsSession.Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) return appLogsSession } } var _ = SecurityGroupsDescribe("Security Groups", func() { var serverAppName, privateHost string var privatePort int BeforeEach(func() { serverAppName = random_name.CATSRandomName("APP") pushApp(serverAppName, Config.GetRubyBuildpackName()) Expect(cf.Cf("start", serverAppName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) privateHost, privatePort = getAppHostIpAndPort(serverAppName) }) Describe("Running security-groups", func() { var clientAppName, securityGroupName string BeforeEach(func() { clientAppName = random_name.CATSRandomName("APP") pushApp(clientAppName, Config.GetRubyBuildpackName()) Expect(cf.Cf("start", clientAppName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) By("Asserting default running security group configuration for traffic between containers")
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" "github.com/cloudfoundry-incubator/cf-test-helpers/cf" "github.com/cloudfoundry-incubator/cf-test-helpers/helpers" "github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers" "github.com/cloudfoundry/cf-acceptance-tests/helpers/assets" "github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name" ) var _ = AppsDescribe("Delete Route", func() { var appName string BeforeEach(func() { appName = random_name.CATSRandomName("APP") Expect(cf.Cf("push", appName, "--no-start", "-b", Config.GetRubyBuildpackName(), "-m", DEFAULT_MEMORY_LIMIT, "-p", assets.NewAssets().Dora, "-d", Config.GetAppsDomain()).Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) app_helpers.SetBackend(appName) Expect(cf.Cf("start", appName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) Eventually(func() string { return helpers.CurlAppRoot(Config, appName) }, Config.DefaultTimeoutDuration()).Should(ContainSubstring("Hi, I'm Dora!")) }) AfterEach(func() { app_helpers.AppReport(appName, Config.DefaultTimeoutDuration()) Expect(cf.Cf("delete", appName, "-f", "-r").Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) })
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" "github.com/cloudfoundry-incubator/cf-test-helpers/cf" "github.com/cloudfoundry-incubator/cf-test-helpers/helpers" "github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers" "github.com/cloudfoundry/cf-acceptance-tests/helpers/assets" "github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name" ) var _ = AppsDescribe("Large_payload", func() { var appName string AfterEach(func() { app_helpers.AppReport(appName, Config.DefaultTimeoutDuration()) Expect(cf.Cf("delete", appName, "-f", "-r").Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) }) It("should be able to curl for a large response body", func() { appName = random_name.CATSRandomName("APP") Expect(cf.Cf("push", appName, "--no-start", "-b", Config.GetRubyBuildpackName(), "-m", DEFAULT_MEMORY_LIMIT, "-p", assets.NewAssets().Dora, "-d", Config.GetAppsDomain()).Wait(Config.DefaultTimeoutDuration())).To(Exit(0)) app_helpers.SetBackend(appName) Expect(cf.Cf("start", appName).Wait(Config.CfPushTimeoutDuration())).To(Exit(0)) Eventually(func() int { curlResponse := helpers.CurlApp(Config, appName, fmt.Sprintf("/largetext/5")) return len(curlResponse) }, 10*time.Second, 10*time.Second).Should(Equal(5 * 1024)) }) })
. "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = V3Describe("droplet features", func() { var ( appGuid string appName string packageGuid string spaceGuid string token string ) BeforeEach(func() { appName = random_name.CATSRandomName("APP") spaceGuid = GetSpaceGuidFromName(TestSetup.RegularUserContext().Space) appGuid = CreateApp(appName, spaceGuid, "{}") packageGuid = CreatePackage(appGuid) token = GetAuthToken() uploadUrl := fmt.Sprintf("%s%s/v3/packages/%s/upload", Config.Protocol(), Config.GetApiEndpoint(), packageGuid) UploadPackage(uploadUrl, assets.NewAssets().DoraZip, token) WaitForPackageToBeReady(packageGuid) }) Context("copying a droplet", func() { var ( destinationAppGuid string destinationAppName string sourceDropletGuid string )
) const ( VCAP_ID = "__VCAP_ID__" ) var _ = RoutingDescribe("Session Affinity", func() { var stickyAsset = assets.NewAssets().HelloRouting Context("when an app sets a JSESSIONID cookie", func() { var ( appName string cookieStorePath string ) BeforeEach(func() { appName = random_name.CATSRandomName("APP") PushApp(appName, stickyAsset, Config.GetRubyBuildpackName(), Config.GetAppsDomain(), Config.CfPushTimeoutDuration(), DEFAULT_MEMORY_LIMIT) cookieStore, err := ioutil.TempFile("", "cats-sticky-session") Expect(err).ToNot(HaveOccurred()) cookieStorePath = cookieStore.Name() cookieStore.Close() }) AfterEach(func() { AppReport(appName, Config.DefaultTimeoutDuration()) DeleteApp(appName, Config.DefaultTimeoutDuration()) err := os.Remove(cookieStorePath) Expect(err).ToNot(HaveOccurred())
"github.com/cloudfoundry-incubator/cf-test-helpers/workflowhelpers" "github.com/cloudfoundry/cf-acceptance-tests/helpers/assets" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" ) var _ = ServicesDescribe("Recursive Delete", func() { var broker ServiceBroker var orgName string var quotaName, spaceName, appName, instanceName string BeforeEach(func() { broker = NewServiceBroker( random_name.CATSRandomName("BRKR"), assets.NewAssets().ServiceBroker, TestSetup, ) broker.Push(Config) broker.Configure() broker.Create() broker.PublicizePlans() orgName = random_name.CATSRandomName("ORG") quotaName = random_name.CATSRandomName("QUOTA") spaceName = random_name.CATSRandomName("SPACE") appName = random_name.CATSRandomName("APP") instanceName = random_name.CATSRandomName("SVIN") workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {