RLSTesterResults.utils.ts 769 B

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