mirror of
https://github.com/supabase/supabase.git
synced 2026-06-11 06:19:22 +08:00
## Context Missed another case here - RLS tester when retrieving policies associated with query needs to consider policies with the `ALL` operation <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Added comprehensive tests for Row-Level Security policy filtering, covering schema/table matching, role handling (including public/service-role cases), command/operation semantics, and combined filter behavior. * **Refactor** * Centralized and clarified RLS policy filtering logic used by the tester for improved maintainability and consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
25 lines
669 B
TypeScript
25 lines
669 B
TypeScript
import type { Policy } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
|
|
import type { ParseSQLQueryResponse } from '@/data/misc/parse-query-mutation'
|
|
|
|
export function filterTablePolicies({
|
|
policies,
|
|
schema,
|
|
table,
|
|
role,
|
|
operation,
|
|
}: {
|
|
policies: Policy[]
|
|
schema: string
|
|
table: string
|
|
role: string | undefined
|
|
operation: ParseSQLQueryResponse['operation']
|
|
}): Policy[] {
|
|
return policies.filter(
|
|
(x) =>
|
|
x.schema === schema &&
|
|
x.table === table &&
|
|
(x.roles.includes(role ?? '') || (x.roles.length === 1 && x.roles[0] === 'public')) &&
|
|
(x.command === 'ALL' || x.command === operation)
|
|
)
|
|
}
|