TestWritePermissionCombinations tests the combined permission check logic that is actually used in the codebase: if !user.CanWriteContent() && !CanWriteContentBypassUserPerms(meta, path) { deny } if !CanWrite(user, meta, path) { deny } This ensures the three-layer permission system w
(t *testing.T)
| 615 | // 2. Meta-level global write permission (CanWriteContentBypassUserPerms) |
| 616 | // 3. Meta-level user whitelist (CanWrite) |
| 617 | func TestWritePermissionCombinations(t *testing.T) { |
| 618 | tests := []struct { |
| 619 | name string |
| 620 | user *model.User |
| 621 | meta *model.Meta |
| 622 | path string |
| 623 | want bool |
| 624 | reason string |
| 625 | checkFirstLayer bool // whether first layer should pass |
| 626 | checkSecondLayer bool // whether second layer should pass |
| 627 | expectedDenyReason string |
| 628 | }{ |
| 629 | // === Scenario 1: User has global write permission === |
| 630 | { |
| 631 | name: "user has CanWriteContent + in WriteUsers whitelist", |
| 632 | user: &model.User{ |
| 633 | ID: 1, |
| 634 | Permission: 1 << 3, // CanWriteContent = true |
| 635 | }, |
| 636 | meta: &model.Meta{ |
| 637 | Path: "/folder", |
| 638 | Write: false, |
| 639 | WriteUsers: []uint{1}, |
| 640 | WriteUsersSub: false, |
| 641 | }, |
| 642 | path: "/folder", |
| 643 | want: true, |
| 644 | reason: "user has global write permission AND is in whitelist", |
| 645 | checkFirstLayer: true, |
| 646 | checkSecondLayer: true, |
| 647 | expectedDenyReason: "", |
| 648 | }, |
| 649 | { |
| 650 | name: "user has CanWriteContent but NOT in WriteUsers whitelist", |
| 651 | user: &model.User{ |
| 652 | ID: 1, |
| 653 | Permission: 1 << 3, // CanWriteContent = true |
| 654 | }, |
| 655 | meta: &model.Meta{ |
| 656 | Path: "/folder", |
| 657 | Write: false, |
| 658 | WriteUsers: []uint{2, 3}, // user 1 not in list |
| 659 | WriteUsersSub: false, |
| 660 | }, |
| 661 | path: "/folder", |
| 662 | want: false, |
| 663 | reason: "even with global write permission, must pass whitelist check", |
| 664 | checkFirstLayer: true, |
| 665 | checkSecondLayer: false, |
| 666 | expectedDenyReason: "whitelist check failed", |
| 667 | }, |
| 668 | |
| 669 | // === Scenario 2: User lacks global permission but meta.Write=true === |
| 670 | { |
| 671 | name: "no CanWriteContent + meta.Write=true + in WriteUsers", |
| 672 | user: &model.User{ |
| 673 | ID: 1, |
| 674 | Permission: 0, // CanWriteContent = false |
nothing calls this directly
no test coverage detected