Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4f78d52

Browse files
committed
Refactor test apps
They are named now so their purpose is clearer.Also, getting apps can be done as a user so do that instead.
1 parent976725e commit4f78d52

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

‎enterprise/coderd/oauth2_test.go

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/coder/coder/v2/testutil"
1414
)
1515

16-
funcTestOAuthApps(t*testing.T) {
16+
funcTestOAuth2ProviderApps(t*testing.T) {
1717
t.Parallel()
1818

1919
t.Run("Validation",func(t*testing.T) {
@@ -162,71 +162,62 @@ func TestOAuthApps(t *testing.T) {
162162
t.Run("DeleteNonExisting",func(t*testing.T) {
163163
t.Parallel()
164164

165-
client,_:=coderdenttest.New(t,&coderdenttest.Options{LicenseOptions:&coderdenttest.LicenseOptions{
165+
client,owner:=coderdenttest.New(t,&coderdenttest.Options{LicenseOptions:&coderdenttest.LicenseOptions{
166166
Features: license.Features{
167167
codersdk.FeatureOAuth2Provider:1,
168168
},
169169
}})
170+
another,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
170171

171172
ctx:=testutil.Context(t,testutil.WaitLong)
172173

173-
//nolint:gocritic // OAauth2 app management requires owner permission.
174-
_,err:=client.OAuth2ProviderApp(ctx,uuid.New())
174+
_,err:=another.OAuth2ProviderApp(ctx,uuid.New())
175175
require.Error(t,err)
176176
})
177177

178178
t.Run("OK",func(t*testing.T) {
179179
t.Parallel()
180180

181-
client,_:=coderdenttest.New(t,&coderdenttest.Options{LicenseOptions:&coderdenttest.LicenseOptions{
181+
client,owner:=coderdenttest.New(t,&coderdenttest.Options{LicenseOptions:&coderdenttest.LicenseOptions{
182182
Features: license.Features{
183183
codersdk.FeatureOAuth2Provider:1,
184184
},
185185
}})
186+
another,_:=coderdtest.CreateAnotherUser(t,client,owner.OrganizationID)
186187

187188
ctx:=testutil.Context(t,testutil.WaitLong)
188189

189190
// No apps yet.
190-
//nolint:gocritic // OAauth2 app management requires owner permission.
191-
apps,err:=client.OAuth2ProviderApps(ctx)
191+
apps,err:=another.OAuth2ProviderApps(ctx)
192192
require.NoError(t,err)
193193
require.Len(t,apps,0)
194194

195195
// Should be able to add apps.
196-
expected:= []codersdk.OAuth2ProviderApp{}
197-
fori:=0;i<5;i++ {
198-
postReq:= codersdk.PostOAuth2ProviderAppRequest{
199-
Name:"foo-"+strconv.Itoa(i),
200-
CallbackURL:"http://"+strconv.Itoa(i)+".localhost:3000",
201-
}
202-
//nolint:gocritic // OAauth2 app management requires owner permission.
203-
app,err:=client.PostOAuth2ProviderApp(ctx,postReq)
204-
require.NoError(t,err)
205-
require.Equal(t,postReq.Name,app.Name)
206-
require.Equal(t,postReq.CallbackURL,app.CallbackURL)
207-
expected=append(expected,app)
196+
expected:=generateApps(ctx,t,client)
197+
expectedOrder:= []codersdk.OAuth2ProviderApp{
198+
expected.Default,expected.NoPort,expected.Subdomain,
199+
expected.Extra[0],expected.Extra[1],
208200
}
209201

210202
// Should get all the apps now.
211-
//nolint:gocritic // OAauth2 app management requires owner permission.
212-
apps,err=client.OAuth2ProviderApps(ctx)
203+
apps,err=another.OAuth2ProviderApps(ctx)
213204
require.NoError(t,err)
214205
require.Len(t,apps,5)
215-
require.Equal(t,expected,apps)
206+
require.Equal(t,expectedOrder,apps)
216207

217208
// Should be able to keep the same name when updating.
218209
req:= codersdk.PutOAuth2ProviderAppRequest{
219-
Name:expected[0].Name,
210+
Name:expected.Default.Name,
220211
CallbackURL:"http://coder.com",
221212
Icon:"test",
222213
}
223214
//nolint:gocritic // OAauth2 app management requires owner permission.
224-
newApp,err:=client.PutOAuth2ProviderApp(ctx,expected[0].ID,req)
215+
newApp,err:=client.PutOAuth2ProviderApp(ctx,expected.Default.ID,req)
225216
require.NoError(t,err)
226217
require.Equal(t,req.Name,newApp.Name)
227218
require.Equal(t,req.CallbackURL,newApp.CallbackURL)
228219
require.Equal(t,req.Icon,newApp.Icon)
229-
require.Equal(t,expected[0].ID,newApp.ID)
220+
require.Equal(t,expected.Default.ID,newApp.ID)
230221

231222
// Should be able to update name.
232223
req= codersdk.PutOAuth2ProviderAppRequest{
@@ -235,34 +226,33 @@ func TestOAuthApps(t *testing.T) {
235226
Icon:"test",
236227
}
237228
//nolint:gocritic // OAauth2 app management requires owner permission.
238-
newApp,err=client.PutOAuth2ProviderApp(ctx,expected[0].ID,req)
229+
newApp,err=client.PutOAuth2ProviderApp(ctx,expected.Default.ID,req)
239230
require.NoError(t,err)
240231
require.Equal(t,req.Name,newApp.Name)
241232
require.Equal(t,req.CallbackURL,newApp.CallbackURL)
242233
require.Equal(t,req.Icon,newApp.Icon)
243-
require.Equal(t,expected[0].ID,newApp.ID)
234+
require.Equal(t,expected.Default.ID,newApp.ID)
244235

245236
// Should be able to get a single app.
246-
//nolint:gocritic // OAauth2 app management requires owner permission.
247-
got,err:=client.OAuth2ProviderApp(ctx,expected[0].ID)
237+
got,err:=another.OAuth2ProviderApp(ctx,expected.Default.ID)
248238
require.NoError(t,err)
249239
require.Equal(t,newApp,got)
250240

251241
// Should be able to delete an app.
252242
//nolint:gocritic // OAauth2 app management requires owner permission.
253-
err=client.DeleteOAuth2ProviderApp(ctx,expected[0].ID)
243+
err=client.DeleteOAuth2ProviderApp(ctx,expected.Default.ID)
254244
require.NoError(t,err)
255245

256246
// Should show the new count.
257-
//nolint:gocritic // OAauth2 app management requires owner permission.
258-
newApps,err:=client.OAuth2ProviderApps(ctx)
247+
newApps,err:=another.OAuth2ProviderApps(ctx)
259248
require.NoError(t,err)
260249
require.Len(t,newApps,4)
261-
require.Equal(t,expected[1:],newApps)
250+
251+
require.Equal(t,expectedOrder[1:],newApps)
262252
})
263253
}
264254

265-
funcTestOAuthAppSecrets(t*testing.T) {
255+
funcTestOAuth2ProviderAppSecrets(t*testing.T) {
266256
t.Parallel()
267257

268258
client,_:=coderdenttest.New(t,&coderdenttest.Options{LicenseOptions:&coderdenttest.LicenseOptions{
@@ -365,3 +355,35 @@ func TestOAuthAppSecrets(t *testing.T) {
365355
require.Error(t,err)
366356
})
367357
}
358+
359+
typeprovisionedAppsstruct {
360+
Default codersdk.OAuth2ProviderApp
361+
NoPort codersdk.OAuth2ProviderApp
362+
Subdomain codersdk.OAuth2ProviderApp
363+
// For sorting purposes these are included. You will likely never touch them.
364+
Extra []codersdk.OAuth2ProviderApp
365+
}
366+
funcgenerateApps(ctx context.Context,t*testing.T,client*codersdk.Client)provisionedApps {
367+
create:=func(name,callbackstring) codersdk.OAuth2ProviderApp {
368+
//nolint:gocritic // OAauth2 app management requires owner permission.
369+
app,err:=client.PostOAuth2ProviderApp(ctx, codersdk.PostOAuth2ProviderAppRequest{
370+
Name:name,
371+
CallbackURL:callback,
372+
Icon:"",
373+
})
374+
require.NoError(t,err)
375+
require.Equal(t,name,app.Name)
376+
require.Equal(t,callback,app.CallbackURL)
377+
returnapp
378+
}
379+
380+
returnprovisionedApps{
381+
Default:create("razzle-dazzle","http://localhost1:8080/foo/bar"),
382+
NoPort:create("razzle-dazzle-the-sequel","http://localhost2"),
383+
Subdomain:create("razzle-dazzle-the-z-prequel","http://30.localhost:3000"),
384+
Extra: []codersdk.OAuth2ProviderApp{
385+
create("the-not-really-twenty","http://20.localhost:3000"),
386+
create("woo-10","http://10.localhost:3000"),
387+
},
388+
}
389+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp