@@ -31,16 +31,38 @@ func (*oauth2Config) TokenSource(context.Context, *oauth2.Token) oauth2.TokenSou
31
31
return nil
32
32
}
33
33
34
+ func TestUserAuthMethods (t * testing.T ) {
35
+ t .Parallel ()
36
+ t .Run ("Basic" , func (t * testing.T ) {
37
+ client := coderdtest .New (t , nil )
38
+ methods , err := client .AuthMethods (context .Background ())
39
+ require .NoError (t , err )
40
+ require .True (t , methods .Password )
41
+ require .False (t , methods .Github )
42
+ })
43
+ t .Run ("Github" , func (t * testing.T ) {
44
+ client := coderdtest .New (t , & coderdtest.Options {
45
+ GithubOAuth2Config : & coderd.GithubOAuth2Config {},
46
+ })
47
+ methods , err := client .AuthMethods (context .Background ())
48
+ require .NoError (t , err )
49
+ require .True (t , methods .Password )
50
+ require .True (t , methods .Github )
51
+ })
52
+ }
53
+
34
54
func TestUserOAuth2Github (t * testing.T ) {
35
55
t .Parallel ()
36
56
t .Run ("NotInAllowedOrganization" , func (t * testing.T ) {
37
57
t .Parallel ()
38
58
client := coderdtest .New (t , & coderdtest.Options {
39
59
GithubOAuth2Config : & coderd.GithubOAuth2Config {
40
60
OAuth2Config : & oauth2Config {},
41
- ListOrganizations : func (ctx context.Context , client * http.Client ) ([]* github.Organization , error ) {
42
- return []* github.Organization {{
43
- Login : github .String ("kyle" ),
61
+ ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
62
+ return []* github.Membership {{
63
+ Organization : & github.Organization {
64
+ Login : github .String ("kyle" ),
65
+ },
44
66
}}, nil
45
67
},
46
68
},
@@ -55,9 +77,11 @@ func TestUserOAuth2Github(t *testing.T) {
55
77
GithubOAuth2Config : & coderd.GithubOAuth2Config {
56
78
OAuth2Config : & oauth2Config {},
57
79
AllowOrganizations : []string {"coder" },
58
- ListOrganizations : func (ctx context.Context , client * http.Client ) ([]* github.Organization , error ) {
59
- return []* github.Organization {{
60
- Login : github .String ("coder" ),
80
+ ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
81
+ return []* github.Membership {{
82
+ Organization : & github.Organization {
83
+ Login : github .String ("kyle" ),
84
+ },
61
85
}}, nil
62
86
},
63
87
AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
@@ -81,9 +105,11 @@ func TestUserOAuth2Github(t *testing.T) {
81
105
GithubOAuth2Config : & coderd.GithubOAuth2Config {
82
106
OAuth2Config : & oauth2Config {},
83
107
AllowOrganizations : []string {"coder" },
84
- ListOrganizations : func (ctx context.Context , client * http.Client ) ([]* github.Organization , error ) {
85
- return []* github.Organization {{
86
- Login : github .String ("coder" ),
108
+ ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
109
+ return []* github.Membership {{
110
+ Organization : & github.Organization {
111
+ Login : github .String ("coder" ),
112
+ },
87
113
}}, nil
88
114
},
89
115
AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
@@ -104,9 +130,11 @@ func TestUserOAuth2Github(t *testing.T) {
104
130
OAuth2Config : & oauth2Config {},
105
131
AllowOrganizations : []string {"coder" },
106
132
AllowSignups : true ,
107
- ListOrganizations : func (ctx context.Context , client * http.Client ) ([]* github.Organization , error ) {
108
- return []* github.Organization {{
109
- Login : github .String ("coder" ),
133
+ ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
134
+ return []* github.Membership {{
135
+ Organization : & github.Organization {
136
+ Login : github .String ("coder" ),
137
+ },
110
138
}}, nil
111
139
},
112
140
AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
@@ -129,9 +157,11 @@ func TestUserOAuth2Github(t *testing.T) {
129
157
GithubOAuth2Config : & coderd.GithubOAuth2Config {
130
158
OAuth2Config : & oauth2Config {},
131
159
AllowOrganizations : []string {"coder" },
132
- ListOrganizations : func (ctx context.Context , client * http.Client ) ([]* github.Organization , error ) {
133
- return []* github.Organization {{
134
- Login : github .String ("coder" ),
160
+ ListOrganizationMemberships : func (ctx context.Context , client * http.Client ) ([]* github.Membership , error ) {
161
+ return []* github.Membership {{
162
+ Organization : & github.Organization {
163
+ Login : github .String ("coder" ),
164
+ },
135
165
}}, nil
136
166
},
137
167
AuthenticatedUser : func (ctx context.Context , client * http.Client ) (* github.User , error ) {
0 commit comments