|
8 | 8 | "testing" |
9 | 9 | "time" |
10 | 10 |
|
| 11 | + "github.com/golang-jwt/jwt" |
11 | 12 | "github.com/google/uuid" |
12 | 13 | "github.com/stretchr/testify/assert" |
13 | 14 | "github.com/stretchr/testify/require" |
@@ -566,6 +567,71 @@ func TestPostUsers(t *testing.T) { |
566 | 567 | } |
567 | 568 | } |
568 | 569 | }) |
| 570 | + |
| 571 | + t.Run("CreateNoneLoginType", func(t *testing.T) { |
| 572 | + t.Parallel() |
| 573 | + client := coderdtest.New(t, nil) |
| 574 | + first := coderdtest.CreateFirstUser(t, client) |
| 575 | + |
| 576 | + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 577 | + defer cancel() |
| 578 | + |
| 579 | + user, err := client.CreateUser(ctx, codersdk.CreateUserRequest{ |
| 580 | + OrganizationID: first.OrganizationID, |
| 581 | + Email: "another@user.org", |
| 582 | + Username: "someone-else", |
| 583 | + Password: "", |
| 584 | + UserLoginType: codersdk.LoginTypeNone, |
| 585 | + }) |
| 586 | + require.NoError(t, err) |
| 587 | + |
| 588 | + found, err := client.User(ctx, user.ID.String()) |
| 589 | + require.NoError(t, err) |
| 590 | + require.Equal(t, found.LoginType, codersdk.LoginTypeNone) |
| 591 | + }) |
| 592 | + |
| 593 | + t.Run("CreateOIDCLoginType", func(t *testing.T) { |
| 594 | + t.Parallel() |
| 595 | + email := "another@user.org" |
| 596 | + conf := coderdtest.NewOIDCConfig(t, "") |
| 597 | + config := conf.OIDCConfig(t, jwt.MapClaims{ |
| 598 | + "email": email, |
| 599 | + }) |
| 600 | + config.AllowSignups = false |
| 601 | + config.IgnoreUserInfo = true |
| 602 | + |
| 603 | + client := coderdtest.New(t, &coderdtest.Options{ |
| 604 | + OIDCConfig: config, |
| 605 | + }) |
| 606 | + first := coderdtest.CreateFirstUser(t, client) |
| 607 | + |
| 608 | + ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 609 | + defer cancel() |
| 610 | + |
| 611 | + _, err := client.CreateUser(ctx, codersdk.CreateUserRequest{ |
| 612 | + OrganizationID: first.OrganizationID, |
| 613 | + Email: email, |
| 614 | + Username: "someone-else", |
| 615 | + Password: "", |
| 616 | + UserLoginType: codersdk.LoginTypeOIDC, |
| 617 | + }) |
| 618 | + require.NoError(t, err) |
| 619 | + |
| 620 | + // Try to log in with OIDC. |
| 621 | + userClient := codersdk.New(client.URL) |
| 622 | + resp := oidcCallback(t, userClient, conf.EncodeClaims(t, jwt.MapClaims{ |
| 623 | + "email": email, |
| 624 | + })) |
| 625 | + require.Equal(t, resp.StatusCode, http.StatusTemporaryRedirect) |
| 626 | + // Set the client to use this OIDC context |
| 627 | + authCookie := authCookieValue(resp.Cookies()) |
| 628 | + userClient.SetSessionToken(authCookie) |
| 629 | + _ = resp.Body.Close() |
| 630 | + |
| 631 | + found, err := userClient.User(ctx, "me") |
| 632 | + require.NoError(t, err) |
| 633 | + require.Equal(t, found.LoginType, codersdk.LoginTypeOIDC) |
| 634 | + }) |
569 | 635 | } |
570 | 636 |
|
571 | 637 | func TestUpdateUserProfile(t *testing.T) { |
|
0 commit comments