Fix federated E2EE delivery when remote node metadata exceeds key lookup limit
Hop-State: A_06FPCJKZ17TQRWHPEDC2R30 Hop-Proposal: R_06FPCJKCFSDGTQJV38RW9AG Hop-Task: T_06FPCHWGKW3T4JFQZMN4MT8 Hop-Attempt: AT_06FPCHWGKYKYAXA04H4WRY0
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
getNodePublicKey: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@/lib/swarm/node-keys', () => ({
|
||||
getNodePublicKey: mocks.getNodePublicKey,
|
||||
}));
|
||||
|
||||
import { GET } from './route';
|
||||
|
||||
describe('GET /api/node/key', () => {
|
||||
beforeEach(() => {
|
||||
mocks.getNodePublicKey.mockReset();
|
||||
process.env.NEXT_PUBLIC_NODE_DOMAIN = 'node.example';
|
||||
});
|
||||
|
||||
it('returns only the node identity needed for signature verification', async () => {
|
||||
mocks.getNodePublicKey.mockResolvedValue('public-key');
|
||||
|
||||
const result = await GET();
|
||||
|
||||
expect(result.status).toBe(200);
|
||||
expect(result.headers.get('cache-control')).toBe('no-store');
|
||||
await expect(result.json()).resolves.toEqual({
|
||||
domain: 'node.example',
|
||||
publicKey: 'public-key',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
import { getNodePublicKey } from '@/lib/swarm/node-keys';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const publicKey = await getNodePublicKey();
|
||||
if (!publicKey) {
|
||||
return NextResponse.json({ error: 'Node public key is unavailable' }, { status: 503 });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
domain: process.env.NEXT_PUBLIC_NODE_DOMAIN || 'localhost:43821',
|
||||
publicKey,
|
||||
}, {
|
||||
headers: { 'Cache-Control': 'no-store' },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Node public key error:', error);
|
||||
return NextResponse.json({ error: 'Node public key is unavailable' }, { status: 503 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user