You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-06-17 00:17:40 +02:00
Merge pull request #1286 from instadeepai/allowed_email_domains-on-auth_request-endpoint
Add allowed_email_domains on auth_request endpoint
This commit is contained in:
@ -2698,3 +2698,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