mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-10-08 10:56:13 -08:00
Persist central network intent and compile complete per-device configs with secure credentials, ACL policy, and dedicated Gateway runtimes. Expose network, credential, device registry, and runtime observation APIs. Treat central management and external Console as alternative consumers of the upstream ClientManager. Register central devices through a local webhook handler and publish through existing runtime reconciliation. Serialize public mutations with enrollment, reject direct credential changes to managed instances, and retain REST revision invalidation. Keep Gateway lifecycle publication in the central service and remove obsolete incremental result bookkeeping. Restore persisted networks and retire orphan runtimes through the same serialized publisher. Add Core and protocol support for Gateway and WireGuard management, including GUI bindings and serialized GUI config writes. Bootstrap IPv4 for DHCP-only networks and retain assigned addresses without peer IPv4. Cover intent transactions, complete configuration publication, offline recovery, authentication, revocation, Gateway lifecycle, and DHCP. Validate central candidates before persistence using Core URL, config, and portal-client rules. Reject unsupported peer schemes, unconvertible proxy subnets, and invalid portal clients without changing live intent. Expose existing pure Core validators without changing runtime behavior. Gate API-facing credential validation on API-enabled Core builds so minimal WASM targets do not reference omitted management types. Preserve session-backed device views in external Console mode. Bound Gateway admissions without cancelling transport upgrades, and cancel pending peer handshakes before retiring runtimes. Batch registry reads and bound runtime observation concurrency. Randomize DHCP bootstrap and conflict retries, keep an advertised current subnet, and select fallback subnets deterministically. Cover concurrent startup, Gateway admission lifetime, and external Console regressions. Allow DHCP bootstrap with no remote routes. Count network members through one tenant-scoped query without write transactions. Cover zero- peer allocation and tenant/empty-network counts. Preserve direct Web configurations and disabled states in central device snapshots. Remove obsolete central rows atomically with membership changes. Stop online managed instances before deleting or blocking devices, retaining intent when shutdown or deletion fails. Persist automatic IPv4 allocations separately from manual overrides so subnet changes reallocate only automatic members. Normalize mapped proxy routes to their advertised CIDRs when granting temporary credentials. Cover publication, deletion rollback, subnet migration, and grant updates. Read central intent in deferred transactions so polling does not reserve the SQLite writer lock. Test reads with an active writer and assert the temporary-member secret constraint using a valid device fixture. Persist patched WireGuard clients from the saved Web or GUI candidate without a follow-up RPC. Preserve pending settings and ownership, and cover disconnects and failed patches. Resolve named credential and config mutations against the live Core instance before checking central ownership. Forward authorized mutations by UUID on the same session, including while network renames are pending. Cover all mutation methods and preserve direct Console behavior. * feat(web-ui): add central network console and WireGuard management Add network and device views with central membership, credentials, ACL policy, temporary peers, and per-instance runtime details. Update console navigation, styling, theme handling, and API clients. Extend shared configuration and status components for central networks. Add a WireGuard portal dialog for setup and running-device management, with matching translations and network configuration types. Use secure UUID generation on HTTP, discard stale member configuration responses, and stop node-detail polling when the component unmounts. Update frontend workspace dependencies and include component, dashboard, configuration serialization, and central console end-to-end tests. Add isolated real-Core E2E coverage for central data-plane traffic, ACL, DHCP, recovery, device lifecycle, and native WireGuard clients. Record all 59 functional checks with evidence and confirmed validation/UI defects; keep runtime artifacts and test credentials out of Git. Normalize protobuf logger levels and render translated labels correctly. Cover all six levels across setting, reload, and language changes. Add real configuration-rejection E2E checks for database and Core stability and uninterrupted traffic, and record the resolved audit findings. Gate central navigation and registry actions by console mode. Refresh WireGuard settings on mounted status views and preserve explicit portal listener endpoints. Explain the trusted permanent-member ACL boundary. Cover external Console rendering, portal refresh retries and teardown, and explicit IPv4/IPv6 listener exports. Preserve PublicServer discovery when saving its settings, including when its URL matches the Gateway. Cover renaming and endpoint edits in the browser. Display automatic member addresses without converting them to manual overrides during edits. Derive offline address prefixes from the network subnet. Add browser regression coverage and real-Core checks for direct configuration preservation, temporary proxy mappings, automatic subnet migration, and shutdown before device deletion. Build enrollment commands from the configured API hostname, including IPv6 and relative endpoints. Use the PublicServer connector in temporary credential CLI and TOML exports. Add browser regression coverage. Preserve form credentials across repeated normalization and GUI storage reloads. Keep explicit form values authoritative over backend keys and cover JSON persistence, idempotence, replacement, and clearing.
648 lines
21 KiB
TypeScript
648 lines
21 KiB
TypeScript
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import { defineComponent, h, nextTick, reactive } from 'vue'
|
|
import Config from '../src/components/Config.vue'
|
|
import {
|
|
DEFAULT_NETWORK_CONFIG,
|
|
normalizeNetworkConfig,
|
|
toBackendNetworkConfig,
|
|
type NetworkConfig,
|
|
} from '../src/types/network'
|
|
|
|
const CONFIG_FLAG_FIELDS = [
|
|
'latency_first',
|
|
'use_smoltcp',
|
|
'disable_ipv6',
|
|
'ipv6_public_addr_auto',
|
|
'enable_kcp_proxy',
|
|
'disable_kcp_input',
|
|
'enable_quic_proxy',
|
|
'disable_quic_input',
|
|
'disable_p2p',
|
|
'p2p_only',
|
|
'lazy_p2p',
|
|
'bind_device',
|
|
'no_tun',
|
|
'enable_exit_node',
|
|
'relay_all_peer_rpc',
|
|
'need_p2p',
|
|
'multi_thread',
|
|
'proxy_forward_by_system',
|
|
'disable_encryption',
|
|
'disable_tcp_hole_punching',
|
|
'disable_udp_hole_punching',
|
|
'enable_udp_broadcast_relay',
|
|
'disable_upnp',
|
|
'disable_sym_hole_punching',
|
|
'enable_magic_dns',
|
|
'enable_private_mode',
|
|
] as const satisfies readonly (keyof NetworkConfig)[]
|
|
|
|
const CONFIG_CHECKBOX_FIELDS = [
|
|
['dhcp', '#virtual_ip_auto'],
|
|
...CONFIG_FLAG_FIELDS.map((field) => [field, `#${field}`] as const),
|
|
] as const satisfies readonly (readonly [keyof NetworkConfig, string])[]
|
|
|
|
const CONFIG_TOGGLE_FIELDS = [
|
|
'enable_relay_network_whitelist',
|
|
'enable_manual_routes',
|
|
'enable_socks5',
|
|
] as const satisfies readonly (keyof NetworkConfig)[]
|
|
|
|
const CONFIG_UI_BOOLEAN_FIELDS = [
|
|
...CONFIG_CHECKBOX_FIELDS.map(([field]) => field),
|
|
...CONFIG_TOGGLE_FIELDS,
|
|
] as const satisfies readonly (keyof NetworkConfig)[]
|
|
|
|
vi.mock('vue-i18n', () => ({
|
|
useI18n: () => ({
|
|
t: (key: string, values?: unknown[]) => values ? `${key}:${values.join(',')}` : key,
|
|
}),
|
|
}))
|
|
|
|
const PassThrough = defineComponent({
|
|
name: 'PassThrough',
|
|
setup(_, { slots }) {
|
|
return () => h('div', slots.default?.())
|
|
},
|
|
})
|
|
|
|
const PanelStub = defineComponent({
|
|
name: 'Panel',
|
|
props: {
|
|
header: String,
|
|
},
|
|
setup(props, { slots }) {
|
|
return () => h('section', { 'data-stub': 'panel', 'data-header': props.header }, slots.default?.())
|
|
},
|
|
})
|
|
|
|
const DividerStub = defineComponent({
|
|
name: 'Divider',
|
|
setup() {
|
|
return () => h('hr', { 'data-stub': 'divider' })
|
|
},
|
|
})
|
|
|
|
function splitList(value: string): string[] {
|
|
return value.split(',').map((item) => item.trim()).filter((item) => item.length > 0)
|
|
}
|
|
|
|
const InputTextStub = defineComponent({
|
|
name: 'InputText',
|
|
props: {
|
|
modelValue: [String, Number],
|
|
id: String,
|
|
disabled: Boolean,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { attrs, emit }) {
|
|
return () => h('input', {
|
|
...attrs,
|
|
id: props.id,
|
|
disabled: props.disabled,
|
|
value: props.modelValue ?? '',
|
|
'data-stub': 'input-text',
|
|
onInput: (event: Event) => emit('update:modelValue', (event.target as HTMLInputElement).value),
|
|
})
|
|
},
|
|
})
|
|
|
|
const PasswordStub = defineComponent({
|
|
name: 'Password',
|
|
props: {
|
|
modelValue: [String, Number],
|
|
id: String,
|
|
disabled: Boolean,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { attrs, emit }) {
|
|
return () => h('input', {
|
|
...attrs,
|
|
id: props.id,
|
|
disabled: props.disabled,
|
|
type: 'password',
|
|
value: props.modelValue ?? '',
|
|
'data-stub': 'password',
|
|
onInput: (event: Event) => emit('update:modelValue', (event.target as HTMLInputElement).value),
|
|
})
|
|
},
|
|
})
|
|
|
|
const InputNumberStub = defineComponent({
|
|
name: 'InputNumber',
|
|
props: {
|
|
modelValue: Number,
|
|
id: String,
|
|
inputId: String,
|
|
disabled: Boolean,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { attrs, emit }) {
|
|
return () => h('input', {
|
|
...attrs,
|
|
id: props.id ?? props.inputId,
|
|
disabled: props.disabled,
|
|
type: 'number',
|
|
value: props.modelValue ?? '',
|
|
'data-stub': 'input-number',
|
|
onInput: (event: Event) => {
|
|
const value = (event.target as HTMLInputElement).value
|
|
emit('update:modelValue', value === '' ? null : Number(value))
|
|
},
|
|
})
|
|
},
|
|
})
|
|
|
|
const CheckboxStub = defineComponent({
|
|
name: 'Checkbox',
|
|
props: {
|
|
modelValue: Boolean,
|
|
inputId: String,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { attrs, emit }) {
|
|
return () => h('input', {
|
|
...attrs,
|
|
id: props.inputId,
|
|
checked: props.modelValue,
|
|
type: 'checkbox',
|
|
'data-stub': 'checkbox',
|
|
onChange: (event: Event) => emit('update:modelValue', (event.target as HTMLInputElement).checked),
|
|
})
|
|
},
|
|
})
|
|
|
|
const ToggleButtonStub = defineComponent({
|
|
name: 'ToggleButton',
|
|
props: {
|
|
modelValue: Boolean,
|
|
onIcon: String,
|
|
offIcon: String,
|
|
onLabel: String,
|
|
offLabel: String,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { emit }) {
|
|
return () => h('button', {
|
|
type: 'button',
|
|
'aria-pressed': String(Boolean(props.modelValue)),
|
|
'data-stub': 'toggle-button',
|
|
onClick: () => emit('update:modelValue', !props.modelValue),
|
|
}, props.modelValue ? props.onLabel : props.offLabel)
|
|
},
|
|
})
|
|
|
|
const AutoCompleteStub = defineComponent({
|
|
name: 'AutoComplete',
|
|
props: {
|
|
modelValue: Array,
|
|
id: String,
|
|
multiple: Boolean,
|
|
},
|
|
emits: ['update:modelValue', 'complete'],
|
|
setup(props, { attrs, emit }) {
|
|
return () => h('input', {
|
|
...attrs,
|
|
id: props.id,
|
|
value: (props.modelValue ?? []).join(','),
|
|
'data-stub': 'auto-complete',
|
|
onInput: (event: Event) => emit('update:modelValue', splitList((event.target as HTMLInputElement).value)),
|
|
})
|
|
},
|
|
})
|
|
|
|
const MultiSelectStub = defineComponent({
|
|
name: 'MultiSelect',
|
|
props: {
|
|
modelValue: Array,
|
|
inputId: String,
|
|
appendTo: String,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { attrs, emit }) {
|
|
return () => h('input', {
|
|
...attrs,
|
|
id: props.inputId,
|
|
'data-append-to': props.appendTo,
|
|
value: (props.modelValue ?? []).join(','),
|
|
'data-stub': 'multi-select',
|
|
onInput: (event: Event) => emit('update:modelValue', splitList((event.target as HTMLInputElement).value)),
|
|
})
|
|
},
|
|
})
|
|
|
|
const UrlListInputStub = defineComponent({
|
|
name: 'UrlListInput',
|
|
props: {
|
|
modelValue: Array,
|
|
id: String,
|
|
addLabel: String,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { attrs, emit }) {
|
|
return () => h('input', {
|
|
...attrs,
|
|
id: props.id,
|
|
value: (props.modelValue ?? []).join(','),
|
|
'data-stub': 'url-list-input',
|
|
'data-add-label': props.addLabel,
|
|
onInput: (event: Event) => emit('update:modelValue', splitList((event.target as HTMLInputElement).value)),
|
|
})
|
|
},
|
|
})
|
|
|
|
const SelectButtonStub = defineComponent({
|
|
name: 'SelectButton',
|
|
props: {
|
|
modelValue: String,
|
|
options: Array,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props, { emit }) {
|
|
return () => h('select', {
|
|
value: props.modelValue,
|
|
'data-stub': 'select-button',
|
|
onChange: (event: Event) => emit('update:modelValue', (event.target as HTMLSelectElement).value),
|
|
}, (props.options ?? []).map((option) => h('option', { value: option as string }, option as string)))
|
|
},
|
|
})
|
|
|
|
const ButtonStub = defineComponent({
|
|
name: 'Button',
|
|
props: {
|
|
label: String,
|
|
icon: String,
|
|
disabled: Boolean,
|
|
},
|
|
emits: ['click'],
|
|
setup(props, { slots, emit }) {
|
|
return () => h('button', {
|
|
type: 'button',
|
|
disabled: props.disabled,
|
|
'data-label': props.label ?? props.icon,
|
|
onClick: (event: MouseEvent) => emit('click', event),
|
|
}, slots.default?.() ?? props.label ?? props.icon)
|
|
},
|
|
})
|
|
|
|
const DialogStub = defineComponent({
|
|
name: 'Dialog',
|
|
props: {
|
|
visible: Boolean,
|
|
},
|
|
setup(props, { slots }) {
|
|
return () => h('div', { hidden: !props.visible, 'data-stub': 'dialog' }, [
|
|
slots.default?.(),
|
|
slots.footer?.(),
|
|
])
|
|
},
|
|
})
|
|
|
|
const AclManagerStub = defineComponent({
|
|
name: 'AclManager',
|
|
props: {
|
|
modelValue: Object,
|
|
},
|
|
emits: ['update:modelValue'],
|
|
setup(props) {
|
|
return () => h('pre', { 'data-stub': 'acl-manager' }, JSON.stringify(props.modelValue))
|
|
},
|
|
})
|
|
|
|
function makeConfig(): NetworkConfig {
|
|
const config = DEFAULT_NETWORK_CONFIG()
|
|
|
|
return {
|
|
...config,
|
|
dhcp: false,
|
|
virtual_ipv4: '10.1.2.3',
|
|
network_length: 24,
|
|
network_name: 'mesh-a',
|
|
network_secret: 'secret-a',
|
|
peer_urls: ['tcp://peer-a:11010', 'udp://peer-b:11010'],
|
|
latency_first: true,
|
|
use_smoltcp: true,
|
|
disable_ipv6: true,
|
|
no_tun: true,
|
|
hostname: 'host-a',
|
|
proxy_cidrs: ['10.10.0.0/16', '172.16.1.0/24'],
|
|
vpn_portal_config: {
|
|
wireguard_listen: '0.0.0.0:22023',
|
|
wireguard_private_key: 'portal-private-key',
|
|
clients: [{
|
|
name: 'phone-a',
|
|
virtual_ip: '10.1.2.10/24',
|
|
groups: ['ops'],
|
|
}],
|
|
},
|
|
listener_urls: ['tcp://0.0.0.0:12010'],
|
|
dev_name: 'tun-test',
|
|
mtu: 1280,
|
|
instance_recv_bps_limit: '9007199254740993',
|
|
enable_relay_network_whitelist: true,
|
|
relay_network_whitelist: ['network-a'],
|
|
enable_manual_routes: true,
|
|
routes: ['192.168.0.0/16'],
|
|
enable_socks5: true,
|
|
socks5_port: 1086,
|
|
exit_nodes: ['exit-a'],
|
|
mapped_listeners: ['tcp://127.0.0.1:22000'],
|
|
port_forwards: [{
|
|
proto: 'udp',
|
|
bind_ip: '0.0.0.0',
|
|
bind_port: 18080,
|
|
dst_ip: '10.0.0.2',
|
|
dst_port: 8080,
|
|
}],
|
|
}
|
|
}
|
|
|
|
function mountConfig(config: NetworkConfig = makeConfig()) {
|
|
const curNetwork = reactive(config) as NetworkConfig
|
|
const wrapper = mount(Config, {
|
|
props: {
|
|
curNetwork,
|
|
hostname: 'host-from-prop',
|
|
},
|
|
global: {
|
|
directives: {
|
|
tooltip: () => {},
|
|
},
|
|
stubs: {
|
|
AclManager: AclManagerStub,
|
|
AutoComplete: AutoCompleteStub,
|
|
Button: ButtonStub,
|
|
Checkbox: CheckboxStub,
|
|
Dialog: DialogStub,
|
|
Divider: DividerStub,
|
|
InputGroup: PassThrough,
|
|
InputGroupAddon: PassThrough,
|
|
InputNumber: InputNumberStub,
|
|
InputText: InputTextStub,
|
|
MultiSelect: MultiSelectStub,
|
|
Panel: PanelStub,
|
|
Password: PasswordStub,
|
|
SelectButton: SelectButtonStub,
|
|
ToggleButton: ToggleButtonStub,
|
|
UrlListInput: UrlListInputStub,
|
|
},
|
|
},
|
|
})
|
|
|
|
return { curNetwork, wrapper }
|
|
}
|
|
|
|
function input(wrapper: VueWrapper, selector: string): HTMLInputElement {
|
|
return wrapper.find(selector).element as HTMLInputElement
|
|
}
|
|
|
|
async function setInput(wrapper: VueWrapper, selector: string, value: string) {
|
|
await wrapper.find(selector).setValue(value)
|
|
await nextTick()
|
|
}
|
|
|
|
describe('Config.vue network config projection', () => {
|
|
it('projects config values into the visible form controls', async () => {
|
|
const { curNetwork, wrapper } = mountConfig()
|
|
await nextTick()
|
|
|
|
expect(input(wrapper, '#network_name').value).toBe('mesh-a')
|
|
expect(input(wrapper, '#network_secret').value).toBe('secret-a')
|
|
expect(input(wrapper, '#virtual_ip').value).toBe('10.1.2.3')
|
|
expect(input(wrapper, '#initial_nodes').value).toBe('tcp://peer-a:11010,udp://peer-b:11010')
|
|
expect(input(wrapper, '#virtual_ip_auto').checked).toBe(false)
|
|
expect(input(wrapper, '#latency_first').checked).toBe(true)
|
|
expect(input(wrapper, '#use_smoltcp').checked).toBe(true)
|
|
expect(input(wrapper, '#disable_ipv6').checked).toBe(true)
|
|
expect(input(wrapper, '#no_tun').checked).toBe(true)
|
|
|
|
expect(input(wrapper, '#hostname').value).toBe('host-a')
|
|
expect(input(wrapper, '#subnet-proxy').value).toBe('10.10.0.0/16,172.16.1.0/24')
|
|
expect(input(wrapper, '#vpn_portal_wireguard_listen').value).toBe('0.0.0.0:22023')
|
|
expect(input(wrapper, '#dev_name').value).toBe('tun-test')
|
|
expect(input(wrapper, '#mtu').value).toBe('1280')
|
|
expect(input(wrapper, '#instance_recv_bps_limit').value).toBe('9007199254740993')
|
|
expect(input(wrapper, '#relay_network_whitelist').value).toBe('network-a')
|
|
expect(input(wrapper, '#routes').value).toBe('192.168.0.0/16')
|
|
expect(input(wrapper, '#socks5_port').value).toBe('1086')
|
|
expect(input(wrapper, '#exit_nodes').value).toBe('exit-a')
|
|
expect(input(wrapper, 'input[data-add-label="add_listener_url"]').value).toBe('tcp://0.0.0.0:12010')
|
|
expect(input(wrapper, 'input[data-add-label="add_mapped_listener"]').value).toBe('tcp://127.0.0.1:22000')
|
|
|
|
expect(wrapper.find<HTMLSelectElement>('select[data-stub="select-button"]').element.value).toBe('udp')
|
|
expect(input(wrapper, 'input[placeholder="port_forwards_bind_addr"]').value).toBe('0.0.0.0')
|
|
expect(input(wrapper, 'input[placeholder="port_forwards_dst_addr"]').value).toBe('10.0.0.2')
|
|
expect(wrapper.findComponent(AclManagerStub).props('modelValue')).toStrictEqual(curNetwork.acl)
|
|
})
|
|
|
|
it('projects form edits back into config and backend JSON', async () => {
|
|
const { curNetwork, wrapper } = mountConfig()
|
|
await nextTick()
|
|
|
|
await wrapper.find('#virtual_ip_auto').setValue(false)
|
|
await setInput(wrapper, '#network_name', 'mesh-edited')
|
|
await setInput(wrapper, '#network_secret', 'secret-edited')
|
|
await setInput(wrapper, '#virtual_ip', '10.7.7.7')
|
|
await setInput(wrapper, '#initial_nodes', ' tcp://peer-x:11010, , udp://peer-y:11010 ')
|
|
await wrapper.find('#no_tun').setValue(false)
|
|
await wrapper.find('#disable_ipv6').setValue(false)
|
|
await setInput(wrapper, '#hostname', 'host-edited')
|
|
await setInput(wrapper, '#subnet-proxy', '10.7.0.0/16,172.17.0.0/16')
|
|
await setInput(wrapper, '#vpn_portal_wireguard_listen', '[::]:23000')
|
|
await setInput(wrapper, 'input[data-add-label="add_listener_url"]', 'tcp://0.0.0.0:13010')
|
|
await setInput(wrapper, '#dev_name', 'tun-edited')
|
|
await setInput(wrapper, '#mtu', '1260')
|
|
await setInput(wrapper, '#instance_recv_bps_limit', '9007199254740993')
|
|
await setInput(wrapper, '#relay_network_whitelist', 'network-edited')
|
|
await setInput(wrapper, '#routes', '192.168.10.0/24')
|
|
await setInput(wrapper, '#socks5_port', '1089')
|
|
await setInput(wrapper, '#exit_nodes', 'exit-edited')
|
|
await setInput(wrapper, 'input[data-add-label="add_mapped_listener"]', 'tcp://127.0.0.1:23000')
|
|
await wrapper.find('select[data-stub="select-button"]').setValue('tcp')
|
|
await setInput(wrapper, 'input[placeholder="port_forwards_bind_addr"]', '127.0.0.1')
|
|
await setInput(wrapper, 'input[placeholder="port_forwards_dst_addr"]', '10.9.0.2')
|
|
|
|
const portNumbers = wrapper.findAll<HTMLInputElement>('input#horizontal-buttons')
|
|
await portNumbers[1].setValue('19090')
|
|
await portNumbers[2].setValue('9090')
|
|
|
|
expect(curNetwork).toMatchObject({
|
|
dhcp: false,
|
|
virtual_ipv4: '10.7.7.7',
|
|
network_name: 'mesh-edited',
|
|
network_secret: 'secret-edited',
|
|
peer_urls: ['tcp://peer-x:11010', 'udp://peer-y:11010'],
|
|
no_tun: false,
|
|
disable_ipv6: false,
|
|
hostname: 'host-edited',
|
|
proxy_cidrs: ['10.7.0.0/16', '172.17.0.0/16'],
|
|
vpn_portal_config: {
|
|
wireguard_listen: '[::]:23000',
|
|
wireguard_private_key: 'portal-private-key',
|
|
clients: [{
|
|
name: 'phone-a',
|
|
virtual_ip: '10.1.2.10/24',
|
|
groups: ['ops'],
|
|
}],
|
|
},
|
|
listener_urls: ['tcp://0.0.0.0:13010'],
|
|
dev_name: 'tun-edited',
|
|
mtu: 1260,
|
|
instance_recv_bps_limit: '9007199254740993',
|
|
relay_network_whitelist: ['network-edited'],
|
|
routes: ['192.168.10.0/24'],
|
|
socks5_port: 1089,
|
|
exit_nodes: ['exit-edited'],
|
|
mapped_listeners: ['tcp://127.0.0.1:23000'],
|
|
port_forwards: [{
|
|
proto: 'tcp',
|
|
bind_ip: '127.0.0.1',
|
|
bind_port: 19090,
|
|
dst_ip: '10.9.0.2',
|
|
dst_port: 9090,
|
|
}],
|
|
})
|
|
|
|
const backend = toBackendNetworkConfig(curNetwork)
|
|
expect(backend).toMatchObject({
|
|
virtual_ipv4: '10.7.7.7',
|
|
network_name: 'mesh-edited',
|
|
network_secret: 'secret-edited',
|
|
peer_urls: ['tcp://peer-x:11010', 'udp://peer-y:11010'],
|
|
listener_urls: ['tcp://0.0.0.0:13010'],
|
|
mtu: 1260,
|
|
instance_recv_bps_limit: '9007199254740993',
|
|
vpn_portal_config: {
|
|
wireguard_listen: '[::]:23000',
|
|
wireguard_private_key: 'portal-private-key',
|
|
clients: [{
|
|
name: 'phone-a',
|
|
virtual_ip: '10.1.2.10/24',
|
|
groups: ['ops'],
|
|
}],
|
|
},
|
|
port_forwards: [{
|
|
proto: 'tcp',
|
|
bind_ip: '127.0.0.1',
|
|
bind_port: 19090,
|
|
dst_ip: '10.9.0.2',
|
|
dst_port: 9090,
|
|
}],
|
|
})
|
|
})
|
|
|
|
it('round-trips every visible boolean config control into backend JSON', async () => {
|
|
const config = makeConfig()
|
|
const originalFlagValues = new Map(
|
|
CONFIG_UI_BOOLEAN_FIELDS.map((field, index) => {
|
|
const value = index % 2 === 0
|
|
config[field] = value
|
|
return [field, value]
|
|
}),
|
|
)
|
|
|
|
const { curNetwork, wrapper } = mountConfig(config)
|
|
await nextTick()
|
|
|
|
for (const [field, selector] of CONFIG_CHECKBOX_FIELDS) {
|
|
const value = originalFlagValues.get(field)
|
|
expect(input(wrapper, selector).checked, `${field} should project into UI`).toBe(value)
|
|
await wrapper.find(selector).setValue(!value)
|
|
await nextTick()
|
|
}
|
|
|
|
const toggleButtons = wrapper.findAll('button[data-stub="toggle-button"]')
|
|
expect(toggleButtons).toHaveLength(CONFIG_TOGGLE_FIELDS.length)
|
|
for (const [index, field] of CONFIG_TOGGLE_FIELDS.entries()) {
|
|
const value = originalFlagValues.get(field)
|
|
const toggle = toggleButtons[index]
|
|
expect(toggle.attributes('aria-pressed'), `${field} should project into UI`)
|
|
.toBe(String(value))
|
|
await toggle.trigger('click')
|
|
await nextTick()
|
|
}
|
|
|
|
const backend = toBackendNetworkConfig(curNetwork) as Record<string, unknown>
|
|
for (const [field, value] of originalFlagValues) {
|
|
const expectedValue = !value
|
|
expect(curNetwork[field], `${field} should update config`).toBe(expectedValue)
|
|
expect(backend[field], `${field} should be preserved in backend JSON`).toBe(expectedValue)
|
|
}
|
|
})
|
|
|
|
it('generates a private key on enable and preserves devices across disable and reload', async () => {
|
|
const { curNetwork, wrapper } = mountConfig(DEFAULT_NETWORK_CONFIG())
|
|
await nextTick()
|
|
expect(input(wrapper, '#vpn_portal_enabled').checked).toBe(false)
|
|
|
|
await wrapper.find('#vpn_portal_enabled').setValue(true)
|
|
const key = curNetwork.vpn_portal_config!.wireguard_private_key!
|
|
expect(atob(key)).toHaveLength(32)
|
|
expect(curNetwork.vpn_portal_config!.wireguard_listen).toBe('0.0.0.0:22022')
|
|
expect(wrapper.find('#vpn_portal_wireguard_private_key').exists()).toBe(false)
|
|
expect(wrapper.find('#vpn_portal_client_name_0').exists()).toBe(false)
|
|
curNetwork.vpn_portal_config!.clients.push({ name: 'phone', virtual_ip: '10.0.0.2/24', groups: [] })
|
|
|
|
await wrapper.find('#vpn_portal_enabled').setValue(false)
|
|
expect(curNetwork.vpn_portal_config!.enabled).toBe(false)
|
|
const restored = normalizeNetworkConfig(toBackendNetworkConfig(curNetwork))
|
|
const reloaded = mountConfig(restored)
|
|
await nextTick()
|
|
expect(input(reloaded.wrapper, '#vpn_portal_enabled').checked).toBe(false)
|
|
await reloaded.wrapper.find('#vpn_portal_enabled').setValue(true)
|
|
expect(reloaded.curNetwork.vpn_portal_config).toMatchObject({
|
|
enabled: true,
|
|
wireguard_private_key: key,
|
|
clients: [{ name: 'phone', virtual_ip: '10.0.0.2/24' }],
|
|
})
|
|
})
|
|
|
|
it('preserves existing keys and completes older enabled configurations without one', async () => {
|
|
const original = makeConfig()
|
|
const existing = mountConfig(original)
|
|
await nextTick()
|
|
expect(existing.curNetwork.vpn_portal_config!.wireguard_private_key).toBe('portal-private-key')
|
|
const incomplete = makeConfig()
|
|
delete incomplete.vpn_portal_config!.wireguard_private_key
|
|
const generated = mountConfig(incomplete)
|
|
await nextTick()
|
|
expect(atob(generated.curNetwork.vpn_portal_config!.wireguard_private_key!)).toHaveLength(32)
|
|
})
|
|
|
|
it('keeps uint64 input editable without losing large values', async () => {
|
|
const { curNetwork, wrapper } = mountConfig()
|
|
await nextTick()
|
|
|
|
await setInput(wrapper, '#instance_recv_bps_limit', '1234')
|
|
expect(curNetwork.instance_recv_bps_limit).toBe(1234)
|
|
|
|
await setInput(wrapper, '#instance_recv_bps_limit', 'not-a-number')
|
|
expect(curNetwork.instance_recv_bps_limit).toBe(1234)
|
|
|
|
await setInput(wrapper, '#instance_recv_bps_limit', '0')
|
|
expect(curNetwork.instance_recv_bps_limit).toBeNull()
|
|
expect(input(wrapper, '#instance_recv_bps_limit').value).toBe('')
|
|
|
|
await setInput(wrapper, '#instance_recv_bps_limit', '9007199254740993')
|
|
expect(curNetwork.instance_recv_bps_limit).toBe('9007199254740993')
|
|
|
|
await setInput(wrapper, '#instance_recv_bps_limit', '18446744073709551616')
|
|
expect(curNetwork.instance_recv_bps_limit).toBe('9007199254740993')
|
|
|
|
await setInput(wrapper, '#instance_recv_bps_limit', '')
|
|
expect(curNetwork.instance_recv_bps_limit).toBeNull()
|
|
})
|
|
|
|
it('emits runNetwork with the current projected config', async () => {
|
|
const { curNetwork, wrapper } = mountConfig()
|
|
await nextTick()
|
|
|
|
await setInput(wrapper, '#network_name', 'mesh-running')
|
|
await wrapper.find('button[data-label="run_network"]').trigger('click')
|
|
|
|
expect(wrapper.emitted('runNetwork')?.[0]).toEqual([curNetwork])
|
|
expect((wrapper.emitted('runNetwork')?.[0][0] as NetworkConfig).network_name).toBe('mesh-running')
|
|
})
|
|
})
|