mirror of
https://github.com/hansjone/netxops.git
synced 2026-10-19 21:44:06 +08:00
19 lines
673 B
JavaScript
19 lines
673 B
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { apiUrlField } from '../src/client/card-form.ts'
|
|
|
|
test('apiUrlField accepts http(s) and normalizes trailing slash', () => {
|
|
const field = apiUrlField('apiUrl')
|
|
assert.deepEqual(field.parse('http://127.0.0.1:8890/'), {
|
|
kind: 'set',
|
|
value: 'http://127.0.0.1:8890',
|
|
})
|
|
assert.deepEqual(field.parse(''), { kind: 'clear' })
|
|
})
|
|
|
|
test('apiUrlField rejects unsafe URLs', () => {
|
|
const field = apiUrlField('apiUrl')
|
|
assert.equal(field.parse('file:///tmp'), undefined)
|
|
assert.equal(field.parse('http://user:pass@h/'), undefined)
|
|
assert.equal(field.parse('not-a-url'), undefined)
|
|
})
|