Skip to content

Commit 783c45a

Browse files
authored
Fix BMC address tests (#2776)
1 parent 541d0b4 commit 783c45a

File tree

3 files changed

+47
-9
lines changed

3 files changed

+47
-9
lines changed

libs/ui-lib/lib/common/components/ui/formik/validationSchemas.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Address4, Address6 } from 'ip-address';
33
import isCIDR from 'is-cidr';
44
import { isInSubnet } from 'is-in-subnet';
55
import * as Yup from 'yup';
6+
import { head } from 'lodash-es';
7+
import parseUrl from 'parse-url';
68

79
import { TFunction } from 'i18next';
810
import {
@@ -27,7 +29,6 @@ import {
2729
} from './constants';
2830
import { allSubnetsIPv4, getAddress, trimCommaSeparatedList, trimSshPublicKey } from './utils';
2931
import { selectApiVip, selectIngressVip } from '../../../selectors';
30-
import { head } from 'lodash-es';
3132
import { ClusterDetailsValues } from '../../clusterWizard/types';
3233

3334
const ALPHANUMERIC_REGEX = /^[a-zA-Z0-9]+$/;
@@ -45,10 +46,6 @@ const IP_V4_ZERO = '0.0.0.0';
4546
const IP_V6_ZERO = '0000:0000:0000:0000:0000:0000:0000:0000';
4647
const MAC_REGEX = /^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$/;
4748
const HOST_NAME_REGEX = /^[^.]{1,63}(?:[.][^.]{1,63})*$/;
48-
49-
// Source of information: https://github.com/metal3-io/baremetal-operator/blob/main/docs/api.md#baremetalhost-spec
50-
const BMC_REGEX =
51-
/^((redfish-virtualmedia|idrac-virtualmedia)(\+https?)?:(\/\/([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?|(\/?[a-z0-9\-._~%!$&'()*+,;=:@]+(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?)?)|([a-z0-9\-._~%!$&'()*+,;=@]+(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?|(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)+\/?))(\?[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?(#[a-z0-9\-._~%!$&'()*+,;=:@/?]*)?$/i;
5249
const LOCATION_CHARS_REGEX = /^[a-zA-Z0-9-._]*$/;
5350

5451
export const nameValidationSchema = (
@@ -643,10 +640,16 @@ export const day2ApiVipValidationSchema = Yup.string().test(
643640
export const bmcAddressValidationSchema = (t: TFunction) => {
644641
const bmcAddressValidationMessagesList = bmcAddressValidationMessages(t);
645642

646-
return Yup.string().required().matches(BMC_REGEX, {
647-
message: bmcAddressValidationMessagesList.INVALID_VALUE,
648-
excludeEmptyString: true,
649-
});
643+
return Yup.string()
644+
.required()
645+
.test('valid-bmc-address', bmcAddressValidationMessagesList.INVALID_VALUE, (val) => {
646+
try {
647+
const url = parseUrl(val);
648+
return ['redfish-virtualmedia', 'idrac-virtualmedia'].includes(url.protocol as string);
649+
} catch (error) {
650+
return false;
651+
}
652+
});
650653
};
651654
export const locationValidationSchema = (t: TFunction) => {
652655
const locationValidationMessagesList = locationValidationMessages(t);

libs/ui-lib/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"is-in-subnet": "^4",
2626
"js-yaml": "^4.1.0",
2727
"lodash-es": "^4.17.21",
28+
"parse-url": "^9.2.0",
2829
"prism-react-renderer": "^1.1.1",
2930
"react-error-boundary": "^3.1.4",
3031
"react-measure": "^2.5.2",

yarn.lock

+34
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ __metadata:
899899
is-in-subnet: ^4
900900
js-yaml: ^4.1.0
901901
lodash-es: ^4.17.21
902+
parse-url: ^9.2.0
902903
prism-react-renderer: ^1.1.1
903904
react-error-boundary: ^3.1.4
904905
react-measure: ^2.5.2
@@ -1792,6 +1793,13 @@ __metadata:
17921793
languageName: node
17931794
linkType: hard
17941795

1796+
"@types/parse-path@npm:^7.0.0":
1797+
version: 7.0.3
1798+
resolution: "@types/parse-path@npm:7.0.3"
1799+
checksum: 21a12c228d38f5a75659dfd7cb127dc2001ed3f6acbd1b2e0575d1348c735594c0bab06a97fe849c151438384829f20ea5971cb045f7ecd37d53c76a9fcb9de3
1800+
languageName: node
1801+
linkType: hard
1802+
17951803
"@types/prop-types@npm:*":
17961804
version: 15.7.12
17971805
resolution: "@types/prop-types@npm:15.7.12"
@@ -7326,6 +7334,25 @@ __metadata:
73267334
languageName: node
73277335
linkType: hard
73287336

7337+
"parse-path@npm:^7.0.0":
7338+
version: 7.0.0
7339+
resolution: "parse-path@npm:7.0.0"
7340+
dependencies:
7341+
protocols: ^2.0.0
7342+
checksum: 244b46523a58181d251dda9b888efde35d8afb957436598d948852f416d8c76ddb4f2010f9fc94218b4be3e5c0f716aa0d2026194a781e3b8981924142009302
7343+
languageName: node
7344+
linkType: hard
7345+
7346+
"parse-url@npm:^9.2.0":
7347+
version: 9.2.0
7348+
resolution: "parse-url@npm:9.2.0"
7349+
dependencies:
7350+
"@types/parse-path": ^7.0.0
7351+
parse-path: ^7.0.0
7352+
checksum: 765d4beac7de59c88007018e2a4b95ed8ff96cdcd0ff510b1ad00ab3d17f63949c7664218685394fe35af52061516c5efbba520fb760d7104b8238a6196f28c4
7353+
languageName: node
7354+
linkType: hard
7355+
73297356
"parse5-htmlparser2-tree-adapter@npm:^7.0.0":
73307357
version: 7.0.0
73317358
resolution: "parse5-htmlparser2-tree-adapter@npm:7.0.0"
@@ -7653,6 +7680,13 @@ __metadata:
76537680
languageName: node
76547681
linkType: hard
76557682

7683+
"protocols@npm:^2.0.0":
7684+
version: 2.0.1
7685+
resolution: "protocols@npm:2.0.1"
7686+
checksum: 4a9bef6aa0449a0245ded319ac3cbfd032c3e76ebb562777037a3a832c99253d0e8bc2847f7be350236df620a11f7d4fe683ea7f59a2cc14c69f746b6259eda4
7687+
languageName: node
7688+
linkType: hard
7689+
76567690
"proxy-from-env@npm:1.0.0":
76577691
version: 1.0.0
76587692
resolution: "proxy-from-env@npm:1.0.0"

0 commit comments

Comments
 (0)