33 lines
1.6 KiB
JavaScript
33 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { createElfArsenalClient, validateHost, validatePort } = require('../../src/services/elf-arsenal-client');
|
|
|
|
test('ELF Arsenal validates the configured endpoint', () => {
|
|
assert.equal(validateHost('192.168.1.105'), '192.168.1.105');
|
|
assert.equal(validatePort('6969'), 6969);
|
|
assert.throws(() => validateHost('http://evil.test'), /geldig PS5-adres/);
|
|
assert.throws(() => validatePort('70000'), /Ongeldige/);
|
|
});
|
|
|
|
test('ELF Arsenal probe returns a stable connected result', async () => {
|
|
const settings = { get(key, fallback) { return key === 'ftp.host' ? '192.168.1.105' : key === 'elfArsenal.port' ? 6969 : fallback; } };
|
|
const client = createElfArsenalClient({
|
|
settings,
|
|
fetchImpl: async url => {
|
|
assert.equal(url, 'http://192.168.1.105:6969/version');
|
|
return { ok: true, status: 200, text: async () => JSON.stringify({ tag: 'v1.2.3' }) };
|
|
},
|
|
});
|
|
assert.deepEqual(await client.probe(), { connected: true, url: 'http://192.168.1.105:6969/', version: 'v1.2.3', tag: 'v1.2.3' });
|
|
});
|
|
|
|
test('ELF Arsenal reports that the payload must be started when unreachable', async () => {
|
|
const settings = { get(key, fallback) { return key === 'ftp.host' ? '192.168.1.105' : fallback; } };
|
|
const client = createElfArsenalClient({ settings, fetchImpl: async () => { throw new Error('ECONNREFUSED'); } });
|
|
const result = await client.probe();
|
|
assert.equal(result.connected, false);
|
|
assert.match(result.error, /Start of verstuur eerst de ELF Arsenal-payload/);
|
|
});
|