MCPcopy Index your code
hub / github.com/coder/coder / TestOAuth2ProviderAppOperations

Function TestOAuth2ProviderAppOperations

coderd/oauth2provider/provider_test.go:314–416  ·  view source on GitHub ↗

TestOAuth2ProviderAppOperations tests basic CRUD operations for OAuth2 provider apps

(t *testing.T)

Source from the content-addressed store, hash-verified

312
313// TestOAuth2ProviderAppOperations tests basic CRUD operations for OAuth2 provider apps
314func TestOAuth2ProviderAppOperations(t *testing.T) {
315 t.Parallel()
316
317 t.Run("DeleteNonExisting", func(t *testing.T) {
318 t.Parallel()
319
320 client := coderdtest.New(t, nil)
321 owner := coderdtest.CreateFirstUser(t, client)
322 another, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
323
324 ctx := testutil.Context(t, testutil.WaitLong)
325
326 _, err := another.OAuth2ProviderApp(ctx, uuid.New())
327 require.Error(t, err)
328 })
329
330 t.Run("BasicOperations", func(t *testing.T) {
331 t.Parallel()
332
333 client := coderdtest.New(t, nil)
334 owner := coderdtest.CreateFirstUser(t, client)
335 another, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
336
337 ctx := testutil.Context(t, testutil.WaitLong)
338
339 // No apps yet.
340 apps, err := another.OAuth2ProviderApps(ctx, codersdk.OAuth2ProviderAppFilter{})
341 require.NoError(t, err)
342 require.Len(t, apps, 0)
343
344 // Should be able to add apps.
345 expectedApps := generateApps(ctx, t, client, "get-apps")
346 expectedOrder := []codersdk.OAuth2ProviderApp{
347 expectedApps.Default, expectedApps.NoPort,
348 expectedApps.Extra[0], expectedApps.Extra[1], expectedApps.Subdomain,
349 }
350
351 // Should get all the apps now.
352 apps, err = another.OAuth2ProviderApps(ctx, codersdk.OAuth2ProviderAppFilter{})
353 require.NoError(t, err)
354 require.Len(t, apps, 5)
355 require.Equal(t, expectedOrder, apps)
356
357 // Should be able to keep the same name when updating.
358 req := codersdk.PutOAuth2ProviderAppRequest{
359 Name: expectedApps.Default.Name,
360 CallbackURL: "http://coder.com",
361 Icon: "test",
362 }
363 //nolint:gocritic // OAuth2 app management requires owner permission.
364 newApp, err := client.PutOAuth2ProviderApp(ctx, expectedApps.Default.ID, req)
365 require.NoError(t, err)
366 require.Equal(t, req.Name, newApp.Name)
367 require.Equal(t, req.CallbackURL, newApp.CallbackURL)
368 require.Equal(t, req.Icon, newApp.Icon)
369 require.Equal(t, expectedApps.Default.ID, newApp.ID)
370
371 // Should be able to update name.

Callers

nothing calls this directly

Calls 14

NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
ContextFunction · 0.92
OAuth2ProviderAppMethod · 0.80
OAuth2ProviderAppsMethod · 0.80
PutOAuth2ProviderAppMethod · 0.80
generateAppsFunction · 0.70
RunMethod · 0.65
NewMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected