func (h *RouterGroupsHandler) ListRouterGroups(w http.ResponseWriter, req *http.Request) {
	log := h.logger.Session("list-router-groups")
	log.Debug("started")
	defer log.Debug("completed")

	err := h.tokenValidator.DecodeToken(req.Header.Get("Authorization"), RouterGroupsReadScope)
	if err != nil {
		handleUnauthorizedError(w, err, log)
		return
	}

	defaultRouterGroup := helpers.GetDefaultRouterGroup()

	jsonBytes, err := json.Marshal([]db.RouterGroup{defaultRouterGroup})
	if err != nil {
		log.Error("failed-to-marshal", err)
	}
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(http.StatusOK)
	w.Write(jsonBytes)
	w.Header().Set("Content-Length", strconv.Itoa(len(jsonBytes)))
}
Ejemplo n.º 2
0
				Expect(log).To(ContainSubstring("RESPONSE: "))
				Expect(log).To(ContainSubstring("HTTP/1.1 400 Bad Request"))
				Expect(log).NotTo(ContainSubstring(string(expectedBody)))
			})
		})
	})
	Context("RouterGroups", func() {
		var (
			routerGroups []db.RouterGroup
			err          error
			routerGroup1 db.RouterGroup
		)

		BeforeEach(func() {
			routerGroup1 = helpers.GetDefaultRouterGroup()
		})

		JustBeforeEach(func() {
			routerGroups, err = client.RouterGroups()
		})

		Context("when the server returns a valid response", func() {
			BeforeEach(func() {
				data, _ := json.Marshal([]db.RouterGroup{routerGroup1})

				server.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", TCP_ROUTER_GROUPS_API_URL),
						ghttp.RespondWith(http.StatusOK, data),
					),
Ejemplo n.º 3
0
							return logger.Logs()[0].Data["error"].(string)
						} else {
							return ""
						}
					}).Should(ContainSubstring("beep boop, self destruct mode engaged"))
				})
			})
		})

		Context("unregistration", func() {
			It("unregisters the routing api when a SIGTERM is received", func() {
				process.Signal(syscall.SIGTERM)
				Eventually(database.DeleteRouteCallCount).Should(Equal(1))
				Eventually(func() db.Route {
					return database.DeleteRouteArgsForCall(0)
				}).Should(Equal(route))
			})
		})
	})

	Describe("GetDefaultRouterGroup", func() {
		It("returns default router group", func() {
			Expect(helpers.GetDefaultRouterGroup()).To(Equal(db.RouterGroup{
				Name:     "default_tcp",
				Features: []db.Feature{"tcp"},
				Guid:     "bad25cff-9332-48a6-8603-b619858e7992",
			}))
		})
	})
})
Ejemplo n.º 4
0
			var proc ifrit.Process

			BeforeEach(func() {
				routingAPIRunner := testrunner.New(routingAPIBinPath, routingAPIArgs)
				proc = ifrit.Invoke(routingAPIRunner)
			})

			AfterEach(func() {
				ginkgomon.Interrupt(proc)
			})

			It("returns router groups", func() {
				client := routing_api.NewClient(fmt.Sprintf("http://127.0.0.1:%d", routingAPIPort))
				routerGroups, err := client.RouterGroups()
				Expect(err).NotTo(HaveOccurred())
				Expect(routerGroups).To(Equal([]db.RouterGroup{helpers.GetDefaultRouterGroup()}))
			})
		})

		Context("when tcp routes create endpoint is invoked", func() {
			var (
				proc             ifrit.Process
				tcpRouteMapping1 db.TcpRouteMapping
				tcpRouteMapping2 db.TcpRouteMapping
			)

			BeforeEach(func() {
				routingAPIRunner := testrunner.New(routingAPIBinPath, routingAPIArgs)
				proc = ifrit.Invoke(routingAPIRunner)
			})