mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Fleet] do not allow empty name for agent policy (#124853)
This commit is contained in:
parent
ca10263ed6
commit
912f4b910f
3 changed files with 24 additions and 2 deletions
|
@ -206,7 +206,12 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
|
|||
updatedAgentPolicy: NewAgentPolicy
|
||||
) => {
|
||||
if (selectedTab === SelectedPolicyTab.NEW) {
|
||||
if (!updatedAgentPolicy.name || !updatedAgentPolicy.namespace) {
|
||||
if (
|
||||
!updatedAgentPolicy.name ||
|
||||
updatedAgentPolicy.name.trim() === '' ||
|
||||
!updatedAgentPolicy.namespace ||
|
||||
updatedAgentPolicy.namespace.trim() === ''
|
||||
) {
|
||||
setHasAgentPolicyError(true);
|
||||
} else {
|
||||
setHasAgentPolicyError(false);
|
||||
|
|
|
@ -11,9 +11,15 @@ import { agentPolicyStatuses, dataTypes } from '../../../common';
|
|||
|
||||
import { PackagePolicySchema, NamespaceSchema } from './package_policy';
|
||||
|
||||
function validateNonEmptyString(val: string) {
|
||||
if (val.trim() === '') {
|
||||
return 'Invalid empty string';
|
||||
}
|
||||
}
|
||||
|
||||
export const AgentPolicyBaseSchema = {
|
||||
id: schema.maybe(schema.string()),
|
||||
name: schema.string({ minLength: 1 }),
|
||||
name: schema.string({ minLength: 1, validate: validateNonEmptyString }),
|
||||
namespace: NamespaceSchema,
|
||||
description: schema.maybe(schema.string()),
|
||||
is_managed: schema.maybe(schema.boolean()),
|
||||
|
|
|
@ -101,6 +101,17 @@ export default function (providerContext: FtrProviderContext) {
|
|||
.expect(400);
|
||||
});
|
||||
|
||||
it('should return a 400 with an empty name', async () => {
|
||||
await supertest
|
||||
.post(`/api/fleet/agent_policies`)
|
||||
.set('kbn-xsrf', 'xxxx')
|
||||
.send({
|
||||
name: ' ',
|
||||
namespace: 'default',
|
||||
})
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it('should return a 400 with an invalid namespace', async () => {
|
||||
await supertest
|
||||
.post(`/api/fleet/agent_policies`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue