fix: address review feedback for Bearer actor revalidation

This commit is contained in:
Reese Norris
2026-07-28 11:25:29 -04:00
parent b229c06ed8
commit 897f514b99
2 changed files with 13 additions and 11 deletions

View File

@@ -500,11 +500,13 @@ func TestBearerActorRevalidation(t *testing.T) {
}
tests := []struct {
name string
mutate func(t *testing.T, env *testAPIEnv)
method string
path string
body any
name string
mutate func(t *testing.T, env *testAPIEnv)
method string
path string
body any
// loadOtherCID: when path is /user/load and body is nil, load observer instead of self.
loadOtherCID bool
wantStatus int
wantErrSubstr string
}{
@@ -571,9 +573,9 @@ func TestBearerActorRevalidation(t *testing.T) {
mutate: func(t *testing.T, env *testAPIEnv) {
setRating(t, env, env.admin.CID, int(protocol.NetworkRatingObserver))
},
method: http.MethodPost,
path: "/api/v1/user/load",
// body set to observer CID in loop
method: http.MethodPost,
path: "/api/v1/user/load",
loadOtherCID: true,
wantStatus: http.StatusForbidden,
wantErrSubstr: "forbidden",
},
@@ -590,9 +592,8 @@ func TestBearerActorRevalidation(t *testing.T) {
body := tt.body
if tt.path == "/api/v1/user/load" && body == nil {
// Default: load self; demoted-cannot-load-other overrides to other CID.
cid := env.admin.CID
if tt.name == "demoted_admin_cannot_load_other" {
if tt.loadOtherCID {
cid = env.observer.CID
}
body = map[string]any{"cid": cid}

View File

@@ -403,7 +403,8 @@ func (s *Server) requireSessionHTML(c *gin.Context) {
c.Next()
}
// getDBUser returns the *db.User stashed by requireSessionHTML / trySessionAuth.
// getDBUser returns the *db.User stashed by requireSessionHTML, trySessionAuth,
// or revalidateBearerActor (dual-accept Bearer resource path).
func getDBUser(c *gin.Context) *db.User {
val, exists := c.Get(dbUserContextKey)
if !exists {