pkg/api: Check errors (#19657)

* pkg/api: Check errors
* pkg/api: Remove unused function HashEmail
This commit is contained in:
Arve Knudsen
2019-10-08 18:57:53 +02:00
committed by GitHub
parent dabc848e11
commit 0a2d5e16dd
12 changed files with 86 additions and 45 deletions

View File

@ -96,10 +96,12 @@ func (proxy *DataSourceProxy) HandleRequest() {
proxy.addTraceFromHeaderValue(span, "X-Panel-Id", "panel_id")
proxy.addTraceFromHeaderValue(span, "X-Dashboard-Id", "dashboard_id")
opentracing.GlobalTracer().Inject(
if err := opentracing.GlobalTracer().Inject(
span.Context(),
opentracing.HTTPHeaders,
opentracing.HTTPHeadersCarrier(proxy.ctx.Req.Request.Header))
opentracing.HTTPHeadersCarrier(proxy.ctx.Req.Request.Header)); err != nil {
logger.Error("Failed to inject span context instance", "err", err)
}
originalSetCookie := proxy.ctx.Resp.Header().Get("Set-Cookie")

View File

@ -500,10 +500,11 @@ func TestDSRouteRule(t *testing.T) {
})
Convey("HandleRequest()", func() {
var writeErr error
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, &http.Cookie{Name: "flavor", Value: "chocolateChip"})
w.WriteHeader(200)
w.Write([]byte("I am the backend"))
_, writeErr = w.Write([]byte("I am the backend"))
}))
defer backend.Close()
@ -533,19 +534,28 @@ func TestDSRouteRule(t *testing.T) {
}
Convey("When response header Set-Cookie is not set should remove proxied Set-Cookie header", func() {
writeErr = nil
ctx := setupCtx(nil)
proxy := NewDataSourceProxy(ds, plugin, ctx, "/render", &setting.Cfg{})
proxy.HandleRequest()
So(writeErr, ShouldBeNil)
So(proxy.ctx.Resp.Header().Get("Set-Cookie"), ShouldBeEmpty)
})
Convey("When response header Set-Cookie is set should remove proxied Set-Cookie header and restore the original Set-Cookie header", func() {
writeErr = nil
ctx := setupCtx(func(w http.ResponseWriter) {
w.Header().Set("Set-Cookie", "important_cookie=important_value")
})
proxy := NewDataSourceProxy(ds, plugin, ctx, "/render", &setting.Cfg{})
proxy.HandleRequest()
So(proxy.ctx.Resp.Header().Get("Set-Cookie"), ShouldEqual, "important_cookie=important_value")
So(writeErr, ShouldBeNil)
So(proxy.ctx.Resp.Header().Get("Set-Cookie"), ShouldEqual,
"important_cookie=important_value")
})
})
})