Gate bot logic on full account authentication

This commit is contained in:
jjbrunton committed 2026-08-08 16:01:06 +01:00
1 parent 4db6de8bf5
commit 2fd92bf82c
22 files changed
+635 -65

No files matched your search

+27
View File
@@ -28,6 +28,9 @@ function appWithBrowser(state: 'authenticated' | 'login-required' | 'unreachable
app.use(
createLoginRouter({
services: {
accountAuth: {
ensureFullyAuthenticated: async () => state === 'authenticated',
},
browser: {
isSessionValid: async () => state === 'authenticated',
getSessionState: () => state,
@@ -39,6 +42,20 @@ function appWithBrowser(state: 'authenticated' | 'login-required' | 'unreachable
return app;
}
function appWithPartialAuthentication() {
const app = express();
app.use(createLoginRouter({
services: {
accountAuth: { ensureFullyAuthenticated: async () => false },
browser: {
getSessionState: () => 'authenticated',
},
},
logger: { error: () => undefined },
} as never));
return app;
}
describe('Reddit session status', () => {
it('reports when Reddit is unreachable instead of presenting it as logged out', async () => {
const response = await request(appWithBrowser('unreachable'), '/login/status');
@@ -60,6 +77,16 @@ describe('Reddit session status', () => {
});
});
it('does not report authenticated when only the Reddit browser session is valid', async () => {
const response = await request(appWithPartialAuthentication(), '/login/status');
expect(await response.json()).toEqual({
ready: true,
loggedIn: false,
status: 'login-required',
});
});
it('returns the configured public noVNC URL', async () => {
process.env.NOVNC_PUBLIC_URL = 'https://red-vnc.apps.jbrunton.co.uk';