(t *testing.T)
| 121 | } |
| 122 | |
| 123 | func TestUserLogin(t *testing.T) { |
| 124 | t.Parallel() |
| 125 | |
| 126 | // Single instance shared across all sub-tests. Each sub-test |
| 127 | // creates its own separate user for isolation. |
| 128 | client := coderdtest.New(t, nil) |
| 129 | user := coderdtest.CreateFirstUser(t, client) |
| 130 | |
| 131 | t.Run("OK", func(t *testing.T) { |
| 132 | t.Parallel() |
| 133 | anotherClient, anotherUser := coderdtest.CreateAnotherUser(t, client, user.OrganizationID) |
| 134 | _, err := anotherClient.LoginWithPassword(context.Background(), codersdk.LoginWithPasswordRequest{ |
| 135 | Email: anotherUser.Email, |
| 136 | Password: "SomeSecurePassword!", |
| 137 | }) |
| 138 | require.NoError(t, err) |
| 139 | }) |
| 140 | t.Run("UserDeleted", func(t *testing.T) { |
| 141 | t.Parallel() |
| 142 | anotherClient, anotherUser := coderdtest.CreateAnotherUser(t, client, user.OrganizationID) |
| 143 | client.DeleteUser(context.Background(), anotherUser.ID) |
| 144 | _, err := anotherClient.LoginWithPassword(context.Background(), codersdk.LoginWithPasswordRequest{ |
| 145 | Email: anotherUser.Email, |
| 146 | Password: "SomeSecurePassword!", |
| 147 | }) |
| 148 | require.Error(t, err) |
| 149 | var apiErr *codersdk.Error |
| 150 | require.ErrorAs(t, err, &apiErr) |
| 151 | require.Equal(t, http.StatusUnauthorized, apiErr.StatusCode()) |
| 152 | }) |
| 153 | |
| 154 | t.Run("LoginTypeNone", func(t *testing.T) { |
| 155 | t.Parallel() |
| 156 | anotherClient, anotherUser := coderdtest.CreateAnotherUserMutators(t, client, user.OrganizationID, nil, func(r *codersdk.CreateUserRequestWithOrgs) { |
| 157 | r.Password = "" |
| 158 | r.UserLoginType = codersdk.LoginTypeNone |
| 159 | }) |
| 160 | |
| 161 | _, err := anotherClient.LoginWithPassword(context.Background(), codersdk.LoginWithPasswordRequest{ |
| 162 | Email: anotherUser.Email, |
| 163 | Password: "SomeSecurePassword!", |
| 164 | }) |
| 165 | require.Error(t, err) |
| 166 | }) |
| 167 | } |
| 168 | |
| 169 | func TestUserAuthMethods(t *testing.T) { |
| 170 | t.Parallel() |
nothing calls this directly
no test coverage detected