AfterEach(func() {
			authServer.Close()
			server.Close()
		})

		It("registers a route to the routing api", func() {
			command := buildCommand("register", flags, []string{`[{"route":"zak.com","port":3,"ip":"4"}]`})

			server.SetHandler(0,
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/v1/routes"),
					ghttp.VerifyJSONRepresenting([]map[string]interface{}{
						{
							"route":    "zak.com",
							"port":     3,
							"ip":       "4",
							"ttl":      0,
							"log_guid": "",
						},
					}),
					ghttp.RespondWithJSONEncoded(http.StatusOK, nil),
				),
			)

			session := routeRegistrar(command...)

			Eventually(session, "2s").Should(Exit(0))
			Expect(server.ReceivedRequests()).To(HaveLen(1))
		})

		It("registers multiple routes to the routing api", func() {
Example #2
0
			})
			Context("when SkipTLSVerify is false", func() {
				It("should return an error", func() {
					// hide tls error
					tlsServer.HTTPTestServer.Config.ErrorLog = log.New(&bytes.Buffer{}, "", 0)
					c.SkipTLSVerify = false

					err := c.Get(route, &responseStruct)
					Expect(err).To(MatchError(HaveSuffix("x509: certificate signed by unknown authority")))
				})
			})
		})

		Context("when the server responds with malformed JSON", func() {
			It("should return an error", func() {
				server.SetHandler(0, ghttp.RespondWith(http.StatusOK, `x`))

				err := c.Get(route, &responseStruct)
				Expect(err).To(MatchError(HavePrefix("server returned malformed JSON")))
			})
		})

		Context("when the server responds with a non-2xx status", func() {
			It("should return an error", func() {
				server.SetHandler(0, ghttp.RespondWith(http.StatusTeapot, `{}`))

				err := c.Get(route, &responseStruct)
				Expect(err).To(MatchError(HavePrefix("server returned status code 418")))
			})
		})
	})
					expectedLayerNum--

					return nil
				}

				imageID, err := fetcher.Fetch("some-repo", "some-tag")
				Ω(err).ShouldNot(HaveOccurred())

				Ω(imageID).Should(Equal("id-1"))
			})

			Context("when the first endpoint fails", func() {
				BeforeEach(func() {
					endpoint1.SetHandler(1, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
						w.WriteHeader(500)
					}))

					endpoint2.AppendHandlers(
						ghttp.CombineHandlers(
							ghttp.VerifyRequest("GET", "/v1/images/id-1/ancestry"),
							http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
								w.Write([]byte(`["layer-1", "layer-2", "layer-3"]`))
							}),
						),
					)

					setupSuccessfulFetch(endpoint2)
				})

				It("retries with the next endpoint", func() {
Example #4
0
		})

		Context("when the authentication endpoint is malformed", func() {
			BeforeEach(func() {
				config.SetAuthenticationEndpoint(":not-well-formed")
			})

			It("returns an error", func() {
				_, err := authRepo.Authorize("auth-token")
				Expect(err).To(HaveOccurred())
			})
		})

		Context("when the authorization server does not return a redirect", func() {
			BeforeEach(func() {
				uaaServer.SetHandler(0, ghttp.RespondWith(http.StatusOK, ``))
			})

			It("returns an error", func() {
				_, err := authRepo.Authorize("auth-token")
				Expect(err).To(HaveOccurred())
				Expect(err.Error()).To(Equal("Authorization server did not redirect with one time code"))
			})
		})

		Context("when the authorization server does not return a redirect", func() {
			BeforeEach(func() {
				config.SetAuthenticationEndpoint("https://127.0.0.1:1")
			})

			It("returns an error", func() {
Example #5
0
		It("tries to create the app", func() {
			repo.Create(appParams)
			Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
		})

		Context("when the create succeeds", func() {
			BeforeEach(func() {
				h := ccServer.GetHandler(0)
				ccServer.SetHandler(0,
					ghttp.CombineHandlers(
						h,
						ghttp.RespondWith(http.StatusCreated, `{
							"metadata": {
									"guid": "my-cool-app-guid"
							},
							"entity": {
									"name": "my-cool-app"
							}
					}`),
					),
				)
			})

			It("returns the application", func() {
				createdApp, err := repo.Create(appParams)
				Expect(err).NotTo(HaveOccurred())

				app := models.Application{}
				app.Name = "my-cool-app"
				app.GUID = "my-cool-app-guid"
			})
		})

		Context("when downloading the gzipped box fails", func() {
			It("should return a useful error", func() {
				fakeDownloadServer.HTTPTestServer.Close()
				_, err := atlasClient.GetAMIs("someuser/somebox", "some-special-version")
				Expect(err).To(MatchError(HavePrefix("error downloading box: Get")))
			})
		})

		Context("when unzipping the box fails", func() {
			It("should return a useful error", func() {
				fakeDownloadServer.SetHandler(0,
					ghttp.CombineHandlers(
						ghttp.RespondWith(http.StatusOK, []byte("not gzipped")),
					),
				)
				_, err := atlasClient.GetAMIs("someuser/somebox", "some-special-version")
				Expect(err).To(MatchError("error gunzipping box: gzip: invalid header"))
			})
		})

		Context("when the box doesn't include AMI definitions", func() {
			It("should return a useful error", func() {
				gzippedMsg, _ := base64.StdEncoding.DecodeString("H4sIADxwvVYAA8vI5AIAenpv7QMAAAA=")
				fakeDownloadServer.SetHandler(0,
					ghttp.CombineHandlers(
						ghttp.RespondWith(http.StatusOK, gzippedMsg),
					),
				)
Example #7
0
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/gohan/v0.1/schemas"),
					ghttp.RespondWithJSONEncoded(200, getSchemasResponse()),
				),
			)
		})

		It("Should create GohanClientCLI instance successfully", func() {
			opts, _ := NewOptsFromEnv()
			gohanClientCLI, err := NewGohanClientCLI(opts)
			Expect(err).ToNot(HaveOccurred())
			Expect(gohanClientCLI).ToNot(BeNil())
		})

		It("Should show error - authentication failed", func() {
			server.SetHandler(0, ghttp.RespondWith(401, nil))
			opts, _ := NewOptsFromEnv()
			gohanClientCLI, err := NewGohanClientCLI(opts)
			Expect(gohanClientCLI).To(BeNil())
			Expect(err).To(HaveOccurred())
		})

		It("Should show error - getting endpoint url failed", func() {
			os.Setenv("GOHAN_SERVICE_NAME", "wrong")
			opts, _ := NewOptsFromEnv()
			gohanClientCLI, err := NewGohanClientCLI(opts)
			Expect(gohanClientCLI).To(BeNil())
			Expect(err).To(HaveOccurred())
		})

		It("Should show error - getting schemas failed", func() {
Example #8
0
				)
			})

			It("tries to create a route", func() {
				repo.CreateInSpace("", "", "my-domain-guid", "my-space-guid", 0, false)
				Expect(ccServer.ReceivedRequests()).To(HaveLen(1))
			})

			Context("when creating the route succeeds", func() {
				BeforeEach(func() {
					h := ccServer.GetHandler(0)
					ccServer.SetHandler(0, ghttp.CombineHandlers(
						h,
						ghttp.RespondWith(http.StatusCreated, `
								{
									"metadata": { "guid": "my-route-guid" },
									"entity": { "host": "my-cool-app" }
								}
							`),
					))
				})

				It("returns the created route", func() {
					createdRoute, err := repo.CreateInSpace("", "", "my-domain-guid", "my-space-guid", 0, false)
					Expect(err).NotTo(HaveOccurred())
					Expect(createdRoute.GUID).To(Equal("my-route-guid"))
				})
			})
		})

		Context("when a host is given", func() {
				header := make(http.Header)
				header.Add("Content-Type", "application/json")

				cpumonitorServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/start"),
						ghttp.RespondWith(http.StatusOK, nil),
					),
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/stop"),
						ghttp.RespondWith(http.StatusOK, cpuMonitorData, header),
					),
				)

				runnerArgs.CPUMonitorURL = cpumonitorServer.URL()
				testS3Server.SetHandler(1, bodyTestHandler)
				testS3Server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyContentType("image/png"),
						bodyTestHandler,
					),
				)
			})
			AfterEach(func() {
				cpumonitorServer.Close()
			})
			It("calls cpumonitor server start & stop endpoints", func() {
				Eventually(process.Wait(), "5s").Should(Receive())
				Expect(cpumonitorServer.ReceivedRequests()).To(HaveLen(2))
			})
