Skip to content

Commit 9a553df

Browse files
committed
chore: work on unit test for device auth
1 parent da21464 commit 9a553df

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

coderd/externalauth_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,32 @@ func TestExternalAuthManagement(t *testing.T) {
264264

265265
func TestExternalAuthDevice(t *testing.T) {
266266
t.Parallel()
267+
// This is an example test on how to do device auth flow using our fake idp.
268+
t.Run("WithFakeIDP", func(t *testing.T) {
269+
t.Parallel()
270+
fake := oidctest.NewFakeIDP(t, oidctest.WithServing())
271+
externalID := "fake-idp"
272+
cfg := fake.ExternalAuthConfig(t, externalID, &oidctest.ExternalAuthConfigOptions{
273+
UseDeviceAuth: true,
274+
})
275+
276+
client := coderdtest.New(t, &coderdtest.Options{
277+
ExternalAuthConfigs: []*externalauth.Config{cfg},
278+
})
279+
coderdtest.CreateFirstUser(t, client)
280+
device, err := client.ExternalAuthDeviceByID(context.Background(), externalID)
281+
require.NoError(t, err)
282+
283+
ctx := testutil.Context(t, testutil.WaitShort)
284+
resp, err := client.Request(ctx, http.MethodPost, device.VerificationURI, nil)
285+
require.NoError(t, err)
286+
fmt.Println(resp.StatusCode)
287+
288+
extAuth, err := client.ExternalAuthByID(context.Background(), externalID)
289+
require.NoError(t, err)
290+
require.True(t, extAuth.Authenticated)
291+
})
292+
267293
t.Run("NotSupported", func(t *testing.T) {
268294
t.Parallel()
269295
client := coderdtest.New(t, &coderdtest.Options{

0 commit comments

Comments
 (0)