Skip to content

Commit

Permalink
Update decrypt.unit.test.ts (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalininator committed Oct 30, 2021
1 parent d8945e5 commit e839e75
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/chrome/decrypt.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createCipheriv } from 'crypto';
import { decrypt } from './decrypt';
import { decrypt, decryptWindows } from './decrypt';
import { getLinuxDerivedKey } from './getDerivedKey';
import { getDpapi } from './optionalDependencies';
import { mockPlatform, restorePlatform } from '../../test/util';

describe('chrome decrypt - linux', () => {
Expand All @@ -26,3 +27,37 @@ describe('chrome decrypt - linux', () => {
expect(res).toEqual('bar');
});
});

jest.mock('./optionalDependencies', () => ({
getDpapi: jest.fn(),
}));

describe('chrome decrypt - window', () => {
beforeAll(() => {
mockPlatform('win32');
});

afterAll(() => {
restorePlatform();
});

it('should decrypt current user cookie', async () => {
const unprotectDataFn = jest.fn().mockReturnValue(Buffer.from('foo'));

(getDpapi as jest.Mock).mockReturnValue({
unprotectData: unprotectDataFn,
});

const bufferPrefix = Buffer.from([0x01, 0x00, 0x00, 0x00]);

const bufContents = Buffer.from('bar');

const fullBuf = Buffer.concat([bufferPrefix, bufContents]);

const decrypted = decryptWindows(fullBuf);

expect(unprotectDataFn).toHaveBeenCalledWith(fullBuf, null, 'CurrentUser');

expect(decrypted).toEqual('foo');
});
});

0 comments on commit e839e75

Please sign in to comment.