Skip to content

Commit

Permalink
Add API integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Aug 27, 2020
1 parent 1bc964c commit 6cb7d98
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,45 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
}
});

it('should handle create alert request appropriately when alert name has leading and trailing whitespaces', async () => {
const response = await supertestWithoutAuth
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.send(
getTestAlertData({
name: ' leading and trailing whitespace ',
})
);

switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'global_read at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'create',
'test.noop',
'alertsFixture'
),
statusCode: 403,
});
break;
case 'superuser at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
case 'space_1_all_with_restricted_fixture at space1':
expect(response.statusCode).to.eql(200);
expect(response.body.name).to.eql(' leading and trailing whitespace ');
objectRemover.add(space.id, response.body.id, 'alert', 'alerts');
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});

it('should handle create alert request appropriately when alert type is unregistered', async () => {
const response = await supertestWithoutAuth
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,57 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
}
});

it('should handle update alert request appropriately when alert name has leading and trailing whitespaces', async () => {
const { body: createdAlert } = await supertest
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)
.set('kbn-xsrf', 'foo')
.send(getTestAlertData())
.expect(200);
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');

const updatedData = {
name: ' leading and trailing whitespace ',
tags: ['bar'],
params: {
foo: true,
},
schedule: { interval: '12s' },
actions: [],
throttle: '1m',
};
const response = await supertestWithoutAuth
.put(`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.send(updatedData);

switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
case 'global_read at space1':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'update',
'test.noop',
'alertsFixture'
),
statusCode: 403,
});
break;
case 'superuser at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
case 'space_1_all_with_restricted_fixture at space1':
expect(response.statusCode).to.eql(200);
expect(response.body.name).to.eql(' leading and trailing whitespace ');
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});

it(`shouldn't update alert from another space`, async () => {
const { body: createdAlert } = await supertest
.post(`${getUrlPrefix(space.id)}/api/alerts/alert`)
Expand Down

0 comments on commit 6cb7d98

Please sign in to comment.