Skip to content

Commit 4f8f7aa

Browse files
committed
Fix failing tests for user proxy preferences
- Fix userProxySettings handler to return 404 when no proxy is set - Add database authorization tests for user proxy methods
1 parent 0543dc7 commit 4f8f7aa

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4896,6 +4896,24 @@ func (s *MethodTestSuite) TestNotifications() {
48964896
}).Asserts(rbac.ResourceNotificationPreference.WithOwner(user.ID.String()), policy.ActionUpdate)
48974897
}))
48984898

4899+
s.Run("GetUserPreferredProxy", s.Subtest(func(db database.Store, check *expects) {
4900+
user := dbgen.User(s.T(), db, database.User{})
4901+
check.Args(user.ID).
4902+
Asserts(rbac.ResourceUser.WithOwner(user.ID.String()), policy.ActionReadPersonal)
4903+
}))
4904+
s.Run("UpdateUserPreferredProxy", s.Subtest(func(db database.Store, check *expects) {
4905+
user := dbgen.User(s.T(), db, database.User{})
4906+
check.Args(database.UpdateUserPreferredProxyParams{
4907+
UserID: user.ID,
4908+
PreferredProxy: "proxy1",
4909+
}).Asserts(rbac.ResourceUser.WithOwner(user.ID.String()), policy.ActionUpdatePersonal)
4910+
}))
4911+
s.Run("DeleteUserPreferredProxy", s.Subtest(func(db database.Store, check *expects) {
4912+
user := dbgen.User(s.T(), db, database.User{})
4913+
check.Args(user.ID).
4914+
Asserts(rbac.ResourceUser.WithOwner(user.ID.String()), policy.ActionUpdatePersonal)
4915+
}))
4916+
48994917
s.Run("GetInboxNotificationsByUserID", s.Subtest(func(db database.Store, check *expects) {
49004918
u := dbgen.User(s.T(), db, database.User{})
49014919

coderd/users.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,15 +1082,18 @@ func (api *API) userProxySettings(rw http.ResponseWriter, r *http.Request) {
10821082

10831083
preferredProxy, err := api.Database.GetUserPreferredProxy(ctx, user.ID)
10841084
if err != nil {
1085-
if !errors.Is(err, sql.ErrNoRows) {
1086-
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
1087-
Message: "Error reading user proxy settings.",
1088-
Detail: err.Error(),
1085+
if errors.Is(err, sql.ErrNoRows) {
1086+
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
1087+
Message: "User proxy settings not found.",
10891088
})
10901089
return
10911090
}
10921091

1093-
preferredProxy = ""
1092+
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
1093+
Message: "Error reading user proxy settings.",
1094+
Detail: err.Error(),
1095+
})
1096+
return
10941097
}
10951098

10961099
httpapi.Write(ctx, rw, http.StatusOK, codersdk.UserProxySettings{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy