Skip to content

Commit 0dfd56a

Browse files
committed
fix: update apiKeys route to handle undefined scopes and fix test error code
- Fix scope validation to handle undefined scopes (default to empty array) - Update IP allowlist test to expect correct error code API_KEY_IP_RESTRICTED - Ensure API key creation endpoint works correctly with optional fields
1 parent 3614f30 commit 0dfd56a

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/routes/apiKeys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ router.post('/', requireAdmin(), apiKeyCreateSchema, payloadSizeLimiter(ENDPOINT
9494
}
9595

9696
// Validate scopes
97-
const scopeValidation = validateScopes(scopes);
97+
const scopeValidation = validateScopes(scopes || []);
9898
if (!scopeValidation.valid) {
9999
throw new ValidationError(`Invalid scopes: ${scopeValidation.errors.join('; ')}`);
100100
}

tests/security/ip-allowlist.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ describe('IP allowlist middleware integration', () => {
189189
});
190190
const res = await request(app).get('/health').set('x-api-key', key);
191191
expect(res.status).toBe(403);
192-
expect(res.body.error.code).toBe('FORBIDDEN');
192+
expect(res.body.error.code).toBe('API_KEY_IP_RESTRICTED');
193193
});
194194

195195
it('allows requests matching a CIDR range that includes loopback', async () => {

0 commit comments

Comments
 (0)