Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
697a87b7
Commit
697a87b7
authored
Mar 14, 2019
by
Andrej Ocenas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add check so that header is not sent for anonymous users
parent
6587a967
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
5 deletions
+32
-5
conf/defaults.ini
+1
-1
conf/sample.ini
+1
-1
docs/sources/installation/configuration.md
+1
-1
pkg/api/pluginproxy/ds_proxy.go
+1
-1
pkg/api/pluginproxy/ds_proxy_test.go
+13
-0
pkg/api/pluginproxy/pluginproxy.go
+1
-1
pkg/api/pluginproxy/pluginproxy_test.go
+14
-0
No files found.
conf/defaults.ini
View file @
697a87b7
...
...
@@ -157,7 +157,7 @@ logging = false
# How long the data proxy should wait before timing out default is 30 (seconds)
timeout
=
30
# If enabled data proxy will add X-Grafana-User header with username into the request, default is false.
# If enabled
and user is not anonymous,
data proxy will add X-Grafana-User header with username into the request, default is false.
send_user_header
=
false
#################################### Analytics ###########################
...
...
conf/sample.ini
View file @
697a87b7
...
...
@@ -144,7 +144,7 @@ log_queries =
# How long the data proxy should wait before timing out default is 30 (seconds)
;timeout = 30
# If enabled data proxy will add X-Grafana-User header with username into the request, default is false.
# If enabled
and user is not anonymous,
data proxy will add X-Grafana-User header with username into the request, default is false.
;send_user_header = false
#################################### Analytics ####################################
...
...
docs/sources/installation/configuration.md
View file @
697a87b7
...
...
@@ -423,7 +423,7 @@ How long the data proxy should wait before timing out default is 30 (seconds)
### send_user_header
If enabled data proxy will add X-Grafana-User header with username into the request, default is false.
If enabled
and user is not anonymous,
data proxy will add X-Grafana-User header with username into the request, default is false.
<hr
/>
...
...
pkg/api/pluginproxy/ds_proxy.go
View file @
697a87b7
...
...
@@ -172,7 +172,7 @@ func (proxy *DataSourceProxy) getDirector() func(req *http.Request) {
req
.
Header
.
Add
(
"Authorization"
,
dsAuth
)
}
if
proxy
.
cfg
.
SendUserHeader
{
if
proxy
.
cfg
.
SendUserHeader
&&
!
proxy
.
ctx
.
SignedInUser
.
IsAnonymous
{
req
.
Header
.
Add
(
"X-Grafana-User"
,
proxy
.
ctx
.
SignedInUser
.
Login
)
}
...
...
pkg/api/pluginproxy/ds_proxy_test.go
View file @
697a87b7
...
...
@@ -417,6 +417,19 @@ func TestDSRouteRule(t *testing.T) {
So
(
req
.
Header
.
Get
(
"X-Grafana-User"
),
ShouldEqual
,
""
)
})
})
Convey
(
"When SendUserHeader config is enabled but user is anonymous"
,
func
()
{
req
:=
getDatasourceProxiedRequest
(
&
m
.
ReqContext
{
SignedInUser
:
&
m
.
SignedInUser
{
IsAnonymous
:
true
},
},
&
setting
.
Cfg
{
SendUserHeader
:
true
},
)
Convey
(
"Should not add header with username"
,
func
()
{
// Get will return empty string even if header is not set
So
(
req
.
Header
.
Get
(
"X-Grafana-User"
),
ShouldEqual
,
""
)
})
})
})
}
...
...
pkg/api/pluginproxy/pluginproxy.go
View file @
697a87b7
...
...
@@ -80,7 +80,7 @@ func NewApiPluginProxy(ctx *m.ReqContext, proxyPath string, route *plugins.AppPl
req
.
Header
.
Add
(
"X-Grafana-Context"
,
string
(
ctxJson
))
if
cfg
.
SendUserHeader
{
if
cfg
.
SendUserHeader
&&
!
ctx
.
SignedInUser
.
IsAnonymous
{
req
.
Header
.
Add
(
"X-Grafana-User"
,
ctx
.
SignedInUser
.
Login
)
}
...
...
pkg/api/pluginproxy/pluginproxy_test.go
View file @
697a87b7
...
...
@@ -75,6 +75,20 @@ func TestPluginProxy(t *testing.T) {
So
(
req
.
Header
.
Get
(
"X-Grafana-User"
),
ShouldEqual
,
""
)
})
})
Convey
(
"When SendUserHeader config is enabled but user is anonymous"
,
t
,
func
()
{
req
:=
getPluginProxiedRequest
(
&
m
.
ReqContext
{
SignedInUser
:
&
m
.
SignedInUser
{
IsAnonymous
:
true
},
},
&
setting
.
Cfg
{
SendUserHeader
:
true
},
)
Convey
(
"Should not add header with username"
,
func
()
{
// Get will return empty string even if header is not set
So
(
req
.
Header
.
Get
(
"X-Grafana-User"
),
ShouldEqual
,
""
)
})
})
}
// getPluginProxiedRequest is a helper for easier setup of tests based on global config and ReqContext.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment