Exemple #1
0
func (f *FakeCC) newHandleStagingRequest() http.HandlerFunc {
	return ghttp.CombineHandlers(
		ghttp.VerifyRequest("POST", MatchRegexp("/internal/staging/(.*)/completed")),
		ghttp.VerifyBasicAuth(CC_USERNAME, CC_PASSWORD),
		http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			var msg cc_messages.StagingResponseForCC
			err := json.NewDecoder(r.Body).Decode(&msg)
			Expect(err).NotTo(HaveOccurred())
			r.Body.Close()
			f.lock.Lock()
			defer f.lock.Unlock()
			guid := strings.TrimSuffix(strings.TrimPrefix(r.URL.Path, "/internal/staging/"), "/completed")
			f.stagingGuids = append(f.stagingGuids, guid)
			f.stagingResponses = append(f.stagingResponses, msg)
		}),
		ghttp.RespondWithPtr(&f.stagingResponseStatusCode, &f.stagingResponseBody),
	)
}
		})
	})

	Describe("delete", func() {
		var (
			httpStatusCode              int
			fakeServer                  *ghttp.Server
			fakeServerURL, sanitizedURL string
		)

		BeforeEach(func() {
			httpStatusCode = http.StatusNoContent
			fakeServer = ghttp.NewServer()
			fakeServer.AppendHandlers(ghttp.CombineHandlers(
				ghttp.VerifyRequest("DELETE", "/blobs/path"),
				ghttp.RespondWithPtr(&httpStatusCode, nil),
				ghttp.VerifyBasicAuth("user", "pass"),
			))
			fakeServerURL = fmt.Sprintf("http://%s:%s@%s%s", "user", "pass", fakeServer.Addr(), "/blobs/path")
			sanitizedURL = fmt.Sprintf("http://%s%s", fakeServer.Addr(), "/blobs/path")
		})

		AfterEach(func() {
			fakeServer.Close()
		})

		It("does a DELETE to the DAV server to delete the file", func() {
			command := exec.Command(davtoolPath, "delete", fakeServerURL)
			session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())
			config = config_package.New(persister.NewMemPersister())
			proxyURL, err := url.Parse(fakeServer.URL())
			Expect(err).NotTo(HaveOccurred())
			proxyHostArr := strings.Split(proxyURL.Host, ":")
			Expect(proxyHostArr).To(HaveLen(2))
			proxyHostPort, _ := strconv.Atoi(proxyHostArr[1])
			config.SetBlobTarget(proxyHostArr[0], uint16(proxyHostPort), "V8GDQFR_VDOGM55IV8OH", "Wv_kltnl98hNWNdNwyQPYnFhK4gVPTxVS3NNMg==", "bucket")

			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() {
Exemple #4
0
	BeforeSuite(func() {
		var err error
		s3downloaderPath, err = gexec.Build("github.com/cloudfoundry-incubator/lattice/cell-helpers/s3downloader")
		Expect(err).ToNot(HaveOccurred())
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	BeforeEach(func() {
		fakeServer = ghttp.NewServer()
		fakeServer.AppendHandlers(ghttp.CombineHandlers(
			ghttp.VerifyRequest("GET", "/bucket/key"),
			ghttp.RespondWithPtr(&httpStatusCode, &httpResponse),
			func(w http.ResponseWriter, req *http.Request) {
				auth, ok := req.Header[http.CanonicalHeaderKey("Authorization")]
				Expect(ok).To(BeTrue())
				Expect(auth).To(ConsistOf(HavePrefix("AWS access:")))
			},
		))
	})

	AfterEach(func() {
		fakeServer.Close()
	})

	It("does a GET to the S3 server to download the url", func() {
		httpStatusCode = 200
		httpResponse = "xyz"
	Describe("UploadDroplet", func() {
		var (
			timeClicker chan time.Time
			startTime   time.Time
			endTime     time.Time
		)

		BeforeEach(func() {
			var err error

			timeClicker = make(chan time.Time, 4)
			fakeCloudController.AppendHandlers(ghttp.CombineHandlers(
				ghttp.VerifyRequest("POST", "/staging/droplet/app-guid/upload"),
				ghttp.VerifyBasicAuth("bob", "password"),
				ghttp.RespondWithPtr(&postStatusCode, &postResponseBody),
				func(w http.ResponseWriter, r *http.Request) {
					uploadedHeaders = r.Header
					file, fileHeader, err := r.FormFile(ccclient.FormField)
					Expect(err).NotTo(HaveOccurred())
					uploadedBytes, err = ioutil.ReadAll(file)
					Expect(err).NotTo(HaveOccurred())
					uploadedFileName = fileHeader.Filename
					Expect(r.ContentLength).To(BeNumerically(">", len(uploadedBytes)))
				},
			))

			uploadURL, err = url.Parse(fakeCloudController.URL())
			Expect(err).NotTo(HaveOccurred())

			uploadURL.User = url.UserPassword("bob", "password")
Exemple #6
0
	BeforeSuite(func() {
		var err error
		s3uploaderPath, err = gexec.Build("github.com/cloudfoundry-incubator/lattice/s3uploader")
		Expect(err).ToNot(HaveOccurred())
	})

	AfterSuite(func() {
		gexec.CleanupBuildArtifacts()
	})

	BeforeEach(func() {
		fakeServer = ghttp.NewServer()
		var emptyResponse = ""
		fakeServer.AppendHandlers(ghttp.CombineHandlers(
			ghttp.VerifyRequest("PUT", ContainSubstring("/bucket/")),
			ghttp.RespondWithPtr(&httpStatusCode, &emptyResponse),
			func(w http.ResponseWriter, req *http.Request) {
				auth, ok := req.Header[http.CanonicalHeaderKey("Authorization")]
				Expect(ok).To(BeTrue())
				Expect(auth).To(ConsistOf(HavePrefix("AWS access:")))
			},
		))
	})

	AfterEach(func() {
		fakeServer.Close()
	})

	It("does a PUT to the S3 server to upload the file", func() {
		httpStatusCode = 200