You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-08-08 22:46:33 +02:00
Add the allowed_email_domains and the allowed_groups on the auth_request endpoint + support standard wildcard char for validation with sub-domain and email-domain.
Signed-off-by: Valentin Pichard <github@w3st.fr>
This commit is contained in:
committed by
Valentin Pichard
parent
c5a98c6d03
commit
2b4c8a9846
@ -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: "toto@example.com",
|
||||
querystring: "",
|
||||
expectedStatusCode: http.StatusAccepted,
|
||||
},
|
||||
{
|
||||
name: "UserInAllowedEmailDomain",
|
||||
email: "toto@example.com",
|
||||
querystring: "?allowed_email_domains=example.com",
|
||||
expectedStatusCode: http.StatusAccepted,
|
||||
},
|
||||
{
|
||||
name: "UserNotInAllowedEmailDomain",
|
||||
email: "toto@example.com",
|
||||
querystring: "?allowed_email_domains=a.example.com",
|
||||
expectedStatusCode: http.StatusForbidden,
|
||||
},
|
||||
{
|
||||
name: "UserInAllowedEmailDomains",
|
||||
email: "toto@example.com",
|
||||
querystring: "?allowed_email_domains=a.example.com,b.example.com",
|
||||
expectedStatusCode: http.StatusForbidden,
|
||||
},
|
||||
{
|
||||
name: "UserInAllowedEmailDomains",
|
||||
email: "toto@example.com",
|
||||
querystring: "?allowed_email_domains=a.example.com,example.com",
|
||||
expectedStatusCode: http.StatusAccepted,
|
||||
},
|
||||
{
|
||||
name: "UserInAllowedEmailDomainWildcard",
|
||||
email: "toto@foo.example.com",
|
||||
querystring: "?allowed_email_domains=*.example.com",
|
||||
expectedStatusCode: http.StatusAccepted,
|
||||
},
|
||||
{
|
||||
name: "UserNotInAllowedEmailDomainWildcard",
|
||||
email: "toto@example.com",
|
||||
querystring: "?allowed_email_domains=*.a.example.com",
|
||||
expectedStatusCode: http.StatusForbidden,
|
||||
},
|
||||
{
|
||||
name: "UserInAllowedEmailDomainsWildcard",
|
||||
email: "toto@example.com",
|
||||
querystring: "?allowed_email_domains=*.a.example.com,*.b.example.com",
|
||||
expectedStatusCode: http.StatusForbidden,
|
||||
},
|
||||
{
|
||||
name: "UserInAllowedEmailDomainsWildcard",
|
||||
email: "toto@c.example.com",
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user