Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport - 1.7.2] Bug 2040695: Fix cluster name validation bug (#1434) #1448

Merged
merged 1 commit into from
Jun 15, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/app/common/duck/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ export const handleSelfSignedCertError = (failedUrl: string, dispatch: any) => {
dispatch(certErrorOccurred(failedUrl));
};

const testClusterName = (value: string) => {
if (value?.length < 3 || value?.length > 63) {
return 'The cluster name should be between 3 and 63 characters long.';
} else if (!DNS1123Validator.test(value)) {
return `Invalid character: "${value}". Name must be DNS-1123 label compliant, starting and ending
with a lowercase alphanumeric character and containing only lowercase alphanumeric characters, "."
or "-".`;
}
return '';
};

const testTargetName = (value: string) => {
if (value?.length < 3 || value?.length > 63) {
return 'The namespace name should be between 3 and 63 characters long.';
Expand Down Expand Up @@ -88,4 +99,5 @@ export default {
testRouteHost,
capitalize,
testTargetName,
testClusterName,
};
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,11 @@ const AddEditClusterForm = withFormik<IOtherProps, IFormValues>({
validate: (values: IFormValues) => {
const errors: FormikErrors<IFormValues> = {};

const clusterNameError = utils.testClusterName(values?.name);
if (!values.name) {
errors.name = 'Required';
} else if (!utils.testDNS1123(values.name)) {
errors.name = utils.DNS1123Error(values.name);
} else if (clusterNameError !== '') {
errors.name = clusterNameError;
}

if (!values.url) {
Expand Down