-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
X-Id-Token
auth header forwarding (#1007)
- Loading branch information
1 parent
ec0fb40
commit 9d6533c
Showing
5 changed files
with
101 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'grafana-infinity-datasource': patch | ||
--- | ||
|
||
Fix forward oauth for x-id-token header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package infinity | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestGetQueryReqHeader(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
requestHeaders map[string]string | ||
headerName string | ||
expected string | ||
}{ | ||
{ | ||
name: "Authorization header exact match", | ||
requestHeaders: map[string]string{ | ||
HeaderKeyAuthorization: "Bearer token", | ||
}, | ||
headerName: HeaderKeyAuthorization, | ||
expected: "Bearer token", | ||
}, | ||
{ | ||
name: "Authorization header case insensitive match", | ||
requestHeaders: map[string]string{ | ||
strings.ToLower(HeaderKeyAuthorization): "Bearer token", | ||
}, | ||
headerName: HeaderKeyAuthorization, | ||
expected: "Bearer token", | ||
}, | ||
{ | ||
name: "X-Id-Token header exact match", | ||
requestHeaders: map[string]string{ | ||
HeaderKeyIdToken: "some-id-token", | ||
}, | ||
headerName: HeaderKeyIdToken, | ||
expected: "some-id-token", | ||
}, | ||
{ | ||
name: "X-Id-Token header case insensitive match", | ||
requestHeaders: map[string]string{ | ||
strings.ToLower(HeaderKeyIdToken): "some-id-token", | ||
}, | ||
headerName: HeaderKeyIdToken, | ||
expected: "some-id-token", | ||
}, | ||
{ | ||
name: "X-Id-Token header case with ID capitalization", | ||
requestHeaders: map[string]string{ | ||
"X-ID-Token": "some-id-token", | ||
}, | ||
headerName: HeaderKeyIdToken, | ||
expected: "some-id-token", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got := getQueryReqHeader(tt.requestHeaders, tt.headerName) | ||
if got != tt.expected { | ||
t.Errorf("getQueryReqHeader() = %v, expected %v", got, tt.expected) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters