-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest Manager] Add namespace validation (#75381)
* Add namespace validation on APIs and UI * Add test coverage * Fix imports * Fix schema * Rename to policy * Fix typo
- Loading branch information
Showing
10 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/ingest_manager/common/services/is_valid_namespace.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { isValidNamespace } from './is_valid_namespace'; | ||
|
||
describe('Ingest Manager - isValidNamespace', () => { | ||
it('returns true for valid namespaces', () => { | ||
expect(isValidNamespace('default')).toBe(true); | ||
expect(isValidNamespace('namespace-with-dash')).toBe(true); | ||
expect(isValidNamespace('123')).toBe(true); | ||
}); | ||
|
||
it('returns false for invalid namespaces', () => { | ||
expect(isValidNamespace('Default')).toBe(false); | ||
expect(isValidNamespace('namespace with spaces')).toBe(false); | ||
expect(isValidNamespace('foo/bar')).toBe(false); | ||
expect(isValidNamespace('foo\\bar')).toBe(false); | ||
expect(isValidNamespace('foo*bar')).toBe(false); | ||
expect(isValidNamespace('foo?bar')).toBe(false); | ||
expect(isValidNamespace('foo"bar')).toBe(false); | ||
expect(isValidNamespace('foo<bar')).toBe(false); | ||
expect(isValidNamespace('foo|bar')).toBe(false); | ||
expect(isValidNamespace('foo,bar')).toBe(false); | ||
expect(isValidNamespace('foo#bar')).toBe(false); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
x-pack/plugins/ingest_manager/common/services/is_valid_namespace.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// Namespace string eventually becomes part of an index name. This method partially implements index name rules from | ||
// https://github.com/elastic/elasticsearch/blob/master/docs/reference/indices/create-index.asciidoc | ||
export function isValidNamespace(namespace: string) { | ||
return ( | ||
typeof namespace === 'string' && | ||
// Lowercase only | ||
namespace === namespace.toLowerCase() && | ||
// Cannot include \, /, *, ?, ", <, >, |, space character, comma, #, : | ||
/^[^\*\\/\?"<>|\s,#:]+$/.test(namespace) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters