mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-25 00:27:32 +00:00
Some checks are pending
CI / build (push) Waiting to run
CI / test (1) (push) Waiting to run
CI / test (2) (push) Waiting to run
CI / test (3) (push) Waiting to run
CI / test (4) (push) Waiting to run
CI / test (5) (push) Waiting to run
CI / test-pi-tui (push) Waiting to run
CI / test-vscode-legacy (push) Waiting to run
CI / test-windows (push) Waiting to run
CI / lint (push) Waiting to run
CI / typecheck (push) Waiting to run
Nix Build / Check flake.nix workspace sync (push) Waiting to run
Nix Build / nix build .#kimi-code (push) Blocked by required conditions
Release / Release (push) Waiting to run
Release / Deploy docs (push) Blocked by required conditions
Release / Native release artifact (push) Blocked by required conditions
Release / Publish native release assets (push) Blocked by required conditions
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { mkdtemp, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
import { type RunningServer, startServer } from '../src/start';
|
|
import { TEST_HOST_IDENTITY } from './helpers/hostIdentity';
|
|
|
|
let prevPassword: string | undefined;
|
|
const createdDirs: string[] = [];
|
|
const running: RunningServer[] = [];
|
|
|
|
beforeEach(() => {
|
|
prevPassword = process.env['KIMI_CODE_PASSWORD'];
|
|
});
|
|
|
|
afterEach(async () => {
|
|
for (const r of running.splice(0)) {
|
|
try {
|
|
await r.close();
|
|
} catch {
|
|
}
|
|
}
|
|
for (const dir of createdDirs.splice(0)) {
|
|
await rm(dir, { recursive: true, force: true });
|
|
}
|
|
if (prevPassword === undefined) {
|
|
delete process.env['KIMI_CODE_PASSWORD'];
|
|
} else {
|
|
process.env['KIMI_CODE_PASSWORD'] = prevPassword;
|
|
}
|
|
});
|
|
|
|
async function tmpHome(): Promise<string> {
|
|
const dir = await mkdtemp(join(tmpdir(), 'kimi-v2-debug-loopback-'));
|
|
createdDirs.push(dir);
|
|
return dir;
|
|
}
|
|
|
|
async function probeDebug(server: RunningServer): Promise<number> {
|
|
const token = server.authTokenService.getToken();
|
|
const res = await fetch(`http://127.0.0.1:${server.port}/api/v1/debug/channels`, {
|
|
headers: { authorization: `Bearer ${token}` },
|
|
});
|
|
return res.status;
|
|
}
|
|
|
|
describe('debug endpoints are not exposed on a non-loopback bind', () => {
|
|
it('returns 404 for /api/v1/debug/* on a 0.0.0.0 bind even when requested', async () => {
|
|
process.env['KIMI_CODE_PASSWORD'] = 'test-pw';
|
|
const home = await tmpHome();
|
|
const server = await startServer({
|
|
hostIdentity: TEST_HOST_IDENTITY,
|
|
host: '0.0.0.0',
|
|
port: 0,
|
|
homeDir: home,
|
|
logLevel: 'silent',
|
|
insecureNoTls: true,
|
|
debugEndpoints: true,
|
|
});
|
|
running.push(server);
|
|
expect(await probeDebug(server)).toBe(404);
|
|
});
|
|
|
|
it('is not mounted on loopback by default (without the option)', async () => {
|
|
const home = await tmpHome();
|
|
const server = await startServer({
|
|
hostIdentity: TEST_HOST_IDENTITY,
|
|
host: '127.0.0.1',
|
|
port: 0,
|
|
homeDir: home,
|
|
logLevel: 'silent',
|
|
});
|
|
running.push(server);
|
|
expect(await probeDebug(server)).toBe(404);
|
|
});
|
|
|
|
it('mounts the whitelist-free RPC surface on loopback when requested', async () => {
|
|
const home = await tmpHome();
|
|
const server = await startServer({
|
|
hostIdentity: TEST_HOST_IDENTITY,
|
|
host: '127.0.0.1',
|
|
port: 0,
|
|
homeDir: home,
|
|
logLevel: 'silent',
|
|
debugEndpoints: true,
|
|
});
|
|
running.push(server);
|
|
expect(await probeDebug(server)).toBe(200);
|
|
});
|
|
});
|