frist
This commit is contained in:
55
test/test_n_gen.js
Normal file
55
test/test_n_gen.js
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Test: N Value Generation
|
||||
*
|
||||
* Validates that the sandbox can execute hsw.js and produce valid n values.
|
||||
*/
|
||||
|
||||
import { HswRunner } from '../src/sandbox/hsw_runner.js';
|
||||
import { Logger } from '../src/utils/logger.js';
|
||||
|
||||
Logger.globalLevel = 'debug';
|
||||
const logger = new Logger('TestN');
|
||||
|
||||
async function test() {
|
||||
logger.info('Starting n value generation test...');
|
||||
|
||||
const runner = new HswRunner();
|
||||
|
||||
try {
|
||||
await runner.init();
|
||||
logger.success('Sandbox initialized');
|
||||
} catch (err) {
|
||||
logger.error(`Sandbox init failed: ${err.message}`);
|
||||
logger.error('This is where debugging begins.');
|
||||
logger.error('The error message tells you what hsw.js tried to access.');
|
||||
logger.error('Add that property to browser_mock.js and try again.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Test with a JWT-formatted req string
|
||||
// In production, this comes from checksiteconfig response
|
||||
// Format: base64(header).base64(payload).base64(signature)
|
||||
const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64');
|
||||
const payload = Buffer.from(JSON.stringify({
|
||||
t: 'hsw',
|
||||
s: 'test-session-id',
|
||||
l: 'https://example.com',
|
||||
iat: Math.floor(Date.now() / 1000)
|
||||
})).toString('base64');
|
||||
const signature = Buffer.from('fake-signature-for-testing').toString('base64');
|
||||
const testReq = `${header}.${payload}.${signature}`;
|
||||
|
||||
logger.info(`Test JWT: ${testReq.substring(0, 50)}...`);
|
||||
|
||||
try {
|
||||
const n = await runner.getN(testReq);
|
||||
logger.success(`Generated n value: ${n}`);
|
||||
logger.info('If this looks like a valid base64 string, you\'re on the right track.');
|
||||
} catch (err) {
|
||||
logger.error(`N generation failed: ${err.message}`);
|
||||
logger.error('Check the error - it tells you what\'s missing in the mock.');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
test().catch(console.error);
|
||||
Reference in New Issue
Block a user