mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 04:12:10 +03:00
chore: remove unused api key format helpers (#5359)
Integrated into release/v3.8.41 — dead-code removal (typecheck:core EXIT 0, 102 affected tests green, fabricated-docs clean). Thanks @JxnLexn.
This commit is contained in:
@@ -90,29 +90,3 @@ export function parseApiKey(
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify API key CRC (only for new format)
|
||||
* @param {string} apiKey
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function verifyApiKeyCrc(apiKey: string): boolean {
|
||||
const parsed = parseApiKey(apiKey);
|
||||
if (!parsed) return false;
|
||||
|
||||
// Old format doesn't have CRC, always valid if parsed
|
||||
if (!parsed.isNewFormat) return true;
|
||||
|
||||
// New format already verified in parseApiKey
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if API key is new format (contains machineId)
|
||||
* @param {string} apiKey
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isNewFormatKey(apiKey: string): boolean {
|
||||
const parsed = parseApiKey(apiKey);
|
||||
return parsed?.isNewFormat === true;
|
||||
}
|
||||
|
||||
29
tests/unit/api-key-utils-public-surface.test.ts
Normal file
29
tests/unit/api-key-utils-public-surface.test.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
process.env.API_KEY_SECRET = "test-api-key-utils-secret";
|
||||
|
||||
const apiKeyUtils = await import("../../src/shared/utils/apiKey.ts");
|
||||
|
||||
test("api key utility public surface keeps generation and parsing only", () => {
|
||||
const machineId = "testmachine";
|
||||
const { key, keyId } = apiKeyUtils.generateApiKeyWithMachine(machineId);
|
||||
|
||||
assert.equal(typeof key, "string");
|
||||
assert.equal(typeof keyId, "string");
|
||||
assert.match(key, new RegExp(`^sk-${machineId}-${keyId}-[a-f0-9]{8}$`));
|
||||
assert.deepEqual(apiKeyUtils.parseApiKey(key), {
|
||||
machineId,
|
||||
keyId,
|
||||
isNewFormat: true,
|
||||
});
|
||||
assert.deepEqual(apiKeyUtils.parseApiKey("sk-legacykey"), {
|
||||
machineId: null,
|
||||
keyId: "legacykey",
|
||||
isNewFormat: false,
|
||||
});
|
||||
assert.equal(apiKeyUtils.parseApiKey("not-a-key"), null);
|
||||
|
||||
assert.equal("verifyApiKeyCrc" in apiKeyUtils, false);
|
||||
assert.equal("isNewFormatKey" in apiKeyUtils, false);
|
||||
});
|
||||
Reference in New Issue
Block a user