TestKillSwitchRequiresAdmin: all three actions are POSTs, so RoleGate (applied at the group level in production) rejects a viewer with 403.
(t *testing.T)
| 187 | // TestKillSwitchRequiresAdmin: all three actions are POSTs, so RoleGate (applied |
| 188 | // at the group level in production) rejects a viewer with 403. |
| 189 | func TestKillSwitchRequiresAdmin(t *testing.T) { |
| 190 | gin.SetMode(gin.TestMode) |
| 191 | r := gin.New() |
| 192 | grp := r.Group("/api/v1") |
| 193 | grp.Use(func(c *gin.Context) { |
| 194 | c.Set(ctxIdentityKey, &Identity{Email: "viewer@posthog.com", Role: RoleViewer}) |
| 195 | }) |
| 196 | grp.Use(RoleGate()) |
| 197 | registerLiveAPI(grp, &fakeLiveInfo{}, &fakePeerFetcher{}, &fakeUserAdmin{}) |
| 198 | |
| 199 | for _, p := range []string{ |
| 200 | "/api/v1/orgs/acme/users/bob/kill", |
| 201 | "/api/v1/orgs/acme/users/bob/disable", |
| 202 | "/api/v1/orgs/acme/users/bob/enable", |
| 203 | } { |
| 204 | code, _ := doPost(t, r, p) |
| 205 | if code != http.StatusForbidden { |
| 206 | t.Fatalf("%s as viewer: expected 403, got %d", p, code) |
| 207 | } |
| 208 | } |
| 209 | } |
nothing calls this directly
no test coverage detected