func newCfApp(appNamePrefix string, maxFailedCurls int) *cfApp {
	appName := appNamePrefix + "-" + generator.RandomName()
	rawUrl := fmt.Sprintf(AppRoutePattern, appName, config.OverrideDomain)
	appUrl, err := url.Parse(rawUrl)
	if err != nil {
		panic(err)
	}
	return &cfApp{
		appName:        appName,
		appRoute:       *appUrl,
		orgName:        "org-" + generator.RandomName(),
		spaceName:      "space-" + generator.RandomName(),
		maxFailedCurls: maxFailedCurls,
	}
}
Example #2
0
func AuthenticateUser(authorizationEndpoint string, username string, password string) (cookie string) {
	loginCsrfUri := fmt.Sprintf("%v/login", authorizationEndpoint)

	cookieFile, err := ioutil.TempFile("", "cats-csrf-cookie"+generator.RandomName())
	Expect(err).ToNot(HaveOccurred())
	cookiePath := cookieFile.Name()
	defer func() {
		cookieFile.Close()
		os.Remove(cookiePath)
	}()

	curl := runner.Curl(loginCsrfUri, `--insecure`, `-i`, `-v`, `-c`, cookiePath).Wait(DEFAULT_TIMEOUT)
	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 = runner.Curl(loginUri, `--data`, loginCredentials, `--insecure`, `-i`, `-v`, `-b`, cookiePath).Wait(DEFAULT_TIMEOUT)
	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
}
Example #3
0
func TestApplications(t *testing.T) {
	RegisterFailHandler(Fail)

	SetDefaultEventuallyTimeout(time.Minute)
	SetDefaultEventuallyPollingInterval(time.Second)

	config := helpers.LoadConfig()
	context = helpers.NewContext(config)
	environment := helpers.NewEnvironment(context)

	BeforeSuite(func() {
		environment.Setup()
	})

	AfterSuite(func() {
		environment.Teardown()
	})

	BeforeEach(func() {
		appName = generator.RandomName()
	})

	componentName := "Diego"

	rs := []Reporter{}

	if config.ArtifactsDirectory != "" {
		helpers.EnableCFTrace(config, componentName)
		rs = append(rs, helpers.NewJUnitReporter(config, componentName))
	}

	RunSpecsWithDefaultAndCustomReporters(t, componentName, rs)
}
func testThatDrainIsReachable(syslogDrainAddress string, drainListener *syslogDrainListener) {
	conn, err := net.Dial("tcp", syslogDrainAddress)
	Expect(err).ToNot(HaveOccurred())
	defer conn.Close()

	randomMessage := "random-message-" + generator.RandomName()
	_, err = conn.Write([]byte(randomMessage))
	Expect(err).ToNot(HaveOccurred())

	Eventually(func() bool {
		return drainListener.DidReceive(randomMessage)
	}).Should(BeTrue())
}
Example #5
0
func NewServiceBroker(name string, path string, context helpers.SuiteContext) ServiceBroker {
	b := ServiceBroker{}
	b.Path = path
	b.Name = name
	b.Service.Name = generator.RandomName()
	b.Service.ID = generator.RandomName()
	b.Plan.Name = generator.RandomName()
	b.Plan.ID = generator.RandomName()
	b.Service.DashboardClient.ID = generator.RandomName()
	b.Service.DashboardClient.Secret = generator.RandomName()
	b.Service.DashboardClient.RedirectUri = generator.RandomName()
	b.context = context
	return b
}
Example #6
0
func NewServiceBroker(name string, path string, context helpers.SuiteContext, includeSSOClient bool) ServiceBroker {
	b := ServiceBroker{}
	b.Path = path
	b.Name = name
	b.Service.Name = generator.RandomName()
	b.Service.ID = generator.RandomName()
	b.SyncPlans = []Plan{
		{Name: generator.RandomName(), ID: generator.RandomName()},
		{Name: generator.RandomName(), ID: generator.RandomName()},
	}
	b.AsyncPlans = []Plan{
		{Name: generator.RandomName(), ID: generator.RandomName()},
		{Name: generator.RandomName(), ID: generator.RandomName()},
	}
	b.SsoPlans = []Plan{
		{
			Name: generator.RandomName(), ID: generator.RandomName(), DashboardClient: DashboardClient{
				ID:     generator.RandomName(),
				Secret: generator.RandomName(),
			},
		},
	}
	if includeSSOClient {
		b.Service.DashboardClient.Key = "dashboard_client"
	} else {
		b.Service.DashboardClient.Key = "dashboard_client-deactivated"
	}

	b.Service.DashboardClient.ID = generator.RandomName()
	b.Service.DashboardClient.Secret = generator.RandomName()
	b.Service.DashboardClient.RedirectUri = generator.RandomName()
	b.context = context
	return b
}
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry-incubator/cf-test-helpers/helpers"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"
	. "github.com/cloudfoundry/cf-acceptance-tests/helpers/services"
)

