fix(striker-ui): yup: reduce restrictions on UUID checks, move IPv4 checks

main^2
Tsu-ba-me 7 months ago
parent aa1d53c737
commit f5351cb50c
  1. 3
      striker-ui/components/Files/schema.ts
  2. 10
      striker-ui/components/ManageHost/schema.ts
  3. 9
      striker-ui/components/ManageHost/testAccessSchema.ts
  4. 7
      striker-ui/components/ManageMailRecipient/schema.ts
  5. 3
      striker-ui/components/ManageMailServer/schema.ts
  6. 17
      striker-ui/lib/yupMatches.ts

@ -1,6 +1,7 @@
import * as yup from 'yup';
import buildYupDynamicObject from '../../lib/buildYupDynamicObject';
import { yupLaxUuid } from '../../lib/yupMatches';
const fileLocationSchema = yup.object({ active: yup.boolean().required() });
@ -19,7 +20,7 @@ const fileSchema = yup.object({
}),
name: yup.string().required(),
type: yup.string().oneOf(['iso', 'other', 'script']),
uuid: yup.string().uuid().required(),
uuid: yupLaxUuid().required(),
});
const fileListSchema = yup.lazy((files) =>

@ -1,13 +1,11 @@
import * as yup from 'yup';
import { REP_IPV4 } from '../../lib/consts/REG_EXP_PATTERNS';
import { yupIpv4, yupLaxUuid } from '../../lib/yupMatches';
const schema = yup.object().shape(
{
enterpriseKey: yup.string().uuid().optional(),
ip: yup.string().matches(REP_IPV4, {
message: 'Expected IP address to be a valid IPv4 address.',
}),
enterpriseKey: yupLaxUuid().optional(),
ip: yupIpv4().required(),
name: yup.string().required(),
redhatConfirmPassword: yup
.string()
@ -27,7 +25,7 @@ const schema = yup.object().shape(
String(redhatPassword).length > 0 ? field.required() : field.optional(),
),
type: yup.string().oneOf(['dr', 'subnode']).required(),
uuid: yup.string().uuid().required(),
uuid: yupLaxUuid().required(),
},
[['redhatUsername', 'redhatPassword']],
);

@ -1,14 +1,9 @@
import * as yup from 'yup';
import { REP_IPV4 } from '../../lib/consts/REG_EXP_PATTERNS';
import { yupIpv4 } from '../../lib/yupMatches';
const schema = yup.object({
ip: yup
.string()
.matches(REP_IPV4, {
message: 'Expected IP address to be a valid IPv4 address.',
})
.required(),
ip: yupIpv4().required(),
password: yup.string().required(),
});

@ -1,6 +1,7 @@
import * as yup from 'yup';
import buildYupDynamicObject from '../../lib/buildYupDynamicObject';
import { yupLaxUuid } from '../../lib/yupMatches';
const alertLevelSchema = yup.number().oneOf([0, 1, 2, 3, 4]);
@ -9,9 +10,9 @@ const alertOverrideSchema = yup.object({
level: alertLevelSchema.required(),
target: yup.object({
type: yup.string().oneOf(['node', 'subnode']).required(),
uuid: yup.string().uuid().required(),
uuid: yupLaxUuid().required(),
}),
uuid: yup.string().uuid().optional(),
uuid: yupLaxUuid().optional(),
});
const alertOverrideListSchema = yup.lazy((entries) =>
@ -24,7 +25,7 @@ const mailRecipientSchema = yup.object({
language: yup.string().oneOf(['en_CA']).optional(),
level: alertLevelSchema.required(),
name: yup.string().required(),
uuid: yup.string().uuid().optional(),
uuid: yupLaxUuid().optional(),
});
const mailRecipientListSchema = yup.lazy((entries) =>

@ -1,6 +1,7 @@
import * as yup from 'yup';
import buildYupDynamicObject from '../../lib/buildYupDynamicObject';
import { yupLaxUuid } from '../../lib/yupMatches';
const mailServerSchema = yup.object({
address: yup.string().required(),
@ -17,7 +18,7 @@ const mailServerSchema = yup.object({
port: yup.number().required(),
security: yup.string().oneOf(['none', 'starttls', 'tls-ssl']),
username: yup.string().optional(),
uuid: yup.string().uuid().required(),
uuid: yupLaxUuid().required(),
});
const mailServerListSchema = yup.lazy((mailServers) =>

@ -0,0 +1,17 @@
import * as yup from 'yup';
import { REP_IPV4, REP_UUID } from './consts/REG_EXP_PATTERNS';
/**
* This is OK because yup uses the template string syntax internally to access
* the field name.
*/
/* eslint-disable no-template-curly-in-string */
export const yupLaxUuid = () =>
yup.string().matches(REP_UUID, { message: '${path} must be a valid UUID' });
export const yupIpv4 = () =>
yup
.string()
.matches(REP_IPV4, { message: '${path} must be a valid IPv4 address' });
Loading…
Cancel
Save