RLSTesterResults.utils.ts20 lines · main
| 1 | import type { ParseQueryResults } from './RLSTester.types' |
| 2 | |
| 3 | export function deriveRLSTestState(parseQueryResults: ParseQueryResults | undefined) { |
| 4 | const isServiceRole = parseQueryResults?.role === undefined |
| 5 | const tableWithRLSEnabledButNoPolicies = parseQueryResults?.tables.find( |
| 6 | (x) => x.isRLSEnabled && x.tablePolicies.length === 0 |
| 7 | ) |
| 8 | const tableWithRLSEnabledWithPolicyFalse = parseQueryResults?.tables.find( |
| 9 | (x) => x.isRLSEnabled && x.tablePolicies.some((y) => y.definition === 'false') |
| 10 | ) |
| 11 | const noAccessToData = |
| 12 | !isServiceRole && (!!tableWithRLSEnabledButNoPolicies || !!tableWithRLSEnabledWithPolicyFalse) |
| 13 | |
| 14 | return { |
| 15 | isServiceRole, |
| 16 | tableWithRLSEnabledButNoPolicies, |
| 17 | tableWithRLSEnabledWithPolicyFalse, |
| 18 | noAccessToData, |
| 19 | } |
| 20 | } |