Eventually(outputBuffer).Should(test_helpers.Say("Secret Key: ")) stdinWriter.Write([]byte("superserial\n")) Eventually(outputBuffer).Should(test_helpers.Say("Bucket Name [condenser-bucket]: ")) stdinWriter.Write([]byte("bhuket\n")) Eventually(commandFinishChan).Should(BeClosed()) Expect(fakeTargetVerifier.VerifyBlobTargetCallCount()).To(Equal(1)) host, port, accessKey, secretKey, bucketName := fakeTargetVerifier.VerifyBlobTargetArgsForCall(0) Expect(host).To(Equal("192.168.11.11")) Expect(port).To(Equal(uint16(8980))) Expect(accessKey).To(Equal("yaykey")) Expect(secretKey).To(Equal("superserial")) Expect(bucketName).To(Equal("bhuket")) blobTarget := config.BlobTarget() Expect(outputBuffer).To(test_helpers.Say("Blob Location Set")) Expect(blobTarget.TargetHost).To(Equal("192.168.11.11")) Expect(blobTarget.TargetPort).To(Equal(uint16(8980))) Expect(blobTarget.AccessKey).To(Equal("yaykey")) Expect(blobTarget.SecretKey).To(Equal("superserial")) }) It("sets the blob target and credentials using the default bucket name", func() { fakeTargetVerifier.VerifyBlobTargetReturns(true, nil) commandFinishChan := test_helpers.AsyncExecuteCommandWithArgs(targetBlobCommand, []string{"192.168.11.11:8980"}) Eventually(outputBuffer).Should(test_helpers.Say("Access Key: ")) stdinWriter.Write([]byte("yaykey\n")) Eventually(outputBuffer).Should(test_helpers.Say("Secret Key: "))
httpHeader := http.Header{ "Content-Type": []string{"application/xml"}, } fakeServer.AppendHandlers(ghttp.CombineHandlers( ghttp.VerifyRequest("GET", "/bucket/"), ghttp.RespondWithPtr(&statusCode, &responseBody, httpHeader), )) }) It("returns ok=true if able to connect and auth and it exists", func() { statusCode = http.StatusOK responseBody = `<?xml version="1.0" encoding="UTF-8"?><ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>x</ID><DisplayName>x</DisplayName></Owner><Buckets><Bucket><Name>bucket</Name><CreationDate>2015-06-11T16:50:43.000Z</CreationDate></Bucket></Buckets></ListAllMyBucketsResult>` ok, err := targetVerifier.VerifyBlobTarget(config.BlobTarget().TargetHost, config.BlobTarget().TargetPort, "V8GDQFR_VDOGM55IV8OH", "Wv_kltnl98hNWNdNwyQPYnFhK4gVPTxVS3NNMg==", "bucket") Expect(ok).To(BeTrue()) Expect(err).ToNot(HaveOccurred()) Expect(fakeServer.ReceivedRequests()).To(HaveLen(1)) }) It("returns ok=false if able to connect but can't auth", func() { statusCode = http.StatusForbidden ok, err := targetVerifier.VerifyBlobTarget(config.BlobTarget().TargetHost, config.BlobTarget().TargetPort, "V8GDQFR_VDOGM55IV8OH", "Wv_kltnl98hNWNdNwyQPYnFhK4gVPTxVS3NNMg==", "bucket") Expect(ok).To(BeFalse()) Expect(err).To(MatchError("unauthorized")) Expect(fakeServer.ReceivedRequests()).To(HaveLen(1)) })
func cliCommands(ltcConfigRoot string, exitHandler exit_handler.ExitHandler, config *config.Config, logger lager.Logger, targetVerifier target_verifier.TargetVerifier, ui terminal.UI) []cli.Command { receptorClient := receptor.NewClient(config.Receptor()) noaaConsumer := noaa.NewConsumer(LoggregatorUrl(config.Loggregator()), nil, nil) appRunner := app_runner.New(receptorClient, config.Target()) clock := clock.NewClock() logReader := logs.NewLogReader(noaaConsumer) tailedLogsOutputter := console_tailed_logs_outputter.NewConsoleTailedLogsOutputter(ui, logReader) taskExaminer := task_examiner.New(receptorClient) taskExaminerCommandFactory := task_examiner_command_factory.NewTaskExaminerCommandFactory(taskExaminer, ui, exitHandler) taskRunner := task_runner.New(receptorClient, taskExaminer) taskRunnerCommandFactory := task_runner_command_factory.NewTaskRunnerCommandFactory(taskRunner, ui, exitHandler) appExaminer := app_examiner.New(receptorClient, app_examiner.NewNoaaConsumer(noaaConsumer)) graphicalVisualizer := graphical.NewGraphicalVisualizer(appExaminer) appExaminerCommandFactory := app_examiner_command_factory.NewAppExaminerCommandFactory(appExaminer, ui, clock, exitHandler, graphicalVisualizer, taskExaminer) appRunnerCommandFactoryConfig := app_runner_command_factory.AppRunnerCommandFactoryConfig{ AppRunner: appRunner, AppExaminer: appExaminer, UI: ui, Domain: config.Target(), Env: os.Environ(), Clock: clock, Logger: logger, TailedLogsOutputter: tailedLogsOutputter, ExitHandler: exitHandler, } appRunnerCommandFactory := app_runner_command_factory.NewAppRunnerCommandFactory(appRunnerCommandFactoryConfig) dockerRunnerCommandFactoryConfig := docker_runner_command_factory.DockerRunnerCommandFactoryConfig{ AppRunner: appRunner, AppExaminer: appExaminer, UI: ui, Domain: config.Target(), Env: os.Environ(), Clock: clock, Logger: logger, ExitHandler: exitHandler, TailedLogsOutputter: tailedLogsOutputter, DockerMetadataFetcher: docker_metadata_fetcher.New(docker_metadata_fetcher.NewDockerSessionFactory()), } dockerRunnerCommandFactory := docker_runner_command_factory.NewDockerRunnerCommandFactory(dockerRunnerCommandFactoryConfig) logsCommandFactory := logs_command_factory.NewLogsCommandFactory(appExaminer, ui, tailedLogsOutputter, exitHandler) configCommandFactory := config_command_factory.NewConfigCommandFactory(config, ui, targetVerifier, exitHandler) testRunner := integration_test.NewIntegrationTestRunner(config, ltcConfigRoot) integrationTestCommandFactory := integration_test_command_factory.NewIntegrationTestCommandFactory(testRunner) s3Auth := aws.Auth{ AccessKey: config.BlobTarget().AccessKey, SecretKey: config.BlobTarget().SecretKey, } s3S3 := s3.New(s3Auth, awsRegion, &http.Client{ Transport: &http.Transport{ Proxy: config.BlobTarget().Proxy(), Dial: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, }, }) blobStore := blob_store.NewBlobStore(config, s3S3) blobBucket := blobStore.Bucket(config.BlobTarget().BucketName) dropletRunner := droplet_runner.New(appRunner, taskRunner, config, blobStore, blobBucket, targetVerifier, appExaminer) cfIgnore := cf_ignore.New() dropletRunnerCommandFactory := droplet_runner_command_factory.NewDropletRunnerCommandFactory(*appRunnerCommandFactory, taskExaminer, dropletRunner, cfIgnore) helpCommand := cli.Command{ Name: "help", Aliases: []string{"h"}, Usage: "Shows a list of commands or help for one command", Description: "ltc help", Action: defaultAction, } return []cli.Command{ appExaminerCommandFactory.MakeCellsCommand(), dockerRunnerCommandFactory.MakeCreateAppCommand(), appRunnerCommandFactory.MakeSubmitLrpCommand(), logsCommandFactory.MakeDebugLogsCommand(), appExaminerCommandFactory.MakeListAppCommand(), logsCommandFactory.MakeLogsCommand(), appRunnerCommandFactory.MakeRemoveAppCommand(), appRunnerCommandFactory.MakeScaleAppCommand(), appExaminerCommandFactory.MakeStatusCommand(), taskRunnerCommandFactory.MakeSubmitTaskCommand(), configCommandFactory.MakeTargetCommand(), configCommandFactory.MakeTargetBlobCommand(), taskExaminerCommandFactory.MakeTaskCommand(), taskRunnerCommandFactory.MakeDeleteTaskCommand(), taskRunnerCommandFactory.MakeCancelTaskCommand(), integrationTestCommandFactory.MakeIntegrationTestCommand(), appRunnerCommandFactory.MakeUpdateRoutesCommand(), appExaminerCommandFactory.MakeVisualizeCommand(), dropletRunnerCommandFactory.MakeBuildDropletCommand(), dropletRunnerCommandFactory.MakeListDropletsCommand(), dropletRunnerCommandFactory.MakeLaunchDropletCommand(), dropletRunnerCommandFactory.MakeRemoveDropletCommand(), helpCommand, } }
BeforeEach(func() { fakeServer = ghttp.NewServer() config = config_package.New(persister.NewMemPersister()) fakeServerURL, err := url.Parse(fakeServer.URL()) Expect(err).NotTo(HaveOccurred()) proxyHostArr := strings.Split(fakeServerURL.Host, ":") Expect(proxyHostArr).To(HaveLen(2)) proxyHostPort, err := strconv.Atoi(proxyHostArr[1]) Expect(err).NotTo(HaveOccurred()) config.SetBlobTarget(proxyHostArr[0], uint16(proxyHostPort), "V8GDQFR_VDOGM55IV8OH", "Wv_kltnl98hNWNdNwyQPYnFhK4gVPTxVS3NNMg==", "buck") httpClient = &http.Client{ Transport: &http.Transport{ Proxy: config.BlobTarget().Proxy(), Dial: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, }).Dial, TLSHandshakeTimeout: 10 * time.Second, }, } s3Auth := aws.Auth{ AccessKey: config.BlobTarget().AccessKey, SecretKey: config.BlobTarget().SecretKey, } s3S3 := s3.New(s3Auth, awsRegion, httpClient) s3S3.AttemptStrategy = aws.AttemptStrategy{}
}) It("returns errors from loading the config", func() { testConfig = config.New(&fakePersister{err: errors.New("Error")}) err := testConfig.Load() Expect(err).To(MatchError("Error")) }) }) Describe("TargetBlob", func() { It("sets the blob target", func() { testConfig.SetBlobTarget("s3-compatible-store", 7474, "NUYP3C_MBM-WDDWYKIUN", "Nb5vjT2V-ZX0O0s00xURSsg2Se0w-bmX40IQNg4==", "the-bucket") blobTarget := testConfig.BlobTarget() Expect(blobTarget.TargetHost).To(Equal("s3-compatible-store")) Expect(blobTarget.TargetPort).To(Equal(uint16(7474))) Expect(blobTarget.AccessKey).To(Equal("NUYP3C_MBM-WDDWYKIUN")) Expect(blobTarget.SecretKey).To(Equal("Nb5vjT2V-ZX0O0s00xURSsg2Se0w-bmX40IQNg4==")) Expect(blobTarget.BucketName).To(Equal("the-bucket")) }) }) Describe("BlobTargetInfo", func() { var blobTargetInfo config.BlobTargetInfo Describe("Proxy", func() { It("returns the proxy func", func() { blobTargetInfo = config.BlobTargetInfo{ TargetHost: "success",
accessKey = "V8GDQFR_VDOGM55IV8OH" secretKey = "Wv_kltnl98hNWNdNwyQPYnFhK4gVPTxVS3NNMg==" bucketName = "BuCKeTHeaD" ) var ( config *config_package.Config fakeServer *ghttp.Server targetVerifier target_verifier.TargetVerifier statusCode int responseBody string ) verifyBlobTarget := func() (bool, error) { return targetVerifier.VerifyBlobTarget( config.BlobTarget().TargetHost, config.BlobTarget().TargetPort, config.BlobTarget().AccessKey, config.BlobTarget().SecretKey, bucketName, ) } BeforeEach(func() { targetVerifier = target_verifier.New(func(string) receptor.Client { return &fake_receptor.FakeClient{} }) fakeServer = ghttp.NewServer() config = config_package.New(persister.NewMemPersister()) proxyURL, err := url.Parse(fakeServer.URL())