edgeFunctions.test.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { describe, expect, it } from 'vitest'
  2. import { isValidEdgeFunctionURL } from './edgeFunctions'
  3. describe('isValidEdgeFunctionURL', () => {
  4. const validEdgeFunctionUrls = [
  5. 'https://uniquetwentychararef.supabase.co/functions/v1/hello-world',
  6. 'https://uniquetwentychararef.briven.red/functions/v1/hello-world',
  7. 'https://uniquetwentychararef.briven.red/functions/v3/hello-world',
  8. 'https://uniquetwentychararef.briven.red/functions/v3/hello-world',
  9. ]
  10. const validLocalEdgeFunctionsUrls = [
  11. 'https://projectref.notbriven.com/functions/v1/test',
  12. 'https://notbriven.com/functions/v1/test',
  13. 'http://localhost:54321/functions/v1/test-2',
  14. 'http://kong:8000/functions/v1/hello-world',
  15. 'https://127.0.0.1:54321/functions/v1/test-3',
  16. 'https://127.0.0.1:54321/functions/v1/test-5',
  17. ]
  18. const invalidPlatformEdgeFunctionUrls = [
  19. 'https://notbriven.com/functions/v1/test',
  20. 'https://projectref.notbriven.com/functions/v1/test',
  21. 'https://localhost?https://aaaa.supabase.co/functions/v1/xxx',
  22. 'https://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
  23. 'http://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
  24. ]
  25. const invalidEdgeFunctionUrls = [
  26. 'https://localhost?https://aaaa.supabase.co/functions/v1/xxx',
  27. 'https://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
  28. 'http://localhost:3000/?https://aaaa.supabase.co/functions/v1/xxx',
  29. ]
  30. it('should match valid edge function URLs on platform', () => {
  31. for (const url of validEdgeFunctionUrls) {
  32. expect(isValidEdgeFunctionURL(url, true), `Expected ${url} to be valid`).toBe(true)
  33. }
  34. })
  35. it('should not match local URLs on platform', () => {
  36. for (const url of validLocalEdgeFunctionsUrls) {
  37. expect(isValidEdgeFunctionURL(url, true), `Expected ${url} to be invalid on platform`).toBe(
  38. false
  39. )
  40. }
  41. })
  42. it('should match valid local edge function URLs off platform', () => {
  43. for (const url of validLocalEdgeFunctionsUrls) {
  44. expect(isValidEdgeFunctionURL(url, false), `Expected ${url} to be valid`).toBe(true)
  45. }
  46. })
  47. it('should not match invalid edge function URLs on platform', () => {
  48. for (const url of invalidPlatformEdgeFunctionUrls) {
  49. expect(isValidEdgeFunctionURL(url, true), `Expected ${url} to be invalid`).toBe(false)
  50. }
  51. })
  52. it('should not match invalid edge function URLs off platform', () => {
  53. for (const url of invalidEdgeFunctionUrls) {
  54. expect(isValidEdgeFunctionURL(url, false), `Expected ${url} to be invalid`).toBe(false)
  55. }
  56. })
  57. })