ci: expand shared package validation and test coverage
Lint / Lint (push) Successful in 32s
Docker / Docker Build & Push (push) Failing after 2m22s
Tests / Go backend (push) Failing after 1m2s
Tests / Dashboard checks (push) Failing after 35s

- Add lint, formatting, vet, and publish workflow checks
- Run Go database tests with PostgreSQL and add Java tests
- Make consumer sync opt-in; update docs and Go dependency
This commit is contained in:
Gabriel20xx committed 2026-10-19 21:46:52 +00:00
1 parent 937f51b4fb
commit 0ff94f9b10
107 files changed
+10124 -410

No files matched your search

+41 -3
View File
@@ -18,6 +18,8 @@
* example.
*/
import crypto from 'node:crypto';
/**
* @typedef {{authGuardUrl?: string, carrierNodeUrl?: string, carrierNodeUrls?: string[]}} InfoLike
*/
@@ -58,6 +60,29 @@ export class Info {
}
}
/**
* True when the X-Internal-Auth value equals the configured secret. An unset
* or empty secret never matches, and the comparison is constant-time.
* @param {unknown} provided
* @param {unknown} secret
* @returns {boolean}
*/
export function internalSecretMatches(provided, secret) {
const expected = Buffer.from(String(secret ?? ''));
if (expected.length === 0) return false;
const actual = Buffer.from(String(provided ?? ''));
return expected.length === actual.length && crypto.timingSafeEqual(expected, actual);
}
function isServiceUrl(value) {
try {
const url = new URL(value);
return (url.protocol === 'http:' || url.protocol === 'https:') && url.host !== '';
} catch {
return false;
}
}
function normalize(info) {
let cleaned = (info.carrierNodeUrls ?? []).map((u) => String(u ?? '').trim()).filter(Boolean);
if (cleaned.length === 0 && String(info.carrierNodeUrl ?? '').trim()) {
@@ -115,13 +140,20 @@ export class Store {
/**
* Replaces the current Info, field by field, ignoring a blank/empty field
* so a partial push (e.g. only carrierNodeUrl(s) changed) never clobbers
* the other value. Returns the resulting Info. Minimal Express usage:
* the other value. Every URL must be an http or https URL with a host;
* otherwise nothing is changed and an error is thrown. Returns the resulting
* Info. Minimal Express usage:
*
* app.put('/api/core-services/internal', (req, res) => {
* if (req.get('X-Internal-Auth') !== process.env.SECRET) {
* if (!internalSecretMatches(req.get('X-Internal-Auth'), process.env.SECRET)) {
* return res.status(401).json({ error: 'internal service authentication required' });
* }
* const info = coreConfigStore.set(Info.fromJSON(req.body));
* let info;
* try {
* info = coreConfigStore.set(Info.fromJSON(req.body));
* } catch (error) {
* return res.status(400).json({ error: error.message });
* }
* res.json({ ok: true, info: info.toJSON() });
* });
*
@@ -130,6 +162,12 @@ export class Store {
*/
set(nextInfo) {
const next = normalize(nextInfo instanceof Info ? nextInfo : new Info(nextInfo));
const badUrl = [next.authGuardUrl, ...next.carrierNodeUrls].find(
(url) => url && !isServiceUrl(url)
);
if (badUrl !== undefined) {
throw new TypeError(`core service URL must be an http or https URL with a host: ${badUrl}`);
}
if (next.authGuardUrl) {
this._info.authGuardUrl = next.authGuardUrl;
}