parent
a4c7d111c5
commit
3f90e72b1d
|
@ -26,6 +26,7 @@ export type AgentActionType =
|
||||||
| 'POLICY_CHANGE'
|
| 'POLICY_CHANGE'
|
||||||
| 'UNENROLL'
|
| 'UNENROLL'
|
||||||
| 'UPGRADE'
|
| 'UPGRADE'
|
||||||
|
| 'SETTINGS'
|
||||||
// INTERNAL* actions are mean to interupt long polling calls these actions will not be distributed to the agent
|
// INTERNAL* actions are mean to interupt long polling calls these actions will not be distributed to the agent
|
||||||
| 'INTERNAL_POLICY_REASSIGN';
|
| 'INTERNAL_POLICY_REASSIGN';
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ describe('test actions handlers schema', () => {
|
||||||
NewAgentActionSchema.validate({
|
NewAgentActionSchema.validate({
|
||||||
type: 'POLICY_CHANGE',
|
type: 'POLICY_CHANGE',
|
||||||
data: 'data',
|
data: 'data',
|
||||||
sent_at: '2020-03-14T19:45:02.620Z',
|
|
||||||
})
|
})
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
@ -34,7 +33,6 @@ describe('test actions handlers schema', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
NewAgentActionSchema.validate({
|
NewAgentActionSchema.validate({
|
||||||
data: 'data',
|
data: 'data',
|
||||||
sent_at: '2020-03-14T19:45:02.620Z',
|
|
||||||
});
|
});
|
||||||
}).toThrowError();
|
}).toThrowError();
|
||||||
});
|
});
|
||||||
|
@ -55,7 +53,6 @@ describe('test actions handlers', () => {
|
||||||
action: {
|
action: {
|
||||||
type: 'POLICY_CHANGE',
|
type: 'POLICY_CHANGE',
|
||||||
data: 'data',
|
data: 'data',
|
||||||
sent_at: '2020-03-14T19:45:02.620Z',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
|
|
|
@ -62,7 +62,8 @@ export const AgentEventSchema = schema.object({
|
||||||
id: schema.string(),
|
id: schema.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const NewAgentActionSchema = schema.object({
|
export const NewAgentActionSchema = schema.oneOf([
|
||||||
|
schema.object({
|
||||||
type: schema.oneOf([
|
type: schema.oneOf([
|
||||||
schema.literal('POLICY_CHANGE'),
|
schema.literal('POLICY_CHANGE'),
|
||||||
schema.literal('UNENROLL'),
|
schema.literal('UNENROLL'),
|
||||||
|
@ -71,5 +72,16 @@ export const NewAgentActionSchema = schema.object({
|
||||||
]),
|
]),
|
||||||
data: schema.maybe(schema.any()),
|
data: schema.maybe(schema.any()),
|
||||||
ack_data: schema.maybe(schema.any()),
|
ack_data: schema.maybe(schema.any()),
|
||||||
sent_at: schema.maybe(schema.string()),
|
}),
|
||||||
});
|
schema.object({
|
||||||
|
type: schema.oneOf([schema.literal('SETTINGS')]),
|
||||||
|
data: schema.object({
|
||||||
|
log_level: schema.oneOf([
|
||||||
|
schema.literal('debug'),
|
||||||
|
schema.literal('info'),
|
||||||
|
schema.literal('warning'),
|
||||||
|
schema.literal('error'),
|
||||||
|
]),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
|
@ -36,6 +36,39 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
expect(apiResponse.item.data).to.eql({ data: 'action_data' });
|
expect(apiResponse.item.data).to.eql({ data: 'action_data' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return a 200 if this a valid SETTINGS action request', async () => {
|
||||||
|
const { body: apiResponse } = await supertest
|
||||||
|
.post(`/api/fleet/agents/agent1/actions`)
|
||||||
|
.set('kbn-xsrf', 'xx')
|
||||||
|
.send({
|
||||||
|
action: {
|
||||||
|
type: 'SETTINGS',
|
||||||
|
data: { log_level: 'debug' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(apiResponse.item.type).to.eql('SETTINGS');
|
||||||
|
expect(apiResponse.item.data).to.eql({ log_level: 'debug' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a 400 if this a invalid SETTINGS action request', async () => {
|
||||||
|
const { body: apiResponse } = await supertest
|
||||||
|
.post(`/api/fleet/agents/agent1/actions`)
|
||||||
|
.set('kbn-xsrf', 'xx')
|
||||||
|
.send({
|
||||||
|
action: {
|
||||||
|
type: 'SETTINGS',
|
||||||
|
data: { log_level: 'thisnotavalidloglevel' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.expect(400);
|
||||||
|
|
||||||
|
expect(apiResponse.message).to.match(
|
||||||
|
/\[request body.action\.[0-9]*\.data\.log_level]: types that failed validation/
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return a 400 when request does not have type information', async () => {
|
it('should return a 400 when request does not have type information', async () => {
|
||||||
const { body: apiResponse } = await supertest
|
const { body: apiResponse } = await supertest
|
||||||
.post(`/api/fleet/agents/agent1/actions`)
|
.post(`/api/fleet/agents/agent1/actions`)
|
||||||
|
@ -43,12 +76,11 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
.send({
|
.send({
|
||||||
action: {
|
action: {
|
||||||
data: { data: 'action_data' },
|
data: { data: 'action_data' },
|
||||||
sent_at: '2020-03-18T19:45:02.620Z',
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.expect(400);
|
.expect(400);
|
||||||
expect(apiResponse.message).to.eql(
|
expect(apiResponse.message).to.match(
|
||||||
'[request body.action.type]: expected at least one defined value but got [undefined]'
|
/\[request body.action\.[0-9]*\.type]: expected at least one defined value but got \[undefined]/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -60,7 +92,6 @@ export default function (providerContext: FtrProviderContext) {
|
||||||
action: {
|
action: {
|
||||||
type: 'POLICY_CHANGE',
|
type: 'POLICY_CHANGE',
|
||||||
data: { data: 'action_data' },
|
data: { data: 'action_data' },
|
||||||
sent_at: '2020-03-18T19:45:02.620Z',
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.expect(404);
|
.expect(404);
|
||||||
|
|
Loading…
Reference in a new issue