forked from oauth2-proxy/oauth2-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the allowed_email_domains and the allowed_groups on the auth_requ…
…est endpoint + support standard wildcard char for validation with sub-domain and email-domain. Signed-off-by: Valentin Pichard <[email protected]>
- Loading branch information
Showing
11 changed files
with
305 additions
and
90 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
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 |
---|---|---|
|
@@ -2683,3 +2683,94 @@ func TestAuthOnlyAllowedGroupsWithSkipMethods(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestAuthOnlyAllowedEmailDomains(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
email string | ||
querystring string | ||
expectedStatusCode int | ||
}{ | ||
{ | ||
name: "NotEmailRestriction", | ||
email: "[email protected]", | ||
querystring: "", | ||
expectedStatusCode: http.StatusAccepted, | ||
}, | ||
{ | ||
name: "UserInAllowedEmailDomain", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=example.com", | ||
expectedStatusCode: http.StatusAccepted, | ||
}, | ||
{ | ||
name: "UserNotInAllowedEmailDomain", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=a.example.com", | ||
expectedStatusCode: http.StatusForbidden, | ||
}, | ||
{ | ||
name: "UserInAllowedEmailDomains", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=a.example.com,b.example.com", | ||
expectedStatusCode: http.StatusForbidden, | ||
}, | ||
{ | ||
name: "UserInAllowedEmailDomains", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=a.example.com,example.com", | ||
expectedStatusCode: http.StatusAccepted, | ||
}, | ||
{ | ||
name: "UserInAllowedEmailDomainWildcard", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=*.example.com", | ||
expectedStatusCode: http.StatusAccepted, | ||
}, | ||
{ | ||
name: "UserNotInAllowedEmailDomainWildcard", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=*.a.example.com", | ||
expectedStatusCode: http.StatusForbidden, | ||
}, | ||
{ | ||
name: "UserInAllowedEmailDomainsWildcard", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=*.a.example.com,*.b.example.com", | ||
expectedStatusCode: http.StatusForbidden, | ||
}, | ||
{ | ||
name: "UserInAllowedEmailDomainsWildcard", | ||
email: "[email protected]", | ||
querystring: "?allowed_email_domains=a.b.c.example.com,*.c.example.com", | ||
expectedStatusCode: http.StatusAccepted, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
groups := []string{} | ||
|
||
created := time.Now() | ||
|
||
session := &sessions.SessionState{ | ||
Groups: groups, | ||
Email: tc.email, | ||
AccessToken: "oauth_token", | ||
CreatedAt: &created, | ||
} | ||
|
||
test, err := NewAuthOnlyEndpointTest(tc.querystring, func(opts *options.Options) {}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = test.SaveSession(session) | ||
assert.NoError(t, err) | ||
|
||
test.proxy.ServeHTTP(test.rw, test.req) | ||
|
||
assert.Equal(t, tc.expectedStatusCode, test.rw.Code) | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.