Verify authenticator codes against RFC 6238 test vectors
Validate / validate (push) Successful in 3m31s

This commit is contained in:
2026-10-30 20:08:23 +08:00
parent 7368317a10
commit c3cc8eff28
3 changed files with 21 additions and 11 deletions
+7
View File
@@ -20,5 +20,12 @@ vm.runInNewContext(ts.transpileModule(fs.readFileSync('lib/editor-session.ts','u
assert.equal(await validSession(token),false);
context.process.env.EDITOR_SESSION_SECRET = '';
assert.equal(await validSession(token),false);
const totpContext = {exports:{},require,Buffer};
vm.runInNewContext(ts.transpileModule(fs.readFileSync('lib/totp.ts','utf8'), {compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2020}}).outputText, totpContext);
const rfcSecret = 'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ';
for (const [time,expected] of [[59,'287082'],[1111111109,'081804'],[1111111111,'050471'],[1234567890,'005924'],[2000000000,'279037'],[20000000000,'353130']]) {
assert.equal(totpContext.exports.totp(rfcSecret,Math.floor(time/30)),expected);
}
console.log('RFC 6238 TOTP vectors: passed');
console.log('Editor session validation: passed');
})().catch(error => { console.error(error); process.exitCode=1; });