Skip to content

Commit 6cb7d98

Browse files
committed
Add API integration tests
1 parent 1bc964c commit 6cb7d98

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/create.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,45 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
347347
}
348348
});
349349

350+
it('should handle create alert request appropriately when alert name has leading and trailing whitespaces', async () => {
351+
const response = await supertestWithoutAuth
352+
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)
353+
.set('kbn-xsrf', 'foo')
354+
.auth(user.username, user.password)
355+
.send(
356+
getTestAlertData({
357+
name: ' leading and trailing whitespace ',
358+
})
359+
);
360+
361+
switch (scenario.id) {
362+
case 'no_kibana_privileges at space1':
363+
case 'global_read at space1':
364+
case 'space_1_all at space2':
365+
expect(response.statusCode).to.eql(403);
366+
expect(response.body).to.eql({
367+
error: 'Forbidden',
368+
message: getConsumerUnauthorizedErrorMessage(
369+
'create',
370+
'test.noop',
371+
'alertsFixture'
372+
),
373+
statusCode: 403,
374+
});
375+
break;
376+
case 'superuser at space1':
377+
case 'space_1_all at space1':
378+
case 'space_1_all_alerts_none_actions at space1':
379+
case 'space_1_all_with_restricted_fixture at space1':
380+
expect(response.statusCode).to.eql(200);
381+
expect(response.body.name).to.eql(' leading and trailing whitespace ');
382+
objectRemover.add(space.id, response.body.id, 'alert', 'alerts');
383+
break;
384+
default:
385+
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
386+
}
387+
});
388+
350389
it('should handle create alert request appropriately when alert type is unregistered', async () => {
351390
const response = await supertestWithoutAuth
352391
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)

x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/update.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,57 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
505505
}
506506
});
507507

508+
it('should handle update alert request appropriately when alert name has leading and trailing whitespaces', async () => {
509+
const { body: createdAlert } = await supertest
510+
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)
511+
.set('kbn-xsrf', 'foo')
512+
.send(getTestAlertData())
513+
.expect(200);
514+
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');
515+
516+
const updatedData = {
517+
name: ' leading and trailing whitespace ',
518+
tags: ['bar'],
519+
params: {
520+
foo: true,
521+
},
522+
schedule: { interval: '12s' },
523+
actions: [],
524+
throttle: '1m',
525+
};
526+
const response = await supertestWithoutAuth
527+
.put(`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}`)
528+
.set('kbn-xsrf', 'foo')
529+
.auth(user.username, user.password)
530+
.send(updatedData);
531+
532+
switch (scenario.id) {
533+
case 'no_kibana_privileges at space1':
534+
case 'space_1_all at space2':
535+
case 'global_read at space1':
536+
expect(response.statusCode).to.eql(403);
537+
expect(response.body).to.eql({
538+
error: 'Forbidden',
539+
message: getConsumerUnauthorizedErrorMessage(
540+
'update',
541+
'test.noop',
542+
'alertsFixture'
543+
),
544+
statusCode: 403,
545+
});
546+
break;
547+
case 'superuser at space1':
548+
case 'space_1_all at space1':
549+
case 'space_1_all_alerts_none_actions at space1':
550+
case 'space_1_all_with_restricted_fixture at space1':
551+
expect(response.statusCode).to.eql(200);
552+
expect(response.body.name).to.eql(' leading and trailing whitespace ');
553+
break;
554+
default:
555+
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
556+
}
557+
});
558+
508559
it(`shouldn't update alert from another space`, async () => {
509560
const { body: createdAlert } = await supertest
510561
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)

0 commit comments

Comments
 (0)