Files
Xen-Orchestra-xen-orchestra…/@xen-orchestra/vmware-explorer/_thumbprint.integ.mjs
Florent BEAUCHAMP 3bf50c38ee fix(vmware-explorer): fixes omnibus (#10363)
This branch is a reliability overhaul of the ESXi/vSphere source side of V2V, plus a scope reduction of the package. The SOAP plumbing is rewritten:

    VimClient wraps @vates/node-vsphere-soap in a promise API with one emitter per call (no more cross-talk between concurrent calls, no listener leak) and a pTimeout;
    vim25 faults are now parsed (_parseFault.mjs) so callers get a real fault type instead of task execution failed;
    the library no longer throws from async callbacks (which killed xo-server) and its beforeExit logout hook is per-client instead of removeAllListeners.
    Request specs are built in explicit schema order (soap/specs.mjs) with xsi:type, and property values are normalized (soap/normalize.mjs) so search() and the new #retrieveProperty share one shape.
    search() now paginates, cancels the retrieval and destroys the container view.
    Datastore HTTP downloads get session-cookie reuse, retry with jittered backoff, a headers-only timeout, and range-honouring validation.
    Task waiting polls with backoff and per-operation timeouts (6 h for snapshot consolidation).
    nbdkit servers are memoized by a key that includes the export options, the readiness wait races the process death instead of sleeping 2 s
    the password file is 0600 and unlinked
    the thumbprint is read over TLS in-process instead of two openssl spawns.
    The old VHD-over-datastore readers (VhdEsxi*, Datastore*, openDeltaVmdkAsVhd) are deleted, hence the majo, rleaving the vddk/NBD path with a COWD grain-directory parser as data-map fallback.
    ~1.7k lines of unit tests are added.
2026-09-11 17:36:38 +02:00

58 lines
2.0 KiB
JavaScript

import assert from 'node:assert/strict'
import { createServer } from 'node:net'
import { describe, it } from 'node:test'
import { findFreePort } from './_nbdkit.mjs'
import { getCertificateThumbprint } from './_thumbprint.mjs'
const noop = () => {}
// the successful path needs a certificate, so it is only exercised against a real host: what is
// covered here are the two failures which used to freeze or terminate the process
describe('getCertificateThumbprint', function () {
it('does not set the TLS server name when the host is an IP address', async function () {
// RFC 6066 forbids it, and node warns `DeprecationWarning DEP0123` before ignoring it
const warnings = []
const onWarning = warning => warnings.push(warning)
process.on('warning', onWarning)
const port = await findFreePort()
try {
await getCertificateThumbprint('127.0.0.1', { port, timeout: 500 }).catch(noop)
// the warning is emitted asynchronously
await new Promise(resolve => setImmediate(resolve))
assert.deepEqual(
warnings.filter(({ code }) => code === 'DEP0123'),
[]
)
} finally {
process.off('warning', onWarning)
}
})
it('rejects when nothing listens', async function () {
const port = await findFreePort()
await assert.rejects(getCertificateThumbprint('127.0.0.1', { port, timeout: 2e3 }), error => {
assert.match(error.message, /^can't read the certificate of 127\.0\.0\.1:/)
assert.equal(error.code, 'ECONNREFUSED')
return true
})
})
it('gives up when the handshake never completes', async function () {
// a port accepting the connection then staying silent, as a black holed host does
const server = createServer()
const port = await findFreePort()
await new Promise(resolve => server.listen(port, '127.0.0.1', resolve))
try {
await assert.rejects(getCertificateThumbprint('127.0.0.1', { port, timeout: 50 }), {
message: `no TLS handshake with 127.0.0.1:${port} after 50ms`,
})
} finally {
server.close()
}
})
})