}
}
+func (s *IntegrationSuite) TestRequestIDHeader(c *check.C) {
+ conn1 := s.testClusters["z1111"].Conn()
+ rootctx1, _, _ := s.testClusters["z1111"].RootClients()
+ _, ac1, _, _ := s.testClusters["z1111"].UserClients(rootctx1, c, conn1, "user@example.com", true)
+
+ tests := []struct {
+ path string
+ reqIdProvided bool
+ }{
+ {"/arvados/v1/container_requests", false},
+ {"/arvados/v1/container_requests", true},
+ {"/arvados/v1/links", false},
+ {"/arvados/v1/links", true},
+ }
+
+ for _, tt := range tests {
+ c.Log(c.TestName() + " " + tt.path)
+ req, err := http.NewRequest("GET", "https://"+ac1.APIHost+tt.path, nil)
+ c.Assert(err, check.IsNil)
+ customReqId := "abcdeG"
+ if !tt.reqIdProvided {
+ c.Assert(req.Header.Get("X-Request-Id"), check.Equals, "")
+ } else {
+ req.Header.Set("X-Request-Id", customReqId)
+ }
+ resp, err := ac1.Do(req)
+ c.Assert(err, check.IsNil)
+ c.Check(resp.StatusCode, check.Equals, http.StatusOK)
+ if !tt.reqIdProvided {
+ c.Check(resp.Header.Get("X-Request-Id"), check.Matches, "^req-[0-9a-zA-Z]{20}$")
+ } else {
+ c.Check(resp.Header.Get("X-Request-Id"), check.Equals, customReqId)
+ }
+ }
+}
+
// We test the direct access to the database
// normally an integration test would not have a database access, but in this case we need
// to test tokens that are secret, so there is no API response that will give them back
return selected
}
-func (rtr *router) sendResponse(w http.ResponseWriter, req *http.Request, resp interface{}, opts responseOptions, reqId string) {
+func (rtr *router) sendResponse(w http.ResponseWriter, req *http.Request, resp interface{}, opts responseOptions) {
var tmp map[string]interface{}
if resp, ok := resp.(http.Handler); ok {
return
}
- w.Header().Set("X-Request-Id", reqId)
+ w.Header().Set("X-Request-Id", req.Header.Get("X-Request-Id"))
err := rtr.transcode(resp, &tmp)
if err != nil {
rtr.sendError(w, err)
}
}
ctx := auth.NewContext(req.Context(), creds)
- var reqId string
- if reqId = req.Header.Get("X-Request-Id"); reqId == "" {
- reqIDGen := httpserver.IDGenerator{Prefix: "req-"}
- reqId = reqIDGen.Next()
- }
- ctx = arvados.ContextWithRequestID(ctx, reqId)
+ ctx = arvados.ContextWithRequestID(ctx, req.Header.Get("X-Request-Id"))
logger.WithFields(logrus.Fields{
"apiEndpoint": endpoint,
"apiOptsType": fmt.Sprintf("%T", opts),
rtr.sendError(w, err)
return
}
- rtr.sendResponse(w, req, resp, respOpts, reqId)
+ rtr.sendResponse(w, req, resp, respOpts)
})
}
c.Check(rr.Code, check.Equals, http.StatusOK)
}
-func (s *RouterIntegrationSuite) TestRequestIDHeader(c *check.C) {
- token := arvadostest.ActiveTokenV2
- req := (&testReq{
- method: "GET",
- path: "arvados/v1/collections/" + arvadostest.FooCollection,
- token: token,
- }).Request()
- rr := httptest.NewRecorder()
- s.rtr.ServeHTTP(rr, req)
- c.Check(rr.Code, check.Equals, http.StatusOK)
- c.Check(rr.Result().Header.Get("X-Request-Id"), check.Matches, "^req-[0-9a-zA-Z]{20}$")
-}
-
-func (s *RouterIntegrationSuite) TestRequestIDHeaderProvidedByClient(c *check.C) {
- token := arvadostest.ActiveTokenV2
- req := (&testReq{
- method: "GET",
- path: "arvados/v1/collections/" + arvadostest.FooCollection,
- token: token,
- header: http.Header{
- "X-Request-Id": []string{"abcdeG"},
- },
- }).Request()
- rr := httptest.NewRecorder()
- s.rtr.ServeHTTP(rr, req)
- c.Check(rr.Code, check.Equals, http.StatusOK)
- c.Check(rr.Result().Header.Get("X-Request-Id"), check.Equals, "abcdeG")
-}
-
func (s *RouterIntegrationSuite) TestRouteNotFound(c *check.C) {
token := arvadostest.ActiveTokenV2
req := (&testReq{