Skip to content

Commit 4ced162

Browse files
committed
Merge branch 'fix/deprecation-cleanup' of https://github.com/markdavid000/Stellar-Dex-Chat into fix/deprecation-cleanup
2 parents d8fccb2 + 871cef2 commit 4ced162

19 files changed

Lines changed: 1036 additions & 24 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ stellar-contracts/target/
1010
# Contract build artifacts
1111
*.wasm
1212

13+
issue.md
14+
pr.md

dex_with_fiat_frontend/.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ NEXT_PUBLIC_XLM_SAC_CONTRACT=CDLZFC3SYJYDZT7K67VZ75HPJVIEUVNIXF47ZG2FB2RMQQVU2HH
1212
# Admin Stellar public key (G...)
1313
NEXT_PUBLIC_ADMIN_PUBLIC_KEY=GBLDNEYP3TGZJQG3QKQXQDQKQXQDQKQXQDQKQXQDQKQXQDQKQXQDQKQXQDQKQXQDQ
1414

15-
# Google Gemini API key for the AI assistant.
1615
# SERVER-ONLY: Do NOT use the NEXT_PUBLIC_ prefix. This key is proxied via
1716
# /api/ai/chat and never sent to the browser.
1817
GEMINI_API_KEY=your_gemini_api_key_here
18+
19+
# Admin secret for accessing reconciliation and audit log endpoints.
20+
ADMIN_SECRET=your_admin_secret_here

dex_with_fiat_frontend/src/app/api/admin/_utils/requireAdminAuth.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import { env } from '@/lib/env';
22

33
export function requireAdminAuth(request: Request): Response | null {
4-
const configuredToken = env.ADMIN_API_TOKEN;
5-
6-
// Keep development ergonomics when no token is configured.
7-
if (!configuredToken) {
8-
return null;
9-
}
4+
const configuredSecret = env.ADMIN_SECRET;
105

116
const headerToken = request.headers.get('x-admin-token');
127
const authHeader = request.headers.get('authorization');
138
const bearerToken = authHeader?.startsWith('Bearer ')
149
? authHeader.slice('Bearer '.length).trim()
1510
: null;
1611

17-
if (headerToken === configuredToken || bearerToken === configuredToken) {
12+
// Basic check: match against secret (header is preferred)
13+
if (configuredSecret && (headerToken === configuredSecret || bearerToken === configuredSecret)) {
1814
return null;
1915
}
2016

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { describe, it, expect, vi, beforeEach } from 'vitest';
2+
import { NextRequest } from 'next/server';
3+
4+
const mockEnv = { ADMIN_SECRET: 'test-admin-secret' };
5+
vi.mock('@/lib/env', () => ({
6+
get env() {
7+
return mockEnv;
8+
},
9+
}));
10+
11+
import { GET } from './route';
12+
13+
describe('GET /api/admin/reconciliation', () => {
14+
beforeEach(() => {
15+
mockEnv.ADMIN_SECRET = 'test-admin-secret';
16+
});
17+
18+
it('returns 401 when no authentication is provided', async () => {
19+
const req = new NextRequest('http://localhost/api/admin/reconciliation');
20+
const res = await GET(req);
21+
expect(res.status).toBe(401);
22+
const body = await res.json();
23+
expect(body.error).toMatch(/Unauthorized/i);
24+
});
25+
26+
it('returns 401 when invalid token is provided in x-admin-token', async () => {
27+
const req = new NextRequest('http://localhost/api/admin/reconciliation', {
28+
headers: { 'x-admin-token': 'wrong-secret' },
29+
});
30+
const res = await GET(req);
31+
expect(res.status).toBe(401);
32+
});
33+
34+
it('returns 200 when valid token is provided in x-admin-token', async () => {
35+
const req = new NextRequest('http://localhost/api/admin/reconciliation', {
36+
headers: { 'x-admin-token': 'test-admin-secret' },
37+
});
38+
const res = await GET(req);
39+
expect(res.status).toBe(200);
40+
const body = await res.json();
41+
expect(Array.isArray(body)).toBe(true);
42+
});
43+
44+
it('returns 200 when valid bearer token is provided', async () => {
45+
const req = new NextRequest('http://localhost/api/admin/reconciliation', {
46+
headers: { authorization: 'Bearer test-admin-secret' },
47+
});
48+
const res = await GET(req);
49+
expect(res.status).toBe(200);
50+
});
51+
});

dex_with_fiat_frontend/src/app/api/webhook/webhook.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vi.mock('@/lib/env', () => ({ get env() { return mockEnv; } }));
1818
vi.mock('@/lib/telemetry', () => ({
1919
telemetry: {
2020
extractTraceFromHeaders: () => ({ traceId: 'trace1', spanId: 'span1' }),
21-
createSpan: (_name: string, _spanId: string, _traceId: string) => ({ spanId: 'span1' }),
21+
createSpan: () => ({ spanId: 'span1' }),
2222
addLog: vi.fn(),
2323
finishSpan: vi.fn(),
2424
setTraceHeaders: vi.fn(),

0 commit comments

Comments
 (0)