Linter.utils.test.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { describe, expect, it } from 'vitest'
  2. import { lintInfoMap } from './Linter.utils'
  3. import { Lint } from '@/data/lint/lint-query'
  4. const projectRef = 'abc'
  5. const trickySchema = 'a&b=c'
  6. const trickyName = 'd e+f'
  7. describe('Linter.utils lintInfoMap link encoding', () => {
  8. const cases: Array<{ name: string; nameParam?: string; hasSchema: boolean }> = [
  9. { name: 'unindexed_foreign_keys', hasSchema: true },
  10. { name: 'unused_index', nameParam: 'table', hasSchema: true },
  11. { name: 'multiple_permissive_policies', nameParam: 'search', hasSchema: true },
  12. { name: 'policy_exists_rls_disabled', nameParam: 'search', hasSchema: true },
  13. { name: 'rls_enabled_no_policy', nameParam: 'search', hasSchema: true },
  14. { name: 'duplicate_index', nameParam: 'table', hasSchema: true },
  15. { name: 'function_search_path_mutable', nameParam: 'search', hasSchema: true },
  16. { name: 'rls_disabled_in_public', nameParam: 'search', hasSchema: true },
  17. { name: 'extension_in_public', nameParam: 'filter', hasSchema: false },
  18. { name: 'sensitive_columns_exposed', nameParam: 'table', hasSchema: true },
  19. { name: 'rls_policy_always_true', nameParam: 'search', hasSchema: true },
  20. { name: 'pg_graphql_anon_table_exposed', nameParam: 'table', hasSchema: true },
  21. { name: 'pg_graphql_authenticated_table_exposed', nameParam: 'table', hasSchema: true },
  22. { name: 'anon_security_definer_function_executable', nameParam: 'search', hasSchema: true },
  23. {
  24. name: 'authenticated_security_definer_function_executable',
  25. nameParam: 'search',
  26. hasSchema: true,
  27. },
  28. ]
  29. for (const { name, nameParam, hasSchema } of cases) {
  30. it(`preserves special characters in metadata for ${name}`, () => {
  31. const info = lintInfoMap.find((entry) => entry.name === name)
  32. expect(info, `expected ${name} in lintInfoMap`).toBeDefined()
  33. const url = info!.link({
  34. projectRef,
  35. metadata: {
  36. schema: trickySchema,
  37. name: trickyName,
  38. } as unknown as Lint['metadata'],
  39. })
  40. const parsed = new URL(url, 'http://example.com')
  41. if (hasSchema) {
  42. expect(parsed.searchParams.get('schema')).toBe(trickySchema)
  43. }
  44. if (nameParam) {
  45. expect(parsed.searchParams.get(nameParam)).toBe(trickyName)
  46. }
  47. })
  48. }
  49. it('preserves slash and space in bucket_id for public_bucket_allows_listing', () => {
  50. const info = lintInfoMap.find((entry) => entry.name === 'public_bucket_allows_listing')
  51. expect(info).toBeDefined()
  52. const url = info!.link({
  53. projectRef,
  54. metadata: {
  55. bucket_id: 'a/b c',
  56. } as unknown as Lint['metadata'],
  57. })
  58. expect(url).toBe('/project/abc/storage/files/buckets/a%2Fb%20c')
  59. })
  60. })