Skip to content

Commit 4076be5

Browse files
authored
fix(core): validate sub-component types in address and fullname fields (#7674)
1 parent 6d35594 commit 4076be5

File tree

18 files changed

+133
-0
lines changed

18 files changed

+133
-0
lines changed

โ€Žpackages/core/src/libraries/custom-profile-fields/utils.tsโ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ const validateRegexProfileField: ValidateCustomProfileField = (data, isStrict) =
6767
const validateAddressProfileField: ValidateCustomProfileField = (data, isStrict) => {
6868
const { config } = addressProfileFieldGuard.parse(data);
6969
assertThat(config.parts.length > 0, 'custom_profile_fields.invalid_address_parts');
70+
assertThat(
71+
!config.parts.some(({ type }) =>
72+
[CustomProfileFieldType.Address, CustomProfileFieldType.Fullname].includes(type)
73+
),
74+
'custom_profile_fields.invalid_sub_component_type'
75+
);
7076

7177
if (isStrict) {
7278
for (const part of config.parts) {
@@ -78,6 +84,12 @@ const validateAddressProfileField: ValidateCustomProfileField = (data, isStrict)
7884
const validateFullnameProfileField: ValidateCustomProfileField = (data, isStrict) => {
7985
const { config } = fullnameProfileFieldGuard.parse(data);
8086
assertThat(config.parts.length > 0, 'custom_profile_fields.invalid_fullname_parts');
87+
assertThat(
88+
!config.parts.some(({ type }) =>
89+
[CustomProfileFieldType.Address, CustomProfileFieldType.Fullname].includes(type)
90+
),
91+
'custom_profile_fields.invalid_sub_component_type'
92+
);
8193

8294
if (isStrict) {
8395
for (const part of config.parts) {

โ€Žpackages/integration-tests/src/tests/api/custom-profile-fields.test.tsโ€Ž

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,96 @@ describe('custom profile fields API', () => {
6666
);
6767
});
6868

69+
it('should fail to create if address field contains invalid sub-component type', async () => {
70+
await expectRejects(
71+
createCustomProfileField({
72+
name: 'address',
73+
type: CustomProfileFieldType.Address,
74+
required: true,
75+
config: {
76+
parts: [
77+
{
78+
name: 'formatted',
79+
type: CustomProfileFieldType.Address,
80+
enabled: true,
81+
required: true,
82+
},
83+
],
84+
},
85+
}),
86+
{
87+
code: 'custom_profile_fields.invalid_sub_component_type',
88+
status: 400,
89+
}
90+
);
91+
await expectRejects(
92+
createCustomProfileField({
93+
name: 'address',
94+
type: CustomProfileFieldType.Address,
95+
required: true,
96+
config: {
97+
parts: [
98+
{
99+
name: 'formatted',
100+
type: CustomProfileFieldType.Fullname,
101+
enabled: true,
102+
required: true,
103+
},
104+
],
105+
},
106+
}),
107+
{
108+
code: 'custom_profile_fields.invalid_sub_component_type',
109+
status: 400,
110+
}
111+
);
112+
});
113+
114+
it('should fail to create if fullname field contains invalid sub-component type', async () => {
115+
await expectRejects(
116+
createCustomProfileField({
117+
name: 'fullname',
118+
type: CustomProfileFieldType.Fullname,
119+
required: true,
120+
config: {
121+
parts: [
122+
{
123+
name: 'givenName',
124+
type: CustomProfileFieldType.Fullname,
125+
enabled: true,
126+
required: true,
127+
},
128+
],
129+
},
130+
}),
131+
{
132+
code: 'custom_profile_fields.invalid_sub_component_type',
133+
status: 400,
134+
}
135+
);
136+
await expectRejects(
137+
createCustomProfileField({
138+
name: 'fullname',
139+
type: CustomProfileFieldType.Fullname,
140+
required: true,
141+
config: {
142+
parts: [
143+
{
144+
name: 'middleName',
145+
type: CustomProfileFieldType.Address,
146+
enabled: true,
147+
required: true,
148+
},
149+
],
150+
},
151+
}),
152+
{
153+
code: 'custom_profile_fields.invalid_sub_component_type',
154+
status: 400,
155+
}
156+
);
157+
});
158+
69159
it('should fail to create if field name is conflicted', async () => {
70160
const nameField = await createCustomProfileField(nameData);
71161
await expectRejects(createCustomProfileField(nameData), {

โ€Žpackages/phrases/src/locales/ar/errors/custom-profile-fields.tsโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const custom_profile_fields = {
22
entity_not_exists_with_names: 'ุชุนุฐุฑ ุงู„ุนุซูˆุฑ ุนู„ู‰ ุงู„ูƒูŠุงู†ุงุช ุจุงู„ุฃุณู…ุงุก ุงู„ู…ู‚ุฏู…ุฉ: {{names}}',
33
invalid_min_max_input: 'ุฅุฏุฎุงู„ ุงู„ุญุฏ ุงู„ุฃุฏู†ู‰ ุฃูˆ ุงู„ุฃู‚ุตู‰ ุบูŠุฑ ุตุงู„ุญ.',
4+
invalid_default_value: 'ุงู„ู‚ูŠู…ุฉ ุงู„ุงูุชุฑุงุถูŠุฉ ุบูŠุฑ ุตุงู„ุญุฉ.',
45
invalid_options: 'ุฎูŠุงุฑุงุช ุงู„ุญู‚ู„ ุบูŠุฑ ุตุงู„ุญุฉ.',
56
invalid_regex_format: 'ุชู†ุณูŠู‚ ุงู„ุชุนุจูŠุฑ ุงู„ู†ู…ุทูŠ ุบูŠุฑ ุตุงู„ุญ.',
67
invalid_address_parts: 'ุฃุฌุฒุงุก ุงู„ุนู†ูˆุงู† ุบูŠุฑ ุตุงู„ุญุฉ.',
78
invalid_fullname_parts: 'ุฃุฌุฒุงุก ุงู„ุงุณู… ุงู„ูƒุงู…ู„ ุบูŠุฑ ุตุงู„ุญุฉ.',
9+
invalid_sub_component_type: 'ู†ูˆุน ุงู„ู…ูƒูˆู‘ู† ุงู„ูุฑุนูŠ ุบูŠุฑ ุตุงู„ุญ.',
810
name_exists: 'ู‡ู†ุงูƒ ุญู‚ู„ ุจุงู„ูุนู„ ุจู‡ุฐุง ุงู„ุงุณู….',
911
conflicted_sie_order: 'ู‡ู†ุงูƒ ุชุนุงุฑุถ ููŠ ุชุฑุชูŠุจ ุงู„ุญู‚ูˆู„ ู„ุชุฌุฑุจุฉ ุชุณุฌูŠู„ ุงู„ุฏุฎูˆู„.',
1012
invalid_name: 'ุงุณู… ุงู„ุญู‚ู„ ุบูŠุฑ ุตุงู„ุญ ุŒ ูŠูุณู…ุญ ูู‚ุท ุจุงู„ุฃุญุฑู ุฃูˆ ุงู„ุฃุฑู‚ุงู… ุŒ ู…ุน ู…ุฑุงุนุงุฉ ุญุงู„ุฉ ุงู„ุฃุญุฑู.',

โ€Žpackages/phrases/src/locales/de/errors/custom-profile-fields.tsโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ const custom_profile_fields = {
22
entity_not_exists_with_names:
33
'Entitรคten mit den angegebenen Namen kรถnnen nicht gefunden werden: {{names}}',
44
invalid_min_max_input: 'Ungรผltige Eingabe fรผr Minimum und Maximum.',
5+
invalid_default_value: 'Ungรผltiger Standardwert.',
56
invalid_options: 'Ungรผltige Feldoptionen.',
67
invalid_regex_format: 'Ungรผltiges Regex-Format.',
78
invalid_address_parts: 'Ungรผltige Adressbestandteile.',
89
invalid_fullname_parts: 'Ungรผltige Vor- und Nachnamenangaben.',
10+
invalid_sub_component_type: 'Ungรผltiger Unterkomponententyp.',
911
name_exists: 'Ein Feld mit diesem Namen existiert bereits.',
1012
conflicted_sie_order: 'Konflikt im Feldreihenfolgewert fรผr die Sign-in Experience.',
1113
invalid_name:

โ€Žpackages/phrases/src/locales/en/errors/custom-profile-fields.tsโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const custom_profile_fields = {
66
invalid_regex_format: 'Invalid regex format.',
77
invalid_address_parts: 'Invalid address parts.',
88
invalid_fullname_parts: 'Invalid fullname parts.',
9+
invalid_sub_component_type: 'Invalid sub-component type.',
910
name_exists: 'Field already exists with the given name.',
1011
conflicted_sie_order: 'Conflicted field order value for Sign-in Experience.',
1112
invalid_name: 'Invalid field name, only letters or numbers are allowed, case sensitive.',

โ€Žpackages/phrases/src/locales/es/errors/custom-profile-fields.tsโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const custom_profile_fields = {
22
entity_not_exists_with_names: 'No se pueden encontrar entidades con los nombres dados: {{names}}',
33
invalid_min_max_input: 'Entrada de mรญnimo y mรกximo no vรกlida.',
4+
invalid_default_value: 'Valor por defecto no vรกlido.',
45
invalid_options: 'Opciones de campo no vรกlidas.',
56
invalid_regex_format: 'Formato de expresiรณn regular no vรกlido.',
67
invalid_address_parts: 'Partes de direcciรณn no vรกlidas.',
78
invalid_fullname_parts: 'Partes de nombre completo no vรกlidas.',
9+
invalid_sub_component_type: 'Tipo de subcomponente no vรกlido.',
810
name_exists: 'Ya existe un campo con el nombre proporcionado.',
911
conflicted_sie_order:
1012
'Valor de orden de campo en conflicto para la experiencia de inicio de sesiรณn.',

โ€Žpackages/phrases/src/locales/fr/errors/custom-profile-fields.tsโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ const custom_profile_fields = {
22
entity_not_exists_with_names:
33
'Impossible de trouver des entitรฉs avec les noms donnรฉs : {{names}}',
44
invalid_min_max_input: 'Entrรฉe min et max invalide.',
5+
invalid_default_value: 'Valeur par dรฉfaut invalide.',
56
invalid_options: 'Options de champ invalides.',
67
invalid_regex_format: 'Format de regex invalide.',
78
invalid_address_parts: "Parties d'adresse invalides.",
89
invalid_fullname_parts: 'Parties de nom complet invalides.',
10+
invalid_sub_component_type: 'Type de sous-composant invalide.',
911
name_exists: 'Un champ existe dรฉjร  avec ce nom.',
1012
conflicted_sie_order: "Valeur d'ordre de champ en conflit pour l'expรฉrience de connexion.",
1113
invalid_name:

โ€Žpackages/phrases/src/locales/it/errors/custom-profile-fields.tsโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const custom_profile_fields = {
22
entity_not_exists_with_names: 'Impossibile trovare le entitร  con i nomi forniti: {{names}}',
33
invalid_min_max_input: 'Input minimo e massimo non valido.',
4+
invalid_default_value: 'Valore predefinito non valido.',
45
invalid_options: 'Opzioni del campo non valide.',
56
invalid_regex_format: 'Formato regex non valido.',
67
invalid_address_parts: "Parti dell'indirizzo non valide.",
78
invalid_fullname_parts: 'Parti del nome completo non valide.',
9+
invalid_sub_component_type: 'Tipo di sottocomponente non valido.',
810
name_exists: 'Esiste giร  un campo con il nome fornito.',
911
conflicted_sie_order: "Valore dell'ordine del campo in conflitto per Sign-in Experience.",
1012
invalid_name:

โ€Žpackages/phrases/src/locales/ja/errors/custom-profile-fields.tsโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const custom_profile_fields = {
22
entity_not_exists_with_names: 'ๆŒ‡ๅฎšใ•ใ‚ŒใŸๅๅ‰ใฎใ‚จใƒณใƒ†ใ‚ฃใƒ†ใ‚ฃใŒ่ฆ‹ใคใ‹ใ‚Šใพใ›ใ‚“: {{names}}',
33
invalid_min_max_input: 'ๆœ€ๅฐๅ€คใจๆœ€ๅคงๅ€คใฎๅ…ฅๅŠ›ใŒ็„กๅŠนใงใ™ใ€‚',
4+
invalid_default_value: 'ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆๅ€คใŒ็„กๅŠนใงใ™ใ€‚',
45
invalid_options: 'ใƒ•ใ‚ฃใƒผใƒซใƒ‰ใ‚ชใƒ—ใ‚ทใƒงใƒณใŒ็„กๅŠนใงใ™ใ€‚',
56
invalid_regex_format: 'ๆญฃ่ฆ่กจ็พใฎๅฝขๅผใŒ็„กๅŠนใงใ™ใ€‚',
67
invalid_address_parts: 'ไฝๆ‰€ใฎๆง‹ๆˆ่ฆ็ด ใŒ็„กๅŠนใงใ™ใ€‚',
78
invalid_fullname_parts: 'ๆฐๅใฎๆง‹ๆˆ่ฆ็ด ใŒ็„กๅŠนใงใ™ใ€‚',
9+
invalid_sub_component_type: 'ใ‚ตใƒ–ใ‚ณใƒณใƒใƒผใƒใƒณใƒˆใ‚ฟใ‚คใƒ—ใŒ็„กๅŠนใงใ™ใ€‚',
810
name_exists: 'ๆŒ‡ๅฎšใ•ใ‚ŒใŸๅๅ‰ใฎใƒ•ใ‚ฃใƒผใƒซใƒ‰ใฏใ™ใงใซๅญ˜ๅœจใ—ใพใ™ใ€‚',
911
conflicted_sie_order: 'ใ‚ตใ‚คใƒณใ‚คใƒณไฝ“้จ“ใฎใƒ•ใ‚ฃใƒผใƒซใƒ‰้ †ๅบใฎๅ€คใŒ้‡่ค‡ใ—ใฆใ„ใพใ™ใ€‚',
1012
invalid_name:

โ€Žpackages/phrases/src/locales/ko/errors/custom-profile-fields.tsโ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const custom_profile_fields = {
22
entity_not_exists_with_names: '์ฃผ์–ด์ง„ ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•˜๋Š” ์—”ํ‹ฐํ‹ฐ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {{names}}',
33
invalid_min_max_input: '์ตœ์†Œ๊ฐ’๊ณผ ์ตœ๋Œ€๊ฐ’ ์ž…๋ ฅ์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.',
4+
invalid_default_value: '๊ธฐ๋ณธ๊ฐ’์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.',
45
invalid_options: 'ํ•„๋“œ ์˜ต์…˜์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.',
56
invalid_regex_format: '์ •๊ทœ์‹ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.',
67
invalid_address_parts: '์ฃผ์†Œ ๊ตฌ์„ฑ ์š”์†Œ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.',
78
invalid_fullname_parts: '์ด๋ฆ„ ๊ตฌ์„ฑ ์š”์†Œ๊ฐ€ ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.',
9+
invalid_sub_component_type: 'ํ•˜์œ„ ๊ตฌ์„ฑ ์š”์†Œ ์œ ํ˜•์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค.',
810
name_exists: 'ํ•ด๋‹น ์ด๋ฆ„์˜ ํ•„๋“œ๊ฐ€ ์ด๋ฏธ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.',
911
conflicted_sie_order: 'Sign-in Experience ์šฉ ํ•„๋“œ ์ˆœ์„œ ๊ฐ’์ด ์ถฉ๋Œํ•ฉ๋‹ˆ๋‹ค.',
1012
invalid_name: 'ํ•„๋“œ ์ด๋ฆ„์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๊ตฌ๋ถ„ํ•˜๋ฉฐ, ๋ฌธ์ž ๋˜๋Š” ์ˆซ์ž๋งŒ ํ—ˆ์šฉ๋ฉ๋‹ˆ๋‹ค.',

0 commit comments

Comments
ย (0)