@@ -79,13 +79,18 @@ func TestUserAuthMethods(t *testing.T) {
79
79
// nolint:bodyclose
80
80
func TestUserOAuth2Github (t * testing.T ) {
81
81
t .Parallel ()
82
+
83
+ stateActive := "active"
84
+ statePending := "pending"
85
+
82
86
t .Run ("NotInAllowedOrganization" , func (t * testing.T ) {
83
87
t .Parallel ()
84
88
client := coderdtest .New (t , & coderdtest.Options {
85
89
GithubOAuth2Config : & coderd.GithubOAuth2Config {
86
90
OAuth2Config : & oauth2Config {},
87
91
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
88
92
return []* github.Membership {{
93
+ State : & stateActive ,
89
94
Organization : & github.Organization {
90
95
Login : github .String ("kyle" ),
91
96
},
@@ -106,6 +111,7 @@ func TestUserOAuth2Github(t *testing.T) {
106
111
OAuth2Config : & oauth2Config {},
107
112
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
108
113
return []* github.Membership {{
114
+ State : & stateActive ,
109
115
Organization : & github.Organization {
110
116
Login : github .String ("coder" ),
111
117
},
@@ -132,6 +138,7 @@ func TestUserOAuth2Github(t *testing.T) {
132
138
AllowOrganizations : []string {"coder" },
133
139
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
134
140
return []* github.Membership {{
141
+ State : & stateActive ,
135
142
Organization : & github.Organization {
136
143
Login : github .String ("coder" ),
137
144
},
@@ -160,6 +167,7 @@ func TestUserOAuth2Github(t *testing.T) {
160
167
AllowOrganizations : []string {"coder" },
161
168
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
162
169
return []* github.Membership {{
170
+ State : & stateActive ,
163
171
Organization : & github.Organization {
164
172
Login : github .String ("coder" ),
165
173
},
@@ -188,6 +196,7 @@ func TestUserOAuth2Github(t *testing.T) {
188
196
AllowOrganizations : []string {"coder" },
189
197
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
190
198
return []* github.Membership {{
199
+ State : & stateActive ,
191
200
Organization : & github.Organization {
192
201
Login : github .String ("coder" ),
193
202
},
@@ -221,6 +230,7 @@ func TestUserOAuth2Github(t *testing.T) {
221
230
AllowSignups : true ,
222
231
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
223
232
return []* github.Membership {{
233
+ State : & stateActive ,
224
234
Organization : & github.Organization {
225
235
Login : github .String ("coder" ),
226
236
},
@@ -262,6 +272,7 @@ func TestUserOAuth2Github(t *testing.T) {
262
272
OAuth2Config : & oauth2Config {},
263
273
ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
264
274
return []* github.Membership {{
275
+ State : & stateActive ,
265
276
Organization : & github.Organization {
266
277
Login : github .String ("coder" ),
267
278
},
@@ -287,6 +298,42 @@ func TestUserOAuth2Github(t *testing.T) {
287
298
resp := oauth2Callback (t , client )
288
299
require .Equal (t , http .StatusTemporaryRedirect , resp .StatusCode )
289
300
})
301
+ t .Run ("SignupFailedInactiveInOrg" , func (t * testing.T ) {
302
+ t .Parallel ()
303
+ client := coderdtest .New (t , & coderdtest.Options {
304
+ GithubOAuth2Config : & coderd.GithubOAuth2Config {
305
+ AllowSignups : true ,
306
+ AllowOrganizations : []string {"coder" },
307
+ AllowTeams : []coderd.GithubOAuth2Team {{"coder" , "frontend" }},
308
+ OAuth2Config : & oauth2Config {},
309
+ ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
310
+ return []* github.Membership {{
311
+ State : & statePending ,
312
+ Organization : & github.Organization {
313
+ Login : github .String ("coder" ),
314
+ },
315
+ }}, nil
316
+ },
317
+ TeamMembership : func (ctx context.Context , client * http.Client , org , team , username string ) (* github.Membership , error ) {
318
+ return & github.Membership {}, nil
319
+ },
320
+ AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
321
+ return & github.User {
322
+ Login : github .String ("kyle" ),
323
+ }, nil
324
+ },
325
+ ListEmails : func (ctx context.Context , client * http.Client ) ([]* github.UserEmail , error ) {
326
+ return []* github.UserEmail {{
327
+ Email : github .String ("kyle@coder.com" ),
328
+ Verified : github .Bool (true ),
329
+ Primary : github .Bool (true ),
330
+ }}, nil
331
+ },
332
+ },
333
+ })
334
+ resp := oauth2Callback (t , client )
335
+ require .Equal (t , http .StatusUnauthorized , resp .StatusCode )
336
+ })
290
337
}
291
338
292
339
// nolint:bodyclose
0 commit comments