Skip to content

Commit 330ab51

Browse files
authored
Fix input validation to support both domain and GUID
1 parent 5db8164 commit 330ab51

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/views/tenant/administration/TenantLookup.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ import { CippContentCard } from 'src/components/layout'
2424
import Skeleton from 'react-loading-skeleton'
2525
import { domainsApi } from 'src/store/api/domains'
2626

27+
const isValidTenantInput = (value) => {
28+
// Regular expression for validating GUID
29+
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}$/
30+
// Regular expression for validating domain
31+
const domainRegex = /^([a-zA-Z0-9](-?[a-zA-Z0-9])*\.)+[a-zA-Z]{2,}$/
32+
33+
// Check if the input is a valid GUID or domain
34+
return !(guidRegex.test(value) || domainRegex.test(value))
35+
}
36+
2737
const GraphExplorer = () => {
2838
let navigate = useNavigate()
2939
const tenant = useSelector((state) => state.app.currentTenant)
@@ -57,12 +67,6 @@ const GraphExplorer = () => {
5767
})
5868
}
5969
}, [execGraphRequest, tenant.defaultDomainName, query, tenantdomain])
60-
const isValidDomain = (value) =>
61-
/^(((?!-))(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(
62-
value,
63-
)
64-
? undefined
65-
: value
6670

6771
return (
6872
<CRow>
@@ -80,7 +84,7 @@ const GraphExplorer = () => {
8084
render={({ handleSubmit, submitting, pristine }) => {
8185
return (
8286
<CForm onSubmit={handleSubmit}>
83-
<Field name="domain" validate={isValidDomain}>
87+
<Field name="domain" validate={isValidTenantInput}>
8488
{({ input, meta }) => {
8589
return (
8690
<>

0 commit comments

Comments
 (0)