Files
supabase/studio/tests/unit/destructive-query-check.test.ts
T
Greg Richardson 285a299b9b Fix: SQL Editor destructive query false positive (#17965)
fix(sql-editor): destructive query false positive
2023-10-05 16:06:35 -02:30

59 lines
1.6 KiB
TypeScript

import { stripIndent } from 'common-tags'
import { checkDestructiveQuery } from 'components/interfaces/SQLEditor/SQLEditor.utils'
describe(`destructive query check`, () => {
it('drop statement matches', () => {
const match = checkDestructiveQuery('drop table films, distributors;')
expect(match).toBe(true)
})
it('truncate statement matches', () => {
const match = checkDestructiveQuery('truncate films;')
expect(match).toBe(true)
})
it('delete statement matches', () => {
const match = checkDestructiveQuery("delete from films where kind <> 'Musical';")
expect(match).toBe(true)
})
it('delete statement after another statement matches', () => {
const match = checkDestructiveQuery(stripIndent`
select * from films;
delete from films where kind <> 'Musical';
`)
expect(match).toBe(true)
})
it("rls policy containing delete doesn't match", () => {
const match = checkDestructiveQuery(stripIndent`
create policy "Users can delete their own files"
on storage.objects for delete to authenticated using (
bucket id = 'files' and auth.uid () = owner
);
`)
expect(match).toBe(false)
})
it('capitalized statement matches', () => {
const match = checkDestructiveQuery("DELETE FROM films WHERE kind <> 'Musical';")
expect(match).toBe(true)
})
it("comment containing keyword doesn't match", () => {
const match = checkDestructiveQuery(stripIndent`
-- Going to drop this in here, might delete later
select * from films;
`)
expect(match).toBe(false)
})
})