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

Function TestUserLogin

coderd/userauth_test.go:123–167  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func 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
169func TestUserAuthMethods(t *testing.T) {
170 t.Parallel()

Callers

nothing calls this directly

Calls 10

StatusCodeMethod · 0.95
NewFunction · 0.92
CreateFirstUserFunction · 0.92
CreateAnotherUserFunction · 0.92
LoginWithPasswordMethod · 0.80
DeleteUserMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected