mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Team LBAC: Add teamHeaders for datasource proxy requests (#76339)
* Add teamHeaders for datasource proxy requests * adds validation for the teamHeaders * added tests for applying teamHeaders * remove previous implementation * validation for header values being set to authproxy * removed unnecessary checks * newline * Add middleware for injecting headers on the data source backend * renamed feature toggle * Get user teams from context * Fix feature toggle name * added test for validation of the auth headers and fixed evaluation to cover headers * renaming of teamHeaders to teamHTTPHeaders * use of header set for non-existing header and add for existing headers * moves types into datasources * fixed unchecked errors * Refactor * Add tests for data model * Update pkg/api/datasources.go Co-authored-by: Victor Cinaglia <victor@grafana.com> * Update pkg/api/datasources.go Co-authored-by: Victor Cinaglia <victor@grafana.com> --------- Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com> Co-authored-by: Victor Cinaglia <victor@grafana.com>
This commit is contained in:
@@ -58,3 +58,45 @@ func TestAllowedCookies(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTeamHTTPHeaders(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
given string
|
||||
want TeamHTTPHeaders
|
||||
}{
|
||||
{
|
||||
desc: "Usual json data with teamHttpHeaders",
|
||||
given: `{"teamHttpHeaders": {"101": [{"header": "X-CUSTOM-HEADER", "value": "foo"}]}}`,
|
||||
want: TeamHTTPHeaders{
|
||||
"101": {
|
||||
{Header: "X-CUSTOM-HEADER", Value: "foo"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "Json data without teamHttpHeaders",
|
||||
given: `{"foo": "bar"}`,
|
||||
want: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
jsonDataBytes := []byte(test.given)
|
||||
jsonData, err := simplejson.NewJson(jsonDataBytes)
|
||||
require.NoError(t, err)
|
||||
|
||||
ds := DataSource{
|
||||
ID: 1235,
|
||||
JsonData: jsonData,
|
||||
UID: "test",
|
||||
}
|
||||
|
||||
actual, err := ds.TeamHTTPHeaders()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, test.want, actual)
|
||||
assert.EqualValues(t, test.want, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user