-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add cookie subject extractor * Fix typo --------- Co-authored-by: Zhuojie Zhou <[email protected]>
- Loading branch information
1 parent
2eee864
commit 9ac5043
Showing
3 changed files
with
49 additions
and
0 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
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 |
---|---|---|
|
@@ -48,3 +48,31 @@ func TestGetSubjectFromOauthProxy(t *testing.T) { | |
r.Header.Set(config.Config.HeaderAuthUserField, "[email protected]") | ||
assert.Equal(t, getSubjectFromRequest(r.WithContext(ctx)), "[email protected]") | ||
} | ||
|
||
func TestGetSubjectFromCookie(t *testing.T) { | ||
var ctx = context.Background() | ||
defer func() { config.Config.CookieAuthEnabled = false }() | ||
config.Config.CookieAuthEnabled = true | ||
|
||
t.Run("test HS256 happy codepath", func(t *testing.T) { | ||
r, _ := http.NewRequest("GET", "", nil) | ||
assert.Equal(t, getSubjectFromRequest(r), "") | ||
|
||
r.AddCookie(&http.Cookie{ | ||
Name: config.Config.CookieAuthUserField, | ||
Value: "eyJhbGciOiJIUzI1NiIsImtpZCI6IjEyMzQ1In0.eyJzdWIiOiIxMjM0NTY3ODkwIiwiZW1haWwiOiJhYmNAZXhhbXBsZS5jb20iLCJpYXQiOjE1MTYyMzkwMjJ9.tzRXenFic8Eqg2awzO0eiX6Rozy_mmsJVzLJfUUfREI", | ||
}) | ||
assert.Equal(t, getSubjectFromRequest(r.WithContext(ctx)), "[email protected]") | ||
}) | ||
|
||
t.Run("test HS256 empty claim", func(t *testing.T) { | ||
r, _ := http.NewRequest("GET", "", nil) | ||
assert.Equal(t, getSubjectFromRequest(r), "") | ||
|
||
r.AddCookie(&http.Cookie{ | ||
Name: config.Config.CookieAuthUserField, | ||
Value: "eyJhbGciOiJIUzI1NiIsImtpZCI6IjEyMzQ1In0.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNTE2MjM5MDIyfQ.C_YsEkcHa7aSVQILzJAayFgJk-sj1cmNWIWUm7m7vy4", | ||
}) | ||
assert.Equal(t, getSubjectFromRequest(r.WithContext(ctx)), "") | ||
}) | ||
} |