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