9 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
10 . "github.com/onsi/gomega"
11 "github.com/stretchr/testify/assert"
14func TestRefresh(t *testing.T) {
17 now := time.Unix(1234567890, 10)
18 expires := time.Unix(1234567890, 0)
20 ss := &sessions.SessionState{
21 Clock: func() time.Time { return now },
23 ss.SetExpiresOn(expires)
25 refreshed, err := p.RefreshSession(context.Background(), ss)
26 assert.False(t, refreshed)
27 assert.Equal(t, ErrNotImplemented, err)
29 refreshed, err = p.RefreshSession(context.Background(), nil)
30 assert.False(t, refreshed)
31 assert.Equal(t, ErrNotImplemented, err)
34func TestCodeChallengeConfigured(t *testing.T) {
39 Path: "/oauth/authorize",
43 extraValues := url.Values{}
44 extraValues["code_challenge"] = []string{"challenge"}
45 extraValues["code_challenge_method"] = []string{"method"}
46 result := p.GetLoginURL("https://my.test.app/oauth", "", "", extraValues)
47 assert.Contains(t, result, "code_challenge=challenge")
48 assert.Contains(t, result, "code_challenge_method=method")
51func TestCodeChallengeNotConfigured(t *testing.T) {
56 Path: "/oauth/authorize",
60 result := p.GetLoginURL("https://my.test.app/oauth", "", "", url.Values{})
61 assert.NotContains(t, result, "code_challenge")
62 assert.NotContains(t, result, "code_challenge_method")
65func TestProviderDataEnrichSession(t *testing.T) {
68 s := &sessions.SessionState{}
70 err := p.EnrichSession(context.Background(), s)
71 g.Expect(err).ToNot(HaveOccurred())
74func TestProviderDataAuthorize(t *testing.T) {
75 testCases := []struct {
77 allowedGroups []string
82 name: "NoAllowedGroups",
83 allowedGroups: []string{},
88 name: "NoAllowedGroupsUserHasGroups",
89 allowedGroups: []string{},
90 groups: []string{"foo", "bar"},
94 name: "UserInAllowedGroup",
95 allowedGroups: []string{"foo"},
96 groups: []string{"foo", "bar"},
100 name: "UserNotInAllowedGroup",
101 allowedGroups: []string{"bar"},
102 groups: []string{"baz", "foo"},
103 expectedAuthZ: false,
106 name: "AllowedGroupsWithEmptyString",
107 allowedGroups: []string{"group2", ""},
108 groups: []string{"group1", "group2"},
112 name: "AllowedGroupsOnlyEmptyString",
113 allowedGroups: []string{""},
114 groups: []string{"group1", "group2"},
119 for _, tc := range testCases {
120 t.Run(tc.name, func(t *testing.T) {
123 session := &sessions.SessionState{
127 p.setAllowedGroups(tc.allowedGroups)
129 authorized, err := p.Authorize(context.Background(), session)
130 g.Expect(err).ToNot(HaveOccurred())
131 g.Expect(authorized).To(Equal(tc.expectedAuthZ))
136func TestResponseModeConfigured(t *testing.T) {
141 Path: "/oauth/authorize",
143 AuthRequestResponseMode: "form_post",
146 result := p.GetLoginURL("https://my.test.app/oauth", "", "", url.Values{})
147 assert.Contains(t, result, "response_mode=form_post")
150func TestResponseModeNotConfigured(t *testing.T) {
155 Path: "/oauth/authorize",
159 result := p.GetLoginURL("https://my.test.app/oauth", "", "", url.Values{})
160 assert.NotContains(t, result, "response_mode")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list