Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): stop an API key name at the gateway's 100 characters

Yudhi Armyndharis255f20fe0d3b
diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.ts
index 2aec65ef4..d1696f541 100644
--- a/dashboard/src/pages/ApiKeys.test.ts
+++ b/dashboard/src/pages/ApiKeys.test.ts
@@ -177,6 +177,12 @@ test('a create sends the IP allow-list, chats and expiry only when filled in', a
});
});
+// A production gateway refuses a name over 100 characters with a bare "Bad Request".
+test('the key name cannot exceed the 100 characters the gateway takes', async () => {
+ await openCreate();
+ assert.equal(rtl.screen.getByLabelText<HTMLInputElement>('Name').maxLength, 100);
+});
+
test('an IP or chat line the gateway would refuse keeps Create disabled and names the line', async () => {
const { screen, fireEvent } = rtl;
const create = await openCreate();
diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsx
index 6938c242c..04746c678 100644
--- a/dashboard/src/pages/ApiKeys.tsx
+++ b/dashboard/src/pages/ApiKeys.tsx
@@ -312,7 +312,7 @@ export function ApiKeys() {
const newErrors = limitErrors(newKey.role, newKey.ips, newKey.chats);
const editErrors =
editDraft && editingKey ? limitErrors(editDraft.role, editDraft.ips, editDraft.chats, editingKey) : null;
- // The gateway requires a name of at least 3 characters.
+ // The gateway requires a name of at least 3 characters; the input stops at its 100-character limit.
const canCreate =
!createMutation.isPending && newKey.name.trim().length >= 3 && newErrors.ip === null && newErrors.chat === null;
const canSave = !updateMutation.isPending && editErrors?.ip === null && editErrors.chat === null;
@@ -564,6 +564,7 @@ export function ApiKeys() {
<input
id="ak-1"
type="text"
+ maxLength={100}
placeholder={t('apiKeys.namePlaceholder')}
value={newKey.name}
onChange={e => setNewKey({ ...newKey, name: e.target.value })}