@@ -2594,3 +2594,92 @@ func TestAuthOnlyAllowedGroups(t *testing.T) {
2598+func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) {
2599+ testCases := []struct {
2605+ expectedStatusCode int
2608+ name: "UserWithGroupSkipAuthPreflight",
2609+ groups: []string{"a", "c"},
2611+ ip: "1.2.3.5:43670",
2613+ expectedStatusCode: http.StatusAccepted,
2616+ name: "UserWithGroupTrustedIp",
2617+ groups: []string{"a", "c"},
2619+ ip: "1.2.3.4:43670",
2621+ expectedStatusCode: http.StatusAccepted,
2624+ name: "UserWithoutGroupSkipAuthPreflight",
2625+ groups: []string{"c"},
2627+ ip: "1.2.3.5:43670",
2629+ expectedStatusCode: http.StatusForbidden,
2632+ name: "UserWithoutGroupTrustedIp",
2633+ groups: []string{"c"},
2635+ ip: "1.2.3.4:43670",
2637+ expectedStatusCode: http.StatusForbidden,
2640+ name: "UserWithoutSessionSkipAuthPreflight",
2642+ ip: "1.2.3.5:43670",
2643+ withSession: false,
2644+ expectedStatusCode: http.StatusAccepted,
2647+ name: "UserWithoutSessionTrustedIp",
2649+ ip: "1.2.3.4:43670",
2650+ withSession: false,
2651+ expectedStatusCode: http.StatusAccepted,
2655+ for _, tc := range testCases {
2656+ t.Run(tc.name, func(t *testing.T) {
2657+ test, err := NewAuthOnlyEndpointTest("?allowed_groups=a,b", func(opts *options.Options) {
2658+ opts.SkipAuthPreflight = true
2659+ opts.TrustedIPs = []string{"1.2.3.4"}
2665+ test.req.Method = tc.method
2666+ test.req.RemoteAddr = tc.ip
2668+ if tc.withSession {
2669+ created := time.Now()
2670+ session := &sessions.SessionState{
2673+ AccessToken: "oauth_token",
2674+ CreatedAt: &created,
2676+ err = test.SaveSession(session)
2678+ assert.NoError(t, err)
2680+ test.proxy.ServeHTTP(test.rw, test.req)
2682+ assert.Equal(t, tc.expectedStatusCode, test.rw.Code)