var _ = Describe("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(generator.RandomName(), assets.NewAssets().ServiceBroker, context, false)
			cf.TargetSpace(context.RegularUserContext(), context.ShortTimeout())
			broker.Push()
			broker.Configure()

			cf.AsUser(context.AdminUserContext(), context.ShortTimeout(), func() {
				broker.Create()
			})
		})

		Describe("Updating the catalog", func() {

			BeforeEach(func() {
				broker.PublicizePlans()
			})
		}, ASYNC_OPERATION_TIMEOUT, ASYNC_OPERATION_POLL_INTERVAL).Should(Say("not found"))
	}

	waitForAsyncOperationToComplete := func(broker ServiceBroker, instanceName string) {
		Eventually(func() *Session {
			serviceDetails := cf.Cf("service", instanceName).Wait(DEFAULT_TIMEOUT)
			Expect(serviceDetails).To(Exit(0), "failed getting service instance details")
			return serviceDetails
		}, ASYNC_OPERATION_TIMEOUT, ASYNC_OPERATION_POLL_INTERVAL).Should(Say("succeeded"))
	}

	type Params struct{ Param1 string }

	Context("Synchronous operations", func() {
		BeforeEach(func() {
			broker = NewServiceBroker(generator.RandomName(), assets.NewAssets().ServiceBroker, context, true)
			broker.Push()
			broker.Configure()
			broker.Create()
			broker.PublicizePlans()
		})

		AfterEach(func() {
			broker.Destroy()
		})

		Context("just service instances", func() {
			It("can create a service instance", func() {
				tags := "['tag1', 'tag2']"
				type Params struct{ Param1 string }
				params, _ := json.Marshal(Params{Param1: "value"})
	"testing"
)

func TestTurbulence(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Turbulence Suite")
}

var (
	goPath             string
	config             helpers.Config
	bosh               *helpers.Bosh
	turbulenceManifest *helpers.Manifest

	etcdRelease          = fmt.Sprintf("etcd-%s", generator.RandomName())
	etcdDeployment       = etcdRelease
	turbulenceDeployment = fmt.Sprintf("turb-%s", generator.RandomName())

	directorUUIDStub, etcdNameOverrideStub, turbulenceNameOverrideStub string

	turbulenceManifestGeneration string
	etcdManifestGeneration       string
)

var _ = BeforeSuite(func() {
	goPath = helpers.SetupGoPath()
	gemfilePath := helpers.SetupFastBosh()
	config = helpers.LoadConfig()
	boshOperationTimeout := helpers.GetBoshOperationTimeout(config)
	bosh = helpers.NewBosh(gemfilePath, goPath, config.BoshTarget, boshOperationTimeout)
				appLogsSession := cf.Cf("logs", "--recent", appName)
				Expect(appLogsSession.Wait(DEFAULT_TIMEOUT)).To(Exit(0))
				return appLogsSession
			}, DEFAULT_TIMEOUT).Should(Say("Muahaha"))
		})
	})

	Context("firehose data", func() {
		It("shows logs and metrics", func() {
			config := helpers.LoadConfig()

			noaaConnection := noaa.NewConsumer(getDopplerEndpoint(), &tls.Config{InsecureSkipVerify: config.SkipSSLValidation}, nil)
			msgChan := make(chan *events.Envelope, 100000)
			errorChan := make(chan error)
			stopchan := make(chan struct{})
			go noaaConnection.Firehose(generator.RandomName(), getAdminUserAccessToken(), msgChan, errorChan, stopchan)
			defer close(stopchan)

			Eventually(func() string {
				return helpers.CurlApp(appName, fmt.Sprintf("/log/sleep/%d", hundredthOfOneSecond))
			}, DEFAULT_TIMEOUT).Should(ContainSubstring("Muahaha"))

			timeout := time.After(5 * time.Second)
			messages := make([]*events.Envelope, 0, 100000)

			for {
				select {
				case <-timeout:
					return
				case msg := <-msgChan:
					messages = append(messages, msg)
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"

	"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers"
	shelpers "github.com/cloudfoundry/cf-acceptance-tests/services/helpers"
)

var _ = Describe("Purging service offerings", func() {
	var broker shelpers.ServiceBroker

	BeforeEach(func() {
		broker = shelpers.NewServiceBroker(generator.RandomName(), helpers.NewAssets().ServiceBroker, context)
		broker.Push()
		broker.Configure()
		broker.Create()
		broker.PublicizePlans()
	})

	AfterEach(func() {
		broker.Destroy()
	})

	It("removes all instances and plans of the service, then removes the service offering", func() {
		instanceName := "purge-offering-instance"

		marketplace := cf.Cf("marketplace").Wait(DEFAULT_TIMEOUT)
		Expect(marketplace).To(Exit(0))
	})

	It("Applies correct environment variables while running apps", func() {
		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
			Expect(cf.Cf("set-running-environment-variable-group", `{"CATS_RUNNING_TEST_VAR":"running_env_value"}`).Wait(DEFAULT_TIMEOUT)).To(Exit(0))
		})

		Expect(cf.Cf("push", appName, "-m", "128M", "-p", assets.NewAssets().Dora, "-d", config.AppsDomain).Wait(CF_PUSH_TIMEOUT)).To(Exit(0))

		env := helpers.CurlApp(appName, "/env")

		Expect(env).To(ContainSubstring("running_env_value"))
	})

	It("Applies environment variables while staging apps", func() {
		buildpackName = generator.RandomName()
		buildpackZip := createBuildpack()

		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
			Expect(cf.Cf("set-staging-environment-variable-group", `{"CATS_STAGING_TEST_VAR":"staging_env_value"}`).Wait(DEFAULT_TIMEOUT)).To(Exit(0))
			Expect(cf.Cf("create-buildpack", buildpackName, buildpackZip, "999").Wait(DEFAULT_TIMEOUT)).To(Exit(0))
		})

		Expect(cf.Cf("push", appName, "-m", "128M", "-b", buildpackName, "-p", assets.NewAssets().HelloWorld, "-d", config.AppsDomain).Wait(CF_PUSH_TIMEOUT)).To(Exit(1))

		Eventually(func() *Session {
			appLogsSession := cf.Cf("logs", "--recent", appName)
			Expect(appLogsSession.Wait(DEFAULT_TIMEOUT)).To(Exit(0))
			return appLogsSession
		}, DEFAULT_TIMEOUT).Should(Say("staging_env_value"))
	})
		app_helpers.SetBackend(appName)
		Expect(cf.Cf("start", appName).Wait(CF_PUSH_TIMEOUT)).To(Exit(0))
		Eventually(func() string {
			return helpers.CurlAppRoot(appName)
		}, DEFAULT_TIMEOUT).Should(ContainSubstring("Hi, I'm Dora!"))
	})

	AfterEach(func() {
		app_helpers.AppReport(appName, DEFAULT_TIMEOUT)

		Expect(cf.Cf("delete", appName, "-f", "-r").Wait(DEFAULT_TIMEOUT)).To(Exit(0))
	})

	Describe("Removing the route", func() {
		It("Should be  able to remove and delete the route", func() {
			secondHost := generator.RandomName()

			By("adding a route")
			Eventually(cf.Cf("map-route", appName, helpers.LoadConfig().AppsDomain, "-n", secondHost), DEFAULT_TIMEOUT).Should(Exit(0))
			Eventually(helpers.CurlingAppRoot(appName), DEFAULT_TIMEOUT).Should(ContainSubstring("Hi, I'm Dora!"))
			Eventually(helpers.CurlingAppRoot(secondHost), DEFAULT_TIMEOUT).Should(ContainSubstring("Hi, I'm Dora!"))

			By("removing a route")
			Eventually(cf.Cf("unmap-route", appName, helpers.LoadConfig().AppsDomain, "-n", secondHost), DEFAULT_TIMEOUT).Should(Exit(0))
			Eventually(helpers.CurlingAppRoot(secondHost), DEFAULT_TIMEOUT).Should(ContainSubstring("404"))
			Eventually(helpers.CurlingAppRoot(appName), DEFAULT_TIMEOUT).Should(ContainSubstring("Hi, I'm Dora!"))

			By("deleting the original route")
			Expect(cf.Cf("delete-route", helpers.LoadConfig().AppsDomain, "-n", appName, "-f").Wait(DEFAULT_TIMEOUT)).To(Exit(0))
			Eventually(helpers.CurlingAppRoot(appName), DEFAULT_TIMEOUT).Should(ContainSubstring("404"))
		})
func TestDeploy(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Deploy Suite")
}

var (
	goPath string
	config helpers.Config

	bosh *helpers.Bosh

	consulManifestGeneration string

	directorUUIDStub string

	consulRelease          = fmt.Sprintf("consul-%s", generator.RandomName())
	consulDeployment       = consulRelease
	consulNameOverrideStub string
)

var _ = BeforeSuite(func() {
	goPath = helpers.SetupGoPath()
	gemfilePath := helpers.SetupFastBosh()
	config = helpers.LoadConfig()
	boshOperationTimeout := helpers.GetBoshOperationTimeout(config)
	bosh = helpers.NewBosh(gemfilePath, goPath, config.BoshTarget, boshOperationTimeout)

	consulManifestGeneration = filepath.Join(goPath, "src", "acceptance-tests", "scripts", "generate-consul-deployment-manifest")

	err := os.Chdir(goPath)
	Expect(err).ToNot(HaveOccurred())
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"

	"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"
	. "github.com/cloudfoundry/cf-acceptance-tests/helpers/services"
)

var _ = Describe("Purging service offerings", func() {
	var broker ServiceBroker

	BeforeEach(func() {
		broker = NewServiceBroker(generator.RandomName(), assets.NewAssets().ServiceBroker, context)
		broker.Push()
		broker.Configure()
		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
			broker.Create()
			broker.PublicizePlans()
		})
	})

	AfterEach(func() {
		broker.Destroy()
	})

	Context("when there are several existing service entities", func() {
		var appName, instanceName string
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry-incubator/cf-test-helpers/helpers"
	"github.com/cloudfoundry-incubator/diego-acceptance-tests/helpers/assets"
)

var _ = Describe("Security Groups", func() {
	type DoraCurlResponse struct {
		Stdout     string
		Stderr     string
		ReturnCode int `json:"return_code"`
	}

	var appName string

	BeforeEach(func() {
		appName = generator.RandomName()
	})

	AfterEach(func() {
		Eventually(cf.Cf("logs", appName, "--recent")).Should(Exit())
		Eventually(cf.Cf("delete", appName, "-f")).Should(Exit(0))
	})

	// this test assumes the default running security groups block access to the DEAs
	// the test takes advantage of the fact that the DEA ip address and internal container ip address
	//  are discoverable via the cc api and dora's myip endpoint
	It("allows traffic and then blocks traffic", func() {
		By("pushing it")
		Eventually(cf.Cf("push", appName, "-p", assets.NewAssets().Dora, "--no-start", "-b", "ruby_buildpack"), CF_PUSH_TIMEOUT).Should(Exit(0))

		By("staging and running it on Diego")
	"testing"
)

func TestTurbulence(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Turbulence Suite")
}

var (
	goPath             string
	config             helpers.Config
	bosh               *helpers.Bosh
	turbulenceManifest *helpers.Manifest

	consulRelease    = fmt.Sprintf("consul-%s", generator.RandomName())
	consulDeployment = consulRelease

	turbulenceDeployment = fmt.Sprintf("turb-%s", generator.RandomName())

	directorUUIDStub, consulNameOverrideStub, turbulenceNameOverrideStub string

	turbulenceManifestGeneration string
	consulManifestGeneration     string
)

var _ = BeforeSuite(func() {
	goPath = helpers.SetupGoPath()
	gemfilePath := helpers.SetupFastBosh()
	config = helpers.LoadConfig()
	boshOperationTimeout := helpers.GetBoshOperationTimeout(config)
	. "github.com/onsi/gomega"

	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers"
	shelpers "github.com/cloudfoundry/cf-acceptance-tests/services/helpers"
)

var _ = Describe("SSO Lifecycle", func() {
	var broker shelpers.ServiceBroker
	var config shelpers.OAuthConfig
	var apiEndpoint = helpers.LoadConfig().ApiEndpoint

	redirectUri := `http://example.com`

	BeforeEach(func() {
		broker = shelpers.NewServiceBroker(generator.RandomName(), helpers.NewAssets().ServiceBroker, context)
		broker.Push()
		broker.Service.DashboardClient.RedirectUri = redirectUri
		broker.Configure()

		config = shelpers.OAuthConfig{}
		config.ClientId = broker.Service.DashboardClient.ID
		config.ClientSecret = broker.Service.DashboardClient.Secret
		config.RedirectUri = redirectUri
		config.RequestedScopes = `openid,cloud_controller_service_permissions.read`

		shelpers.SetOauthEndpoints(apiEndpoint, &config)
	})

	AfterEach(func() {
		broker.Destroy()
	BeforeEach(func() {
		Expect(helpers.TestConfig.MysqlNodes).NotTo(BeNil())
		Expect(len(helpers.TestConfig.MysqlNodes)).To(BeNumerically(">=", 1))

		Expect(helpers.TestConfig.Brokers).NotTo(BeNil())
		Expect(len(helpers.TestConfig.Brokers)).To(BeNumerically(">=", 2))

		broker0SshTunnel = helpers.TestConfig.Brokers[0].SshTunnel
		broker1SshTunnel = helpers.TestConfig.Brokers[1].SshTunnel

		// Remove broker partitions in case previous test did not cleanup correctly
		partition.Off(broker0SshTunnel)
		partition.Off(broker1SshTunnel)

		appName = generator.RandomName()

		By("Push an app", func() {
			runner.NewCmdRunner(Cf("push", appName, "-m", "256M", "-p", sinatraPath, "-b", "ruby_buildpack", "-no-start"), helpers.TestContext.LongTimeout()).Run()
		})
	})

	AfterEach(func() {
		partition.Off(broker0SshTunnel)
		partition.Off(broker1SshTunnel)
		// TODO: Reintroduce the mariadb node once #81974864 is complete.
		// partition.Off(IntegrationConfig.MysqlNodes[0].SshTunnel)
	})

	It("write/read data before and after a partition of mysql node and then broker", func() {
		instanceCount := 3
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"
	. "github.com/cloudfoundry/cf-acceptance-tests/helpers/services"
)

var _ = Describe("SSO Lifecycle", func() {
	var broker ServiceBroker
	var config OAuthConfig
	var redirectUri string
	var apiEndpoint = helpers.LoadConfig().ApiEndpoint

	Describe("For service clients (provided in catalog)", func() {

		BeforeEach(func() {
			redirectUri = `http://www.purple.com`

			broker = NewServiceBroker(generator.RandomName(), assets.NewAssets().ServiceBroker, context, true)
			broker.Push()
			broker.Service.DashboardClient.RedirectUri = redirectUri
			broker.Configure()

			config = OAuthConfig{}
			config.ClientId = broker.Service.DashboardClient.ID
			config.ClientSecret = broker.Service.DashboardClient.Secret
			config.RedirectUri = redirectUri
			config.RequestedScopes = `openid,cloud_controller_service_permissions.read`

			SetOauthEndpoints(apiEndpoint, &config)

			broker.Create()
		})
		systemDomain       string
		oauthPassword      string
		oauthUrl           string
		routingApiEndpoint string

		route     string
		routeJSON string
	)

	BeforeEach(func() {
		systemDomain = config.SystemDomain
		oauthPassword = config.ClientSecret
		oauthUrl = config.Protocol() + "uaa." + systemDomain
		routingApiEndpoint = config.Protocol() + "routing-api." + systemDomain

		route = generator.RandomName()
		routeJSON = `[{"route":"` + route + `","port":65340,"ip":"1.2.3.4","ttl":60}]`
	})

	Describe("the routing API is enabled", func() {
		It("can register, list and unregister routes", func() {
			args := []string{"register", routeJSON, "--api", routingApiEndpoint, "--client-id", "gorouter", "--client-secret", oauthPassword, "--oauth-url", oauthUrl}
			session := Rtr(args...)

			Eventually(session.Out).Should(Say("Successfully registered routes"))

			args = []string{"list", "--api", routingApiEndpoint, "--client-id", "gorouter", "--client-secret", oauthPassword, "--oauth-url", oauthUrl}
			session = Rtr(args...)

			Eventually(session.Out).Should(Say(route))
		BeforeEach(func() {
			syslogDrainAddress := fmt.Sprintf("%s:%d", testConfig.SyslogIpAddress, testConfig.SyslogDrainPort)

			drainListener = &syslogDrainListener{port: testConfig.SyslogDrainPort}
			drainListener.StartListener()
			go drainListener.AcceptConnections()

			testThatDrainIsReachable(syslogDrainAddress, drainListener)

			appName = generator.PrefixedRandomName("CATS-APP-")

			Eventually(cf.Cf("push", appName, "-p", assets.NewAssets().RubySimple, "-d", config.AppsDomain), CF_PUSH_TIMEOUT).Should(Exit(0), "Failed to push app")

			syslogDrainURL := "syslog://" + syslogDrainAddress
			serviceName = "service-" + generator.RandomName()

			Eventually(cf.Cf("cups", serviceName, "-l", syslogDrainURL), DEFAULT_TIMEOUT).Should(Exit(0), "Failed to create syslog drain service")
			Eventually(cf.Cf("bind-service", appName, serviceName), DEFAULT_TIMEOUT).Should(Exit(0), "Failed to bind service")
		})

		AfterEach(func() {
			Eventually(cf.Cf("delete", appName, "-f"), DEFAULT_TIMEOUT).Should(Exit(0), "Failed to delete app")
			if serviceName != "" {
				Eventually(cf.Cf("delete-service", serviceName, "-f"), DEFAULT_TIMEOUT).Should(Exit(0), "Failed to delete service")
			}

			Eventually(cf.Cf("delete-orphaned-routes", "-f"), CF_PUSH_TIMEOUT).Should(Exit(0), "Failed to delete orphaned routes")

			drainListener.Stop()
		})
import (
	"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gbytes"
	. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Getting instance information", func() {
	var appName string

	BeforeEach(func() {
		appName = generator.RandomName()

		Eventually(cf.Cf("push", appName, "-p", helpers.NewAssets().HelloWorld, "--no-start", "-b=ruby_buildpack"), CF_PUSH_TIMEOUT).Should(Exit(0))
		Eventually(cf.Cf("set-env", appName, "CF_DIEGO_RUN_BETA", "true"), DEFAULT_TIMEOUT).Should(Exit(0))

		Eventually(cf.Cf("scale", appName, "-i", "3"), DEFAULT_TIMEOUT).Should(Exit(0))
		Eventually(cf.Cf("start", appName), CF_PUSH_TIMEOUT).Should(Exit(0))
	})

	AfterEach(func() {
		Eventually(cf.Cf("delete", appName, "-f"), DEFAULT_TIMEOUT).Should(Exit(0))
	})

	It("Retrieves instance information for cf app", func() {
		app := cf.Cf("app", appName).Wait(DEFAULT_TIMEOUT)
		Expect(app).To(Exit(0))
	"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Recursive Delete", func() {
	var broker ServiceBroker
	var orgName string

	BeforeEach(func() {
		broker = NewServiceBroker(generator.RandomName(), assets.NewAssets().ServiceBroker, context, false)
		broker.Push()
		broker.Configure()
		broker.Create()
		broker.PublicizePlans()

		orgName = generator.RandomName()
		spaceName := generator.RandomName()
		appName := generator.RandomName()
		instanceName := generator.RandomName()

		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
			createOrg := cf.Cf("create-org", orgName).Wait(DEFAULT_TIMEOUT)
			Expect(createOrg).To(Exit(0), "failed to create org")

			createSpace := cf.Cf("create-space", spaceName, "-o", orgName).Wait(DEFAULT_TIMEOUT)
	var spaceName string

	curlRoute := func(hostName string, path string) string {
		uri := config.Protocol() + hostName + "." + domainName + path
		curlCmd := runner.Curl(uri)

		runner.NewCmdRunner(curlCmd, DEFAULT_TIMEOUT).Run()
		Expect(string(curlCmd.Err.Contents())).To(HaveLen(0))
		return string(curlCmd.Out.Contents())
	}

	BeforeEach(func() {
		orgName = context.RegularUserContext().Org
		spaceName = context.RegularUserContext().Space

		domainName = generator.RandomName() + "." + helpers.LoadConfig().AppsDomain
		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
			Expect(cf.Cf("create-shared-domain", domainName).Wait(CF_PUSH_TIMEOUT)).To(Exit(0))
		})

		appNameDora = generator.PrefixedRandomName("CATS-APP-")
		Expect(cf.Cf("push", appNameDora, "-m", "128M", "-p", assets.NewAssets().Dora, "-d", config.AppsDomain).Wait(CF_PUSH_TIMEOUT)).To(Exit(0))

		appNameSimple = generator.PrefixedRandomName("CATS-APP-")
		Expect(cf.Cf("push", appNameSimple, "-m", "128M", "-p", assets.NewAssets().HelloWorld, "-d", config.AppsDomain).Wait(CF_PUSH_TIMEOUT)).To(Exit(0))
	})

	AfterEach(func() {
		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
			Expect(cf.Cf("target", "-o", orgName).Wait(DEFAULT_TIMEOUT)).To(Exit(0))
			Expect(cf.Cf("delete-shared-domain", domainName, "-f").Wait(DEFAULT_TIMEOUT)).To(Exit(0))
	"github.com/cloudfoundry-incubator/cf-test-helpers/generator"
	"github.com/cloudfoundry-incubator/cf-test-helpers/runner"
	"github.com/cloudfoundry/cf-acceptance-tests/helpers/assets"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	. "github.com/onsi/gomega/gexec"
)

var _ = Describe("Recursive Delete", func() {
	var broker ServiceBroker
	var orgName string
	var quotaName string

	BeforeEach(func() {
		broker = NewServiceBroker(generator.RandomName(), assets.NewAssets().ServiceBroker, context, false)
		broker.Push()
		broker.Configure()
		broker.Create()
		broker.PublicizePlans()

		orgName = generator.RandomName()
		quotaName = generator.RandomName() + "-recursive-delete"
		spaceName := generator.RandomName()
		appName := generator.RandomName()
		instanceName := generator.RandomName()

		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {

			runner.NewCmdRunner(cf.Cf("create-quota", quotaName, "-m", "10G", "-r", "1000", "-s", "5"), context.ShortTimeout()).Run()
		curlResponse = helpers.CurlApp(clientAppName, fmt.Sprintf("/curl/%s/%d", privateHost, privatePort))
		json.Unmarshal([]byte(curlResponse), &doraCurlResponse)
		Expect(doraCurlResponse.ReturnCode).ToNot(Equal(0))

		By("Applying security group")
		rules := fmt.Sprintf(
			`[{"destination":"%s","ports":"%d","protocol":"tcp"},
        {"destination":"%s","ports":"%d","protocol":"tcp"}]`,
			privateHost, privatePort, containerIp, privatePort)

		file, _ := ioutil.TempFile(os.TempDir(), "CATS-sg-rules")
		defer os.Remove(file.Name())
		file.WriteString(rules)

		rulesPath := file.Name()
		securityGroupName = fmt.Sprintf("CATS-SG-%s", generator.RandomName())

		cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
			Expect(cf.Cf("create-security-group", securityGroupName, rulesPath).Wait(DEFAULT_TIMEOUT)).To(Exit(0))
			Expect(
				cf.Cf("bind-security-group",
					securityGroupName,
					context.RegularUserContext().Org,
					context.RegularUserContext().Space).Wait(DEFAULT_TIMEOUT)).To(Exit(0))
		})
		defer func() {
			cf.AsUser(context.AdminUserContext(), DEFAULT_TIMEOUT, func() {
				Expect(cf.Cf("delete-security-group", securityGroupName, "-f").Wait(DEFAULT_TIMEOUT)).To(Exit(0))
			})
		}()
func TestDeploy(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Deploy Suite")
}

var (
	goPath string
	config helpers.Config

	bosh *helpers.Bosh

	etcdManifestGeneration string

	directorUUIDStub string

	etcdRelease          = fmt.Sprintf("etcd-%s", generator.RandomName())
	etcdDeployment       = etcdRelease
	etcdNameOverrideStub string
)

var _ = BeforeSuite(func() {
	goPath = helpers.SetupGoPath()
	gemfilePath := helpers.SetupFastBosh()
	config = helpers.LoadConfig()
	boshOperationTimeout := helpers.GetBoshOperationTimeout(config)
	bosh = helpers.NewBosh(gemfilePath, goPath, config.BoshTarget, boshOperationTimeout)

	etcdManifestGeneration = filepath.Join(goPath, "src", "acceptance-tests", "scripts", "generate_etcd_deployment_manifest")

	err := os.Chdir(goPath)
	Expect(err).ToNot(HaveOccurred())