-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add namespace validation on APIs and UI * Add test coverage * Fix imports * Fix schema * Rename to policy * Fix typo # Conflicts: # x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_policy/components/agent_policy_form.tsx # x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_policy/create_package_policy_page/services/validate_package_policy.ts # x-pack/plugins/ingest_manager/public/applications/ingest_manager/services/index.ts # x-pack/plugins/ingest_manager/server/types/models/agent_policy.ts # x-pack/plugins/ingest_manager/server/types/models/package_policy.ts # x-pack/test/ingest_manager_api_integration/apis/agent_policy/agent_policy.ts # x-pack/test/ingest_manager_api_integration/apis/package_policy/create.ts
- 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