forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternalUrl.test.ts
More file actions
23 lines (20 loc) · 1.1 KB
/
Copy pathexternalUrl.test.ts
File metadata and controls
23 lines (20 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { describe, it, expect } from 'vitest'
import { isAllowedExternalScheme } from './externalUrl'
describe('isAllowedExternalScheme', () => {
it('allows a scheme in the allow-list', () => {
expect(isAllowedExternalScheme('https://omi.me', ['http', 'https'])).toBe(true)
expect(isAllowedExternalScheme('http://omi.me', ['http', 'https'])).toBe(true)
expect(isAllowedExternalScheme('mailto:hi@omi.me', ['http', 'https', 'mailto'])).toBe(true)
})
it('blocks a scheme not in the allow-list', () => {
expect(isAllowedExternalScheme('mailto:hi@omi.me', ['http', 'https'])).toBe(false)
expect(isAllowedExternalScheme('file:///etc/passwd', ['http', 'https'])).toBe(false)
// UNC / custom-protocol handler abuse vectors.
expect(isAllowedExternalScheme('\\\\evil\\share', ['http', 'https'])).toBe(false)
expect(isAllowedExternalScheme('omi-agent://run', ['http', 'https'])).toBe(false)
})
it('blocks an unparseable URL', () => {
expect(isAllowedExternalScheme('not a url', ['http', 'https'])).toBe(false)
expect(isAllowedExternalScheme('', ['http', 'https'])).toBe(false)
})
})