Example #10
0
		})
	})

	Context("when fetching a layer fails", func() {
		Context("when the image manifest contains an invalid layer digest", func() {
			BeforeEach(func() {
				setupSuccessfulV2Fetch(server, false)
				server.SetHandler(0, http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
					w.Write([]byte(`
					{
					   "name":"some-repo",
					   "tag":"some-tag",
					   "fsLayers":[
						  {
							 "blobSum":"barry"
						  }
					   ],
					   "history":[
						  {
							 "v1Compatibility": "{\"id\":\"banana-pie-2\"}"
						  }
					   ]
					}`))
				}))
			})

			It("returns an error", func() {
				_, err := fetcher.Fetch(fetchRequest)
				Expect(err).To(MatchError(ContainSubstring("invalid checksum digest format")))
			})
		})
Example #11
0
				BeforeEach(func() {
					responseCode = http.StatusInternalServerError
					expectedResponse = &authenticators.AppSSHResponse{}
				})

				It("fails to authenticate", func() {
					Expect(err).To(Equal(authenticators.FetchAppFailedErr))
					Expect(fakeCC.ReceivedRequests()).To(HaveLen(1))
				})
			})

			Context("and the response cannot be parsed", func() {
				BeforeEach(func() {
					fakeCC.SetHandler(0, ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", "/internal/apps/app-guid/ssh_access"),
						ghttp.VerifyHeader(http.Header{"Authorization": []string{"bearer token"}}),
						ghttp.RespondWith(http.StatusOK, "{{"),
					))
				})

				It("fails to authenticate", func() {
					Expect(err).To(Equal(authenticators.InvalidCCResponse))
					Expect(fakeCC.ReceivedRequests()).To(HaveLen(1))
				})
			})

			Context("and fetching the ssh_access from cc times out", func() {
				BeforeEach(func() {
					ccTempClientTimeout := ccClientTimeout
					fakeCC.SetHandler(0, func(w http.ResponseWriter, req *http.Request) {
						time.Sleep(ccTempClientTimeout * 2)