upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/phase2.mjs40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/phase2.mjs b/tests/phase2.mjs
index fa29337..5ee08f7 100644
--- a/tests/phase2.mjs
+++ b/tests/phase2.mjs
@@ -94,6 +94,46 @@ if (TEST_TOKEN) {
94 const body20 = curlBody(`${API}/`, { method: 'POST', data: TEST_TOKEN }); 94 const body20 = curlBody(`${API}/`, { method: 'POST', data: TEST_TOKEN });
95 const json20 = body20 ? JSON.parse(body20) : null; 95 const json20 = body20 ? JSON.parse(body20) : null;
96 assert(json20 && json20.kind === 21023, 'Returns kind=21023 for spent token'); 96 assert(json20 && json20.kind === 21023, 'Returns kind=21023 for spent token');
97
98 // Test 22: Session expiry
99 console.log('\nTest 22: Session expiry (waiting 65s for allotment to expire)...');
100 try {
101 execSync(`echo '${sudoPw}' | sudo -S ip route add default via 192.168.4.1 dev wlp59s0 metric 50 2>/dev/null`, { encoding: 'utf8', timeout: 5000 });
102 } catch {}
103 await sleep(65000);
104 let expiredPingOk = true;
105 try {
106 const ping22 = execSync('ping -c 2 -W 2 8.8.8.8', { encoding: 'utf8', timeout: 10000 });
107 expiredPingOk = !ping22.includes('100% packet loss');
108 } catch {
109 expiredPingOk = false;
110 }
111 assert(!expiredPingOk, 'Internet blocked after session expiry');
112 const body22 = curlBody(`${API}/usage`);
113 assert(body22 && body22.includes('-1/-1'), 'Usage returns -1/-1 after expiry');
114
115 // Test 23: Session renewal
116 const TEST_TOKEN2 = process.env.TEST_TOKEN2;
117 if (TEST_TOKEN2) {
118 console.log('\nTest 23: Session renewal with second token');
119 const body23 = curlBody(`${API}/`, { method: 'POST', data: TEST_TOKEN2 });
120 const json23 = body23 ? JSON.parse(body23) : null;
121 assert(json23 && json23.kind === 1022, 'Returns kind=1022 for renewal');
122 await sleep(1500);
123 let renewPingOk = false;
124 try {
125 const ping23 = execSync('ping -c 2 -W 2 8.8.8.8', { encoding: 'utf8', timeout: 10000 });
126 renewPingOk = !ping23.includes('100% packet loss');
127 } catch {
128 renewPingOk = false;
129 }
130 assert(renewPingOk, 'Internet works after renewal');
131 } else {
132 console.log('\n ⚠ Skipping test 23: Set TEST_TOKEN2 env var for renewal test');
133 }
134 try {
135 execSync(`echo '${sudoPw}' | sudo -S ip route del default via 192.168.4.1 dev wlp59s0 metric 50 2>/dev/null`, { encoding: 'utf8', timeout: 5000 });
136 } catch {}
97} else { 137} else {
98 console.log('\n ⚠ Skipping tests 16-20: Set TEST_TOKEN env var with a valid Cashu token'); 138 console.log('\n ⚠ Skipping tests 16-20: Set TEST_TOKEN env var with a valid Cashu token');
99} 139}