fix(config): name malformed local identity errors
This commit is contained in:
@@ -96,8 +96,12 @@ export function assertLocalStartupContext(context: LocalStartupContext): void {
|
||||
try {
|
||||
resolveIdentity([() => config.identity]);
|
||||
} catch (error) {
|
||||
if (error instanceof Error) throw error;
|
||||
fail('identity', 'is invalid');
|
||||
const reason = error instanceof Error ? error.message : 'validation failed';
|
||||
const wrapped = new Error(`Invalid local startup identity: ${reason}`) as Error & {
|
||||
cause?: unknown;
|
||||
};
|
||||
wrapped.cause = error;
|
||||
throw wrapped;
|
||||
}
|
||||
|
||||
const authoritative = PROFILES.local?.servers;
|
||||
|
||||
@@ -141,6 +141,24 @@ test('context validator rejects forged config fields and malformed identity', ()
|
||||
);
|
||||
});
|
||||
|
||||
test('context validator names identity when a forged context omits the identity object', () => {
|
||||
const base = validContext();
|
||||
for (const identity of [null, undefined]) {
|
||||
assert.throws(
|
||||
() => assertLocalStartupContext({
|
||||
...base,
|
||||
config: { ...base.config, identity },
|
||||
} as unknown as LocalStartupContext),
|
||||
(error: unknown) => {
|
||||
assert.ok(error instanceof Error);
|
||||
assert.match(error.message, /identity/i);
|
||||
assert.ok((error as Error & { cause?: unknown }).cause instanceof Error);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('connection target must be a valid URL from the authoritative local profile', () => {
|
||||
const context = validContext();
|
||||
assert.doesNotThrow(() => assertLocalConnectionTarget(context, 'ws://127.0.0.1:3088'));
|
||||
|
||||
Reference in New Issue
Block a user