Snapshot of private main @ 10300fb6 through the extended publish excision (SC-SIM module, internal infra/ops scripts, personal material, debug cruft) plus the IP/e-mail scrub. Notable: - backend/services/agent-tools/principal.js — principal identity + owner-only naturalization (ADR-165 WP-4), with its two consumers. - backend/services/audit/toolAudit.js — hash-chained tool audit. - backend/services/mail/provisionMailbox.js + migration 089 — ADR-198 mailbox provisioning. - shared/column-types.js + migration 088 — ADR-0041R type ratchet. - migration 090 — ADR-0066-B agent provenance. - docs/MANIFESTO.md, docs/MCP.md — the two README links that were dangling. - LICENSE now also lives in the source tree; package.json declares MIT. - run-pes.js / deploy-package.cjs no longer carry credential fallbacks.
80 lines
3.1 KiB
JavaScript
80 lines
3.1 KiB
JavaScript
/**
|
|
* ADR-188 F5 — GET /api/v3/public/config (unauthenticated public slice).
|
|
*
|
|
* The login page must decide whether to show the "Sign up" link BEFORE auth,
|
|
* so it needs the effective signup policy without a token. This route is the
|
|
* public, non-sensitive projection of `getEffectiveRegistrationPolicy()`:
|
|
* only `{ signup_mode, referral_enabled }` — never roles / auto_join / landing.
|
|
*
|
|
* No DB (ADR-0009): the `_app_settings` read is swapped via __setRuntimeFetcher
|
|
* so these run against no combat master. The router-level abuse-guard +
|
|
* rate-limit still run (real chain), matching /registration-config.
|
|
*/
|
|
import { describe, test, expect, afterEach, beforeEach } from 'vitest';
|
|
import request from 'supertest';
|
|
import express from 'express';
|
|
import cookieParser from 'cookie-parser';
|
|
import publicRoutes from '../public.js';
|
|
import {
|
|
__setRuntimeFetcher,
|
|
__resetRuntimeFetcher,
|
|
invalidateRegistrationCache,
|
|
} from '../../../services/registrationPolicy.js';
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
app.use(cookieParser());
|
|
app.use('/api/v3/public', publicRoutes);
|
|
|
|
afterEach(() => {
|
|
__resetRuntimeFetcher();
|
|
invalidateRegistrationCache();
|
|
});
|
|
beforeEach(() => invalidateRegistrationCache());
|
|
|
|
describe('ADR-188 F5 — GET /api/v3/public/config', () => {
|
|
test('no auth required — returns 200 with the public contract shape', async () => {
|
|
__setRuntimeFetcher(async () => ({ signup_mode: 'open' }));
|
|
invalidateRegistrationCache();
|
|
|
|
const res = await request(app).get('/api/v3/public/config');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.success).toBe(true);
|
|
expect(res.body.data).toEqual({ signup_mode: 'open', referral_enabled: true });
|
|
});
|
|
|
|
test('projects runtime signup_mode; referral_enabled true for invite', async () => {
|
|
__setRuntimeFetcher(async () => ({ signup_mode: 'invite' }));
|
|
invalidateRegistrationCache();
|
|
|
|
const res = await request(app).get('/api/v3/public/config');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.data.signup_mode).toBe('invite');
|
|
// invite = "only users with a valid referral/invite code can register" → referral IS the door
|
|
expect(res.body.data.referral_enabled).toBe(true);
|
|
});
|
|
|
|
test('closed signup → referral_enabled false (no self-registration door)', async () => {
|
|
__setRuntimeFetcher(async () => ({ signup_mode: 'closed' }));
|
|
invalidateRegistrationCache();
|
|
|
|
const res = await request(app).get('/api/v3/public/config');
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body.data).toEqual({ signup_mode: 'closed', referral_enabled: false });
|
|
});
|
|
|
|
test('never leaks sensitive policy fields (roles / auto_join / landing)', async () => {
|
|
__setRuntimeFetcher(async () => ({ signup_mode: 'open', default_role: 'user' }));
|
|
invalidateRegistrationCache();
|
|
|
|
const res = await request(app).get('/api/v3/public/config');
|
|
|
|
expect(Object.keys(res.body.data).sort()).toEqual(['referral_enabled', 'signup_mode']);
|
|
expect(res.body.data).not.toHaveProperty('default_role');
|
|
expect(res.body.data).not.toHaveProperty('auto_join');
|
|
expect(res.body.data).not.toHaveProperty('landing_space');
|
|
});
|
|
});
|