Skip to content

Commit

Permalink
Fix input validation to support both domain and GUID
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdwegen committed Aug 2, 2023
1 parent 5db8164 commit 330ab51
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/views/tenant/administration/TenantLookup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ import { CippContentCard } from 'src/components/layout'
import Skeleton from 'react-loading-skeleton'
import { domainsApi } from 'src/store/api/domains'

const isValidTenantInput = (value) => {
// Regular expression for validating GUID
const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/
// Regular expression for validating domain
const domainRegex = /^([a-zA-Z0-9](-?[a-zA-Z0-9])*\.)+[a-zA-Z]{2,}$/

// Check if the input is a valid GUID or domain
return !(guidRegex.test(value) || domainRegex.test(value))
}

const GraphExplorer = () => {
let navigate = useNavigate()
const tenant = useSelector((state) => state.app.currentTenant)
Expand Down Expand Up @@ -57,12 +67,6 @@ const GraphExplorer = () => {
})
}
}, [execGraphRequest, tenant.defaultDomainName, query, tenantdomain])
const isValidDomain = (value) =>
/^(((?!-))(xn--|_{1,1})?[a-z0-9-]{0,61}[a-z0-9]{1,1}\.)*(xn--)?([a-z0-9][a-z0-9-]{0,60}|[a-z0-9-]{1,30}\.[a-z]{2,})$/i.test(
value,
)
? undefined
: value

return (
<CRow>
Expand All @@ -80,7 +84,7 @@ const GraphExplorer = () => {
render={({ handleSubmit, submitting, pristine }) => {
return (
<CForm onSubmit={handleSubmit}>
<Field name="domain" validate={isValidDomain}>
<Field name="domain" validate={isValidTenantInput}>
{({ input, meta }) => {
return (
<>
Expand Down

0 comments on commit 330ab51

Please sign in to comment.