Files
OSIT-AE-App-Svelte/tests/verify_jwt_logic.js
Scott Idem 88bc18cf15 fix(core): resolve 68 compiler errors and stabilize Svelte 5 reactivity
- Fixed 'Captured initial value' warnings in 65+ components by implementing
  proper sync effects with 'untrack' and derived states.
- Hardened Event Settings JSON editors using a temporary string-buffer pattern
  to safely decouple object-based data from CodeMirror's string requirements.
- Resolved strict TypeScript mismatches across core routes (Accounts, Sites, etc.)
  and improved property indexing safety in views.
- Patched Flowbite-Svelte Drawer transitions for Svelte 5 compatibility using
  prop spreading.
- Added comprehensive safety comments to high-risk reactivity blocks.
- Synchronized 'ae_types.ts' with V3 backend models.
2026-02-08 16:05:35 -05:00

66 lines
2.1 KiB
JavaScript

// @ts-nocheck
const api_cfg_missing_jwt = {
headers: {
'x-aether-api-key': 'secret-key',
}
};
const api_cfg_with_jwt = {
headers: {
'x-aether-api-key': 'secret-key',
},
jwt: 'valid-jwt-token'
};
const api_cfg_with_header_jwt = {
headers: {
'x-aether-api-key': 'secret-key',
'jwt': 'valid-jwt-token-in-header'
}
};
function simulate_get_object(api_cfg, headers = {}) {
// Logic from api_get_object.ts
const headers_cleaned = {};
const merged_headers = { ...api_cfg['headers'], ...headers };
for (const prop in merged_headers) {
const prop_cleaned = prop.replaceAll('_', '-');
let value = merged_headers[prop];
if (value === null || value === undefined) continue;
headers_cleaned[prop_cleaned] = value;
}
const jwt = headers_cleaned['jwt'] || headers_cleaned['JWT'] || api_cfg['jwt'];
if (jwt && !headers_cleaned['Authorization'] && !headers_cleaned['authorization']) {
headers_cleaned['Authorization'] = `Bearer ${jwt}`;
}
return headers_cleaned;
}
console.log("--- Test 1: Missing JWT in Config ---");
const headers1 = simulate_get_object(api_cfg_missing_jwt);
if (headers1['Authorization']) {
console.error("FAIL: Authorization header present when it should be missing.");
} else {
console.log("PASS: Authorization header missing as expected.");
}
console.log("\n--- Test 2: JWT in Config Root ---");
const headers2 = simulate_get_object(api_cfg_with_jwt);
if (headers2['Authorization'] === 'Bearer valid-jwt-token') {
console.log("PASS: Authorization header present and correct.");
} else {
console.error(`FAIL: Authorization header incorrect or missing. Got: ${headers2['Authorization']}`);
}
console.log("\n--- Test 3: JWT in Config Headers ---");
const headers3 = simulate_get_object(api_cfg_with_header_jwt);
if (headers3['Authorization'] === 'Bearer valid-jwt-token-in-header') {
console.log("PASS: Authorization header present and correct.");
} else {
console.error(`FAIL: Authorization header incorrect or missing. Got: ${headers3['Authorization']}`);
}