-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathtest-transport.js
More file actions
37 lines (29 loc) · 1.63 KB
/
Copy pathtest-transport.js
File metadata and controls
37 lines (29 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2026 Quantova Inc
// SPDX-License-Identifier: Apache-2.0 OR MIT
const { Client } = require('./index.js');
function fail(msg) {
console.error('FAIL ' + msg);
process.exit(1);
}
function accepts(base) {
try { new Client(base); return true; } catch { return false; }
}
function rejects(base) {
try { new Client(base); return false; } catch { return true; }
}
if (!accepts('http://127.0.0.1:8080')) fail('loopback http must be accepted');
if (!accepts('http://localhost:8080')) fail('localhost http must be accepted');
if (!accepts('http://[::1]:8080')) fail('ipv6 loopback http must be accepted');
if (!accepts('http://127.0.0.1:8080/')) fail('a trailing slash on a loopback base must be accepted');
if (!accepts('https://gateway.quantova.example')) fail('https must be accepted');
if (!accepts('https://203.0.113.7:443')) fail('https to a public host must be accepted');
if (!rejects('http://203.0.113.7:8080')) fail('plaintext http to a public ip must be refused');
if (!rejects('http://gateway.quantova.example')) fail('plaintext http to a public host must be refused');
if (!rejects('http://10.0.0.5:8080')) fail('plaintext http to a private lan host must be refused');
if (!rejects('ftp://127.0.0.1:21')) fail('a non http scheme must be refused');
if (!rejects('127.0.0.1:8080')) fail('a base with no scheme must be refused');
if (!rejects('')) fail('an empty base must be refused');
let msg = '';
try { new Client('http://gateway.quantova.example'); } catch (e) { msg = e.message; }
if (!/plaintext http/.test(msg) || !/drain funds/.test(msg)) fail('the refusal message is unclear: ' + msg);
console.log('transport guard: all cases passed');