feat: replace browser login with imported Reddit sessions
This commit is contained in:
1 parent
2b0545afcf
commit
c483c7b8be
76 files changed
+2048
-2828
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { createSessionExportDownload } from '../extensions/reddit-session-exporter/session-export.js';
|
||||
|
||||
describe('createSessionExportDownload', () => {
|
||||
it('creates a JSON data URL that Chrome can download from a service worker', () => {
|
||||
const download = createSessionExportDownload([
|
||||
{
|
||||
name: 'reddit_session',
|
||||
value: 'secret',
|
||||
domain: '.reddit.com',
|
||||
path: '/',
|
||||
expirationDate: 1_800_000_000,
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'lax',
|
||||
},
|
||||
], {
|
||||
homeserver: 'https://matrix.redditspace.com',
|
||||
accessToken: 'matrix-secret',
|
||||
userId: '@t2_bot:reddit.com',
|
||||
capturedAt: 1_700_000_000_000,
|
||||
});
|
||||
|
||||
expect(download.filename).toBe('redditbot-session.json');
|
||||
expect(download.url).toMatch(/^data:application\/json;charset=utf-8,/);
|
||||
expect(JSON.parse(decodeURIComponent(download.url.split(',')[1]))).toEqual({
|
||||
cookies: [
|
||||
{
|
||||
name: 'reddit_session',
|
||||
value: 'secret',
|
||||
domain: '.reddit.com',
|
||||
path: '/',
|
||||
expires: 1_800_000_000,
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: 'lax',
|
||||
},
|
||||
],
|
||||
matrix: {
|
||||
homeserver: 'https://matrix.redditspace.com',
|
||||
accessToken: 'matrix-secret',
|
||||
userId: '@t2_bot:reddit.com',
|
||||
capturedAt: 1_700_000_000_000,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('refuses to create an incomplete dump without Matrix credentials', () => {
|
||||
expect(() => createSessionExportDownload([], null)).toThrow(/Reddit Chat/i);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user