Make AuthGuard integration decouple from knowing the URL at startup
Every language's AuthGuard client/service used "no URL at construction" to mean "auth disabled forever" - a live SetBaseUrl/setBaseUrl push from ProjectConfigurator could only ever retarget an *already-enabled* client, never turn one on for the first time. That made AUTHGUARD_URL a de-facto required env var everywhere, even though ProjectConfigurator can push it live after startup. - Go: shared/backend/auth's New/NewWithStore now default to a "pending" Service (still enabled, fails closed until a URL arrives) instead of disabled when authGuardURL is empty; add an explicit Disabled() option for the genuine standalone/local-dev opt-out. - Python/Node/Java: add setBaseUrl/set_base_url to each AuthClient so a client built with an empty base URL can be retargeted in place once a URL is pushed, the same as the Go client already supported. - Python/Node: add a coreconfig module (Info/Store), the framework-agnostic equivalent of shared/backend/coreconfig (Go), for services in those languages to receive ProjectConfigurator's core-services push at all. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c09957189f
commit
dcfdb3d7af
18 files changed
+747
-46
No files matched your search
@@ -68,6 +68,25 @@ test('constructor trims whitespace and leaves an empty base URL empty', () => {
|
||||
assert.equal(new AuthClient('').baseUrl, '');
|
||||
});
|
||||
|
||||
test('setBaseUrl retargets a pending client (constructed with "") to its first real URL', async () => {
|
||||
const client = new AuthClient('', {
|
||||
fetchImpl: fakeFetch([{ status: 200, body: { valid: true, user_id: 7, username: 'gabriel', role: 'admin' } }]),
|
||||
});
|
||||
await assert.rejects(() => client.validate('good-token'), /no base URL/);
|
||||
|
||||
client.setBaseUrl('https://auth.example.com');
|
||||
|
||||
assert.equal(client.baseUrl, 'https://auth.example.com');
|
||||
const user = await client.validate('good-token');
|
||||
assert.deepEqual(user, { id: 7, username: 'gabriel', role: 'admin' });
|
||||
});
|
||||
|
||||
test('setBaseUrl ignores a blank value, leaving the previous URL in place', () => {
|
||||
const client = new AuthClient('https://auth.example.com');
|
||||
client.setBaseUrl(' ');
|
||||
assert.equal(client.baseUrl, 'https://auth.example.com');
|
||||
});
|
||||
|
||||
test('validate resolves the user on a valid session', async () => {
|
||||
const client = new AuthClient('https://auth.example.com', {
|
||||
fetchImpl: fakeFetch([{ status: 200, body: { valid: true, user_id: 7, username: 'gabriel', role: 'admin' } }]),
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Info, Store } from '../src/coreconfig.js';
|
||||
|
||||
test('store seeds from the fallback Info', () => {
|
||||
const store = new Store({ authGuardUrl: 'http://auth.example.com', carrierNodeUrl: 'http://carrier.example.com' });
|
||||
assert.equal(store.authGuardUrl, 'http://auth.example.com');
|
||||
assert.equal(store.carrierNodeUrl, 'http://carrier.example.com');
|
||||
assert.deepEqual(store.carrierNodeUrls, ['http://carrier.example.com']);
|
||||
});
|
||||
|
||||
test('store defaults to empty with no fallback', () => {
|
||||
const store = new Store();
|
||||
assert.equal(store.authGuardUrl, '');
|
||||
assert.deepEqual(store.carrierNodeUrls, []);
|
||||
});
|
||||
|
||||
test('set ignores a blank authGuardUrl rather than clobbering the existing one', () => {
|
||||
const store = new Store({ authGuardUrl: 'http://auth.example.com' });
|
||||
store.set({ authGuardUrl: '', carrierNodeUrl: 'http://carrier.example.com' });
|
||||
assert.equal(store.authGuardUrl, 'http://auth.example.com');
|
||||
assert.equal(store.carrierNodeUrl, 'http://carrier.example.com');
|
||||
});
|
||||
|
||||
test('set only replaces carrierNodeUrls when the push actually carries one', () => {
|
||||
const store = new Store({ carrierNodeUrl: 'http://carrier.example.com' });
|
||||
store.set({ authGuardUrl: 'http://auth.example.com' });
|
||||
assert.equal(store.carrierNodeUrl, 'http://carrier.example.com');
|
||||
assert.equal(store.authGuardUrl, 'http://auth.example.com');
|
||||
});
|
||||
|
||||
test('onUpdate is called with the resulting Info after set', () => {
|
||||
const store = new Store();
|
||||
const seen = [];
|
||||
store.onUpdate((info) => seen.push(info));
|
||||
store.set({ authGuardUrl: 'http://auth.example.com' });
|
||||
assert.equal(seen.length, 1);
|
||||
assert.equal(seen[0].authGuardUrl, 'http://auth.example.com');
|
||||
});
|
||||
|
||||
test('Info.fromJSON/toJSON round-trip the wire shape', () => {
|
||||
const payload = {
|
||||
authGuardUrl: 'http://auth.example.com',
|
||||
carrierNodeUrl: 'http://carrier.example.com',
|
||||
carrierNodeUrls: ['http://carrier.example.com', 'http://carrier2.example.com'],
|
||||
};
|
||||
const info = Info.fromJSON(payload);
|
||||
assert.deepEqual(info.carrierNodeUrls, ['http://carrier.example.com', 'http://carrier2.example.com']);
|
||||
assert.equal(info.toJSON().carrierNodeUrl, 'http://carrier.example.com');
|
||||
});
|
||||
Reference in new issue
Block a user