UNPKG

chrome-cookies-secure

Version:

Extract encrypted Google Chrome cookies for a url on a Mac, Linux or Windows

59 lines (51 loc) 1.71 kB
// https://gemini.google.com/app/749e87d38954e931?hl=en-GB const sinon = require('sinon'); const sqlite3 = require('sqlite3').verbose(); const assert = require('assert'); const chromeCookies = require('../index'); // Path to your library describe('Chrome Cookies Secure - Logic Tests', () => { let db; let decryptStub; before((done) => { // 1. Create In-Memory DB and populate schema db = new sqlite3.Database(':memory:'); db.serialize(() => { db.run(` CREATE TABLE cookies ( host_key TEXT, name TEXT, value TEXT, encrypted_value BLOB, path TEXT, expires_utc INTEGER, is_secure INTEGER ) `); // Insert a mock "encrypted" cookie const stmt = db.prepare("INSERT INTO cookies VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.run('.example.com', 'auth_token', '', Buffer.from('fake_blob'), '/', 0, 1); stmt.finalize(done); }); }); beforeEach(() => { // 2. Stub the decryption logic // Assuming your lib has an internal _decrypt method or calls a specific module decryptStub = sinon.stub(chromeCookies, 'decrypt').callsFake((blob) => { return 'decrypted_secret_value'; }); }); afterEach(() => { decryptStub.restore(); }); after(() => { db.close(); }); it('should retrieve and "decrypt" a cookie from the database', (done) => { // You'll need to point your library to use the 'db' instance or the memory path chromeCookies.getCookies('https://example.com', (err, cookies) => { assert.strictEqual(cookies.auth_token, 'decrypted_secret_value'); assert(decryptStub.calledOnce); done(); }); }); });