Buckets:
| import { isCsrfOriginAllowed } from './csrf-protection' | |
| describe('isCsrfOriginAllowed', () => { | |
| it('should return true when allowedOrigins contains originDomain', () => { | |
| expect(isCsrfOriginAllowed('vercel.com', ['vercel.com'])).toBe(true) | |
| expect(isCsrfOriginAllowed('www.vercel.com', ['www.vercel.com'])).toBe(true) | |
| }) | |
| it('should return true when allowedOrigins contains originDomain with matching pattern', () => { | |
| expect(isCsrfOriginAllowed('asdf.vercel.com', ['*.vercel.com'])).toBe(true) | |
| expect(isCsrfOriginAllowed('asdf.vercel.com', ['**.vercel.com'])).toBe(true) | |
| expect(isCsrfOriginAllowed('asdf.jkl.vercel.com', ['**.vercel.com'])).toBe( | |
| true | |
| ) | |
| }) | |
| it("should correctly handle origins that don't have a TLD (eg for localhost)", () => { | |
| // Single level wildcard | |
| expect(isCsrfOriginAllowed('subdomain.localhost', ['*.localhost'])).toBe( | |
| true | |
| ) | |
| expect(isCsrfOriginAllowed('localhost', ['*.localhost'])).toBe(false) | |
| // Multi-level wildcard | |
| expect(isCsrfOriginAllowed('subdomain.localhost', ['**.localhost'])).toBe( | |
| true | |
| ) | |
| expect(isCsrfOriginAllowed('a.b.localhost', ['**.localhost'])).toBe(true) | |
| expect(isCsrfOriginAllowed('localhost', ['**.localhost'])).toBe(false) | |
| // Exact match | |
| expect(isCsrfOriginAllowed('localhost', ['localhost'])).toBe(true) | |
| expect(isCsrfOriginAllowed('subdomain.localhost', ['localhost'])).toBe( | |
| false | |
| ) | |
| // Multiple patterns | |
| expect( | |
| isCsrfOriginAllowed('subdomain.localhost', ['localhost', '*.localhost']) | |
| ).toBe(true) | |
| expect( | |
| isCsrfOriginAllowed('a.b.localhost', [ | |
| 'localhost', | |
| '*.localhost', | |
| '**.localhost', | |
| ]) | |
| ).toBe(true) | |
| }) | |
| it('should return false when allowedOrigins contains originDomain with non-matching pattern', () => { | |
| expect(isCsrfOriginAllowed('asdf.vercel.com', ['*.vercel.app'])).toBe(false) | |
| expect(isCsrfOriginAllowed('asdf.jkl.vercel.com', ['*.vercel.com'])).toBe( | |
| false | |
| ) | |
| expect(isCsrfOriginAllowed('asdf.jkl.vercel.app', ['**.vercel.com'])).toBe( | |
| false | |
| ) | |
| }) | |
| it('should return false when allowedOrigins does not contain originDomain', () => { | |
| expect(isCsrfOriginAllowed('vercel.com', ['nextjs.org'])).toBe(false) | |
| }) | |
| it('should return false when allowedOrigins is undefined', () => { | |
| expect(isCsrfOriginAllowed('vercel.com', undefined)).toBe(false) | |
| }) | |
| it('should return false when allowedOrigins is empty', () => { | |
| expect(isCsrfOriginAllowed('vercel.com', [])).toBe(false) | |
| }) | |
| it('should return false when allowedOrigins is empty string', () => { | |
| expect(isCsrfOriginAllowed('vercel.com', [''])).toBe(false) | |
| }) | |
| it('wildcards are only supported below the domain level', () => { | |
| expect(isCsrfOriginAllowed('vercel.com', ['*'])).toBe(false) | |
| expect(isCsrfOriginAllowed('vercel.com', ['**'])).toBe(false) | |
| }) | |
| it('should match case-insensitively (RFC 1035)', () => { | |
| // DNS names are case-insensitive per RFC 1035 | |
| expect(isCsrfOriginAllowed('sub.VERCEL.com', ['*.vercel.com'])).toBe(true) | |
| expect(isCsrfOriginAllowed('SUB.vercel.COM', ['*.vercel.com'])).toBe(true) | |
| expect(isCsrfOriginAllowed('VERCEL.COM', ['vercel.com'])).toBe(true) | |
| expect(isCsrfOriginAllowed('vercel.com', ['VERCEL.COM'])).toBe(true) | |
| expect(isCsrfOriginAllowed('Sub.Vercel.Com', ['**.vercel.com'])).toBe(true) | |
| }) | |
| }) | |
Xet Storage Details
- Size:
- 3.42 kB
- Xet hash:
- e9cc2574795e4deb405699a1aa9e21a1d93e392ced41d3f53f8f08a5d803c419
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.