@@ -2725,7 +2725,7 @@ func TestAuthOnlyAllowedEmailDomains(t *testing.T) {
27252725 expectedStatusCode: http.StatusForbidden,
27262726 },
27272727 {
2728− name: "UserInAllowedEmailDomains",
2728+ name: "UserNotInAllowedEmailDomains",
27292729 email: "toto@example.com",
27302730 querystring: "?allowed_email_domains=a.example.com,b.example.com",
27312731 expectedStatusCode: http.StatusForbidden,
@@ -2789,3 +2789,70 @@ func TestAuthOnlyAllowedEmailDomains(t *testing.T) {
27892789 })
27902790 }
27912791}
2792+
2793+func TestAuthOnlyAllowedEmails(t *testing.T) {
2794+ testCases := []struct {
2795+ name string
2796+ email string
2797+ querystring string
2798+ expectedStatusCode int
2799+ }{
2800+ {
2801+ name: "NotEmailRestriction",
2802+ email: "toto@example.com",
2803+ querystring: "",
2804+ expectedStatusCode: http.StatusAccepted,
2805+ },
2806+ {
2807+ name: "UserInAllowedEmail",
2808+ email: "toto@example.com",
2809+ querystring: "?allowed_emails=toto@example.com",
2810+ expectedStatusCode: http.StatusAccepted,
2811+ },
2812+ {
2813+ name: "UserNotInAllowedEmail",
2814+ email: "toto@example.com",
2815+ querystring: "?allowed_emails=tete@example.com",
2816+ expectedStatusCode: http.StatusForbidden,
2817+ },
2818+ {
2819+ name: "UserNotInAllowedEmails",
2820+ email: "toto@example.com",
2821+ querystring: "?allowed_emails=tete@example.com,tutu@example.com",
2822+ expectedStatusCode: http.StatusForbidden,
2823+ },
2824+ {
2825+ name: "UserInAllowedEmails",
2826+ email: "toto@example.com",
2827+ querystring: "?allowed_emails=tete@example.com,toto@example.com",
2828+ expectedStatusCode: http.StatusAccepted,
2829+ },
2830+ }
2831+
2832+ for _, tc := range testCases {
2833+ t.Run(tc.name, func(t *testing.T) {
2834+ groups := []string{}
2835+
2836+ created := time.Now()
2837+
2838+ session := &sessions.SessionState{
2839+ Groups: groups,
2840+ Email: tc.email,
2841+ AccessToken: "oauth_token",
2842+ CreatedAt: &created,
2843+ }
2844+
2845+ test, err := NewAuthOnlyEndpointTest(tc.querystring, func(opts *options.Options) {})
2846+ if err != nil {
2847+ t.Fatal(err)
2848+ }
2849+
2850+ err = test.SaveSession(session)
2851+ assert.NoError(t, err)
2852+
2853+ test.proxy.ServeHTTP(test.rw, test.req)
2854+
2855+ assert.Equal(t, tc.expectedStatusCode, test.rw.Code)
2856+ })
2857+ }
2858+}