mirror of
https://github.com/renorris/openfsd
synced 2026-08-12 12:25:40 +08:00
fix: address review feedback for Bearer actor revalidation
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user