Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions app/components/form/fields/TlsCertsField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import { Modal } from '~/ui/lib/Modal'
import { DescriptionField } from './DescriptionField'
import { ErrorMessage } from './ErrorMessage'
import { FileField } from './FileField'
import { validateName } from './NameField'
import { TextField } from './TextField'
import { NameField } from './NameField'

export function TlsCertsField({ control }: { control: Control<SiloCreateFormValues> }) {
const [showAddCert, setShowAddCert] = useState(false)
Expand Down Expand Up @@ -110,19 +109,14 @@ const AddCertModal = ({ onDismiss, onSubmit, allNames }: AddCertModalProps) => {
<Modal.Body>
<form autoComplete="off" onSubmit={handleSubmit(onSubmit)}>
<Modal.Section>
<TextField
<NameField
name="name"
control={control}
required
// this field is identical to NameField (which just does
// validateName for you) except we also want to check that the
// name is not in the list of certs you've already added
validate={(name) => {
if (allNames.includes(name)) {
return 'A certificate with this name already exists'
}
return validateName(name, 'Name', true)
}}
validate={(name) =>
allNames.includes(name)
? 'A certificate with this name already exists'
: undefined
}
/>
<DescriptionField name="description" control={control} />
<FileField
Expand Down
9 changes: 8 additions & 1 deletion test/e2e/silos.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@ test('Create silo', async ({ page }) => {
await chooseFile(page.getByLabel('Cert', { exact: true }), 'small')
await chooseFile(page.getByLabel('Key'), 'small')
const certName = certDialog.getByRole('textbox', { name: 'Name' })
await certName.fill('test-cert')

// check name format validation
await certName.fill('Bad Name')
await certSubmit.click()
await expect(
certDialog.getByText('Can only contain lower-case letters, numbers, and dashes')
).toBeVisible()

await certName.fill('test-cert')
await certSubmit.click()

// Check cert appears in the mini-table
Expand Down
Loading