コード例 #1
0
ファイル: dataplane_test.go プロジェクト: iovisor/iomodules
	)
	BeforeEach(func() {
		fakeserver = ghttp.NewServer()
		dataplane = NewDataplane()
		Expect(dataplane).NotTo(BeNil())
		module = models.ModuleEntry{
			Id: "some-module-id",
		}
	})
	Describe("Init Dataplane", func() {
		var statusCode int
		It("Instantiates a dataplane object", func() {
			statusCode := http.StatusOK
			fakeserver.AppendHandlers(ghttp.CombineHandlers(
				ghttp.VerifyRequest("POST", "/modules/"),
				ghttp.RespondWithJSONEncodedPtr(&statusCode, &module),
			))
			err := dataplane.Init(fakeserver.URL())
			Expect(err).NotTo(HaveOccurred())
			Expect(dataplane.Id()).To(Equal("some-module-id"))
		})
		Context("When the post to server fails", func() {
			BeforeEach(func() {
				statusCode = http.StatusInternalServerError
				fakeserver.AppendHandlers(ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/modules/"),
					ghttp.RespondWithJSONEncodedPtr(&statusCode, &models.ModuleEntry{}),
				))
			})
			It("Returns an error", func() {
				err := dataplane.Init(fakeserver.URL())
コード例 #2
0
				},
				Gateway: net.ParseIP("192.168.1.1"),
				Routes: []types.Route{{
					Dst: net.IPNet{
						IP:   net.ParseIP("192.168.0.0"),
						Mask: net.CIDRMask(16, 32),
					},
					GW: net.ParseIP("192.168.1.1"),
				}},
			},
		}

		statusCode := http.StatusCreated
		server.RouteToHandler("POST", "/cni/add", ghttp.CombineHandlers(
			ghttp.VerifyHeaderKV("Content-Type", "application/json"),
			ghttp.RespondWithJSONEncodedPtr(&statusCode, &ipamResult),
		))
	})

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

	Describe("ADD", func() {
		It("returns IPAM data", func() {
			var err error
			var cmd *exec.Cmd
			cmd, err = buildCNICmdLight("ADD", netConfig, containerNSPath, containerID)
			Expect(err).NotTo(HaveOccurred())
			session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
			Expect(err).NotTo(HaveOccurred())
コード例 #3
0
		})
	})

	Describe("Token Acquisition", func() {
		var server *ghttp.Server
		var statusCode int
		var responseBody UAATokenResponse

		BeforeEach(func() {
			server = ghttp.NewTLSServer()
			url, _ = url.Parse(server.URL())
			server.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/oauth/token", "grant_type=client_credentials"),
					ghttp.VerifyBasicAuth("client_id", "client_secret"),
					ghttp.RespondWithJSONEncodedPtr(&statusCode, &responseBody),
				),
			)
			uaaCC, _ = New(url, true, "client_id", "client_secret")
		})

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

		Context("when the request is all good", func() {
			BeforeEach(func() {
				statusCode = http.StatusOK
				responseBody = UAATokenResponse{
					AccessToken: "test_token",
					TokenType:   "bearer",
コード例 #4
0
			metadata.UserReturns("cf:app-guid/1")
			password = []byte(expectedOneTimeCode)

			uaaTokenResponseCode = http.StatusOK
			uaaTokenResponse = &authenticators.UAAAuthTokenResponse{
				AccessToken: "exchanged-token",
				TokenType:   "bearer",
			}

			fakeUAA.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/oauth/token"),
					ghttp.VerifyBasicAuth("diego-ssh", "diego-ssh-secret-$\"^&'"),
					ghttp.VerifyFormKV("grant_type", "authorization_code"),
					ghttp.VerifyFormKV("code", expectedOneTimeCode),
					ghttp.RespondWithJSONEncodedPtr(&uaaTokenResponseCode, uaaTokenResponse),
				),
			)

			sshAccessResponseCode = http.StatusOK
			sshAccessResponse = &authenticators.AppSSHResponse{
				ProcessGuid: "app-guid-app-version",
			}

			fakeCC.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/internal/apps/app-guid/ssh_access/1"),
					ghttp.VerifyHeader(http.Header{"Authorization": []string{"bearer exchanged-token"}}),
					ghttp.RespondWithJSONEncodedPtr(&sshAccessResponseCode, sshAccessResponse),
				),
			)
コード例 #5
0
		server      *ghttp.Server
		command     *exec.Cmd
		deployments DeploymentResponse
	)

	BeforeEach(func() {
		server = ghttp.NewServer()
		statusCode := http.StatusOK
		server.AppendHandlers(
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/info"),
				ghttp.RespondWithJSONEncoded(statusCode, InfoResponse{}),
			),
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/deployments"),
				ghttp.RespondWithJSONEncodedPtr(&statusCode, &deployments),
			),
		)

		var err error
		config, err = ioutil.TempFile("", "bosh_pre_destroy")
		Expect(err).ToNot(HaveOccurred())

		configContents := fmt.Sprintf("---\ntarget: %s\n", server.URL())
		_, err = config.Write([]byte(configContents))
		Expect(err).ToNot(HaveOccurred())

		command = exec.Command("bundle", "exec", "./bosh_pre_destroy.rb")
		command.Env = append(os.Environ(), fmt.Sprintf("BOSH_CONFIG=%s", config.Name()))
	})
コード例 #6
0
ファイル: client_test.go プロジェクト: iovisor/iomodules
	})
	Describe("Endpoint APIs", func() {
		var endpoint models.EndpointEntry
		BeforeEach(func() {
			endpoint = models.EndpointEntry{
				Ip:    "some-ip",
				EpgId: "some-id",
			}
		})
		Describe("Add Endpoint", func() {
			It("Adds an endpoint to the server", func() {
				statusCode := http.StatusOK
				Expect(p).NotTo(BeNil())
				fakeserver.AppendHandlers(ghttp.CombineHandlers(
					ghttp.VerifyRequest("POST", "/endpoints/"),
					ghttp.RespondWithJSONEncodedPtr(&statusCode, &endpoint),
				))
				err := p.AddEndpoint(&endpoint)
				Expect(err).NotTo(HaveOccurred())
			})
		})
		Describe("Delete Endpoint", func() {
			It("Deletes an endpint from the server", func() {
				someId := "some-id"
				statusCode := http.StatusOK
				fakeserver.AppendHandlers(ghttp.CombineHandlers(
					ghttp.VerifyRequest("DELETE", "/endpoints/"+someId),
					ghttp.RespondWith(statusCode, ""),
				))
				err := p.DeleteEndpoint(someId)
				Expect(err).NotTo(HaveOccurred())
コード例 #7
0
			ipAddr, err := net.ResolveIPAddr("ip", "1.1.1.1")
			Expect(err).NotTo(HaveOccurred())
			metadata.RemoteAddrReturns(ipAddr)

			password = []byte("bearer token")

			expectedResponse = &authenticators.AppSSHResponse{
				ProcessGuid: "app-guid-app-version",
			}
			responseCode = http.StatusOK

			fakeCC.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("GET", "/internal/apps/app-guid/ssh_access"),
					ghttp.VerifyHeader(http.Header{"Authorization": []string{"bearer token"}}),
					ghttp.RespondWithJSONEncodedPtr(&responseCode, expectedResponse),
				),
			)

			expectedRoute = routes.SSHRoute{
				ContainerPort:   1111,
				PrivateKey:      "pem-encoded-key",
				HostFingerprint: "host-fingerprint",
				User:            "******",
				Password:        "******",
			}

			diegoSSHRoutePayload, err := json.Marshal(expectedRoute)
			Expect(err).NotTo(HaveOccurred())

			diegoSSHRouteMessage := json.RawMessage(diegoSSHRoutePayload)