From 04b451b1625ee65aba37edd2933586c1e44ee503 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Wed, 12 Feb 2025 10:57:54 +0100 Subject: [PATCH 1/2] fix package name validation --- .../shared/automatic_import/common/constants.ts | 2 +- .../steps/data_stream_step/translations.ts | 2 +- .../build_integration.test.ts | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/x-pack/platform/plugins/shared/automatic_import/common/constants.ts b/x-pack/platform/plugins/shared/automatic_import/common/constants.ts index ee668a859cc05..109de8faf9e1a 100644 --- a/x-pack/platform/plugins/shared/automatic_import/common/constants.ts +++ b/x-pack/platform/plugins/shared/automatic_import/common/constants.ts @@ -48,7 +48,7 @@ export const CATEGORIZATION_REVIEW_MAX_CYCLES = 5; export const CATEGORIZATION_RECURSION_LIMIT = 50; // Name regex pattern -export const NAME_REGEX_PATTERN = /^[a-z0-9_]+$/; +export const NAME_REGEX_PATTERN = /^[a-z_][a-z0-9_]+$/; // Datastream name regex pattern. Same regex that for the name validation in elastic-package export const DATASTREAM_NAME_REGEX_PATTERN = /^([a-z0-9]{2}|[a-z0-9][a-z0-9_]+[a-z0-9])$/; diff --git a/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/translations.ts b/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/translations.ts index 4e6f3ab72313c..c0f337d381e15 100644 --- a/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/translations.ts +++ b/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/translations.ts @@ -46,7 +46,7 @@ export const NO_SPACES_HELP = i18n.translate( 'xpack.automaticImport.step.dataStream.noSpacesHelpText', { defaultMessage: - 'Name must be at least 2 characters long and can only contain lowercase letters, numbers, and underscores (_)', + 'Name must be at least 2 characters long, start with a letter, and can only contain lowercase letters, numbers, and underscores (_)', } ); export const PACKAGE_NAMES_FETCH_ERROR = i18n.translate( diff --git a/x-pack/platform/plugins/shared/automatic_import/server/integration_builder/build_integration.test.ts b/x-pack/platform/plugins/shared/automatic_import/server/integration_builder/build_integration.test.ts index cb40f9731242c..83a5b62fbbaee 100644 --- a/x-pack/platform/plugins/shared/automatic_import/server/integration_builder/build_integration.test.ts +++ b/x-pack/platform/plugins/shared/automatic_import/server/integration_builder/build_integration.test.ts @@ -304,6 +304,23 @@ describe('isValidName', () => { expect(isValidName('valid_name')).toBe(true); expect(isValidName('anothervalidname')).toBe(true); }); + it('should return false for names starting with numbers', () => { + expect(isValidName('123name')).toBe(false); + expect(isValidName('1name')).toBe(false); + expect(isValidName('999invalid')).toBe(false); + }); + + it('should return false for names starting with underscore', () => { + expect(isValidName('_name')).toBe(true); + expect(isValidName('_invalid_name')).toBe(true); + expect(isValidName('__name')).toBe(true); + }); + + it('should return true for names starting with letters followed by numbers', () => { + expect(isValidName('name123')).toBe(true); + expect(isValidName('valid1')).toBe(true); + expect(isValidName('valid_123')).toBe(true); + }); it('should return false for empty string', () => { expect(isValidName('')).toBe(false); From 62663c354a87deb4dba32bf6be808014f2ed11b7 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Wed, 12 Feb 2025 11:09:57 +0100 Subject: [PATCH 2/2] Remove the predefined value --- .../steps/data_stream_step/data_stream_step.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/data_stream_step.tsx b/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/data_stream_step.tsx index 3b3ac84635991..d929dae7812e3 100644 --- a/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/data_stream_step.tsx +++ b/x-pack/platform/plugins/shared/automatic_import/public/components/create_integration/create_automatic_import/steps/data_stream_step/data_stream_step.tsx @@ -195,7 +195,7 @@ export const DataStreamStep = React.memo(