|
| 1 | +package rights_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/TheManticoreProject/winacl/sddl/rights" |
| 7 | +) |
| 8 | + |
| 9 | +// TestRightToSDDL_CollisionDeterministic verifies that the reverse map resolves |
| 10 | +// the KR/KX mask collision (both 0x00020019) to a stable canonical token. |
| 11 | +func TestRightToSDDL_CollisionDeterministic(t *testing.T) { |
| 12 | + const keyReadExecute = 0x00020019 |
| 13 | + |
| 14 | + got, ok := rights.RightToSDDL[keyReadExecute] |
| 15 | + if !ok { |
| 16 | + t.Fatalf("RightToSDDL[0x%08x] missing", keyReadExecute) |
| 17 | + } |
| 18 | + // "KR" sorts before "KX", so it is the deterministic winner. |
| 19 | + if got != "KR" { |
| 20 | + t.Errorf("RightToSDDL[0x%08x] = %q, want %q", keyReadExecute, got, "KR") |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +// TestRightToSDDL_IsValidInverse verifies that every mask present in the reverse |
| 25 | +// map resolves to a token that maps back to that same mask in SDDLToRight, i.e. |
| 26 | +// the reverse map is a valid inverse for every entry. |
| 27 | +func TestRightToSDDL_IsValidInverse(t *testing.T) { |
| 28 | + for mask, token := range rights.RightToSDDL { |
| 29 | + if rights.SDDLToRight[token] != mask { |
| 30 | + t.Errorf("RightToSDDL[0x%08x] = %q, but SDDLToRight[%q] = 0x%08x", mask, token, token, rights.SDDLToRight[token]) |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + // Every forward mask must be representable in the reverse map. |
| 35 | + for token, mask := range rights.SDDLToRight { |
| 36 | + if _, ok := rights.RightToSDDL[mask]; !ok { |
| 37 | + t.Errorf("mask 0x%08x (from token %q) has no entry in RightToSDDL", mask, token) |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments