Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): hold Create for an API key name over 100 characters
Yudhi Armyndharis06e348045926
diff --git a/dashboard/src/pages/ApiKeys.test.ts b/dashboard/src/pages/ApiKeys.test.tsindex 541338889..6bdd035ae 100644--- a/dashboard/src/pages/ApiKeys.test.ts+++ b/dashboard/src/pages/ApiKeys.test.ts@@ -215,10 +215,17 @@ test('a name of two emoji keeps Create disabled', async () => {assert.equal(create.disabled, false);});-// 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);+// A production gateway refuses a name over 100 characters with a bare "Bad Request". It counts code+// points, while a maxlength attribute counts UTF-16 units and would cut an emoji name at 50.+test('a key name over the 100 characters the gateway takes keeps Create disabled', async () => {+ const { screen, fireEvent } = rtl;+ const create = await openCreate();+ const name = screen.getByLabelText<HTMLInputElement>('Name');+ assert.equal(name.hasAttribute('maxlength'), false);+ fireEvent.change(name, { target: { value: '\u{1F511}'.repeat(100) } });+ assert.equal(create.disabled, false, 'Create is disabled for a 100-character name');+ fireEvent.change(name, { target: { value: '\u{1F511}'.repeat(101) } });+ assert.equal(create.disabled, true, 'Create is enabled for a 101-character name');});test('an IP or chat line the gateway would refuse keeps Create disabled and names the line', async () => {diff --git a/dashboard/src/pages/ApiKeys.tsx b/dashboard/src/pages/ApiKeys.tsxindex 53d6b5a85..795d208c7 100644--- a/dashboard/src/pages/ApiKeys.tsx+++ b/dashboard/src/pages/ApiKeys.tsx@@ -313,10 +313,12 @@ 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, counted the way its validator counts them- // (an emoji is one); the input stops at its 100-character limit.+ // The gateway takes a name of 3 to 100 characters, counted the way its validators count them (an+ // emoji is one); Create is held outside that range.const nameTooShort = captionLength(newKey.name.trim()) < 3;- const canCreate = !createMutation.isPending && !nameTooShort && newErrors.ip === null && newErrors.chat === null;+ const nameTooLong = [...newKey.name].length > 100;+ const canCreate =+ !createMutation.isPending && !nameTooShort && !nameTooLong && newErrors.ip === null && newErrors.chat === null;const canSave = !updateMutation.isPending && editErrors?.ip === null && editErrors.chat === null;const handleRevoke = async (id: string) => {@@ -569,7 +571,6 @@ export function ApiKeys() {<inputid="ak-1"type="text"- maxLength={100}placeholder={t('apiKeys.namePlaceholder')}value={newKey.name}onChange={e => setNewKey({ ...newKey, name: e.target.value })}