Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit671c56d

Browse files
committed
Remove user restriction and refactor tests
1 parent4f9f506 commit671c56d

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

‎coderd/httpmw/userparam.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,6 @@ func ExtractUserParam(db database.Store) func(http.Handler) http.Handler {
7676
}
7777
}
7878

79-
apiKey:=APIKey(r)
80-
ifapiKey.UserID!=user.ID {
81-
httpapi.Write(rw,http.StatusBadRequest, httpapi.Response{
82-
Message:"getting non-personal users isn't supported yet",
83-
})
84-
return
85-
}
86-
8779
ctx:=context.WithValue(r.Context(),userParamContextKey{},user)
8880
next.ServeHTTP(rw,r.WithContext(ctx))
8981
})

‎coderd/users_test.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,21 +290,38 @@ func TestUpdateUserProfile(t *testing.T) {
290290
funcTestUpdateUserPassword(t*testing.T) {
291291
t.Parallel()
292292

293-
t.Run("Success",func(t*testing.T) {
293+
t.Run("MemberCantUpdateAdminPassword",func(t*testing.T) {
294294
t.Parallel()
295295
client:=coderdtest.New(t,nil)
296-
coderdtest.CreateFirstUser(t,client)
297-
err:=client.UpdateUserPassword(context.Background(),codersdk.Me, codersdk.UpdateUserPasswordRequest{
296+
admin:=coderdtest.CreateFirstUser(t,client)
297+
member:=coderdtest.CreateAnotherUser(t,client,admin.OrganizationID)
298+
err:=member.UpdateUserPassword(context.Background(),admin.UserID, codersdk.UpdateUserPasswordRequest{
298299
Password:"newpassword",
299300
})
300-
require.NoError(t,err,"update password request should be successful")
301+
require.Error(t,err,"member should not be able to update admin password")
302+
})
301303

302-
// Check if the user can login using the new password
304+
t.Run("AdminCanUpdateMemberPassword",func(t*testing.T) {
305+
t.Parallel()
306+
client:=coderdtest.New(t,nil)
307+
admin:=coderdtest.CreateFirstUser(t,client)
308+
member,err:=client.CreateUser(context.Background(), codersdk.CreateUserRequest{
309+
Email:"coder@coder.com",
310+
Username:"coder",
311+
Password:"password",
312+
OrganizationID:admin.OrganizationID,
313+
})
314+
require.NoError(t,err,"create member")
315+
err=client.UpdateUserPassword(context.Background(),member.ID, codersdk.UpdateUserPasswordRequest{
316+
Password:"newpassword",
317+
})
318+
require.NoError(t,err,"admin should be able to update member password")
319+
// Check if the member can login using the new password
303320
_,err=client.LoginWithPassword(context.Background(), codersdk.LoginWithPasswordRequest{
304-
Email:coderdtest.FirstUserParams.Email,
321+
Email:"coder@coder.com",
305322
Password:"newpassword",
306323
})
307-
require.NoError(t,err,"login shouldbe successful")
324+
require.NoError(t,err,"member shouldlogin successfully with the new password")
308325
})
309326
}
310327

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp