Skip to content

Commit

Permalink
moves 404-not-found tests to execute for all authorized users
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurley14 committed Jul 8, 2021
1 parent 0b247b3 commit c22e179
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,6 @@ export default ({ getService }: FtrProviderContext) => {
await esArchiver.unload('x-pack/test/functional/es_archives/rule_registry/alerts');
});

it('should return a 404 when superuser accesses not-existent alert', async () => {
await supertestWithoutAuth
.get(`${getSpaceUrlPrefix()}${TEST_URL}?id=myfakeid&index=${APM_ALERT_INDEX}`)
.auth(superUser.username, superUser.password)
.set('kbn-xsrf', 'true')
.expect(404);
});

it('should return a 404 when superuser accesses not-existent alerts as data index', async () => {
await supertestWithoutAuth
.get(`${getSpaceUrlPrefix()}${TEST_URL}?id=${APM_ALERT_ID}&index=myfakeindex`)
.auth(superUser.username, superUser.password)
.set('kbn-xsrf', 'true')
.expect(404);
});

function addTests({ space, authorizedUsers, unauthorizedUsers, alertId, index }: TestCase) {
authorizedUsers.forEach(({ username, password }) => {
it(`${username} should be able to access alert ${alertId} in ${space}/${index}`, async () => {
Expand All @@ -124,15 +108,22 @@ export default ({ getService }: FtrProviderContext) => {
.expect(200);
});

// // NOTE: this test case actually results in a 500 error, not 404
// it(`${username} should fail to access a non-existent alert in ${space}/${index}`, async () => {
// const fakeAlertId = 'some-alert-id-that-doesnt-exist';
// await supertestWithoutAuth
// .get(`${getSpaceUrlPrefix(space)}${TEST_URL}?id=${fakeAlertId}&index=${index}`)
// .auth(username, password)
// .set('kbn-xsrf', 'true')
// .expect(404);
// });
it(`${username} should fail to access a non-existent alert in ${space}/${index}`, async () => {
const fakeAlertId = 'some-alert-id-that-doesnt-exist';
await supertestWithoutAuth
.get(`${getSpaceUrlPrefix(space)}${TEST_URL}?id=${fakeAlertId}&index=${index}`)
.auth(username, password)
.set('kbn-xsrf', 'true')
.expect(404);
});

it(`${username} should return a 404 when trying to accesses not-existent alerts as data index`, async () => {
await supertestWithoutAuth
.get(`${getSpaceUrlPrefix(space)}${TEST_URL}?id=${APM_ALERT_ID}&index=myfakeindex`)
.auth(username, password)
.set('kbn-xsrf', 'true')
.expect(404);
});
});

unauthorizedUsers.forEach(({ username, password }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,6 @@ export default ({ getService }: FtrProviderContext) => {
await esArchiver.unload('x-pack/test/functional/es_archives/rule_registry/alerts');
});

it('should return a 404 when superuser accesses not-existent alert', async () => {
await supertestWithoutAuth
.post(`${getSpaceUrlPrefix()}${TEST_URL}`)
.auth(superUser.username, superUser.password)
.set('kbn-xsrf', 'true')
.send({
ids: ['this id does not exist'],
status: 'closed',
index: APM_ALERT_INDEX,
_version: Buffer.from(JSON.stringify([0, 1]), 'utf8').toString('base64'),
})
.expect(404);
});

it('should return a 404 when superuser accesses not-existent alerts as data index', async () => {
await supertestWithoutAuth
.post(`${getSpaceUrlPrefix()}${TEST_URL}`)
.auth(superUser.username, superUser.password)
.set('kbn-xsrf', 'true')
.send({
ids: [APM_ALERT_ID],
status: 'closed',
index: 'this index does not exist',
_version: Buffer.from(JSON.stringify([0, 1]), 'utf8').toString('base64'),
})
.expect(404);
});

function addTests({ space, authorizedUsers, unauthorizedUsers, alertId, index }: TestCase) {
authorizedUsers.forEach(({ username, password }) => {
it(`${username} should be able to update alert ${alertId} in ${space}/${index}`, async () => {
Expand Down Expand Up @@ -159,21 +131,34 @@ export default ({ getService }: FtrProviderContext) => {
.expect(409);
});

// // NOTE: this test case actually results in a 500 error, not 404
// it(`${username} should fail to update a non-existent alert in ${space}/${index}`, async () => {
// const fakeAlertId = 'some-alert-id-that-doesnt-exist';
// await supertestWithoutAuth
// .post(`${getSpaceUrlPrefix(space)}${TEST_URL}`)
// .auth(username, password)
// .set('kbn-xsrf', 'true')
// .send({
// ids: [fakeAlertId],
// status: 'closed',
// index,
// _version: ALERT_VERSION,
// })
// .expect(404);
// });
it(`${username} should fail to update a non-existent alert in ${space}/${index}`, async () => {
const fakeAlertId = 'some-alert-id-that-doesnt-exist';
await supertestWithoutAuth
.post(`${getSpaceUrlPrefix(space)}${TEST_URL}`)
.auth(username, password)
.set('kbn-xsrf', 'true')
.send({
ids: [fakeAlertId],
status: 'closed',
index,
_version: ALERT_VERSION,
})
.expect(404);
});

it(`${username} should return a 404 when superuser accesses not-existent alerts as data index`, async () => {
await supertestWithoutAuth
.get(`${getSpaceUrlPrefix(space)}${TEST_URL}?id=${APM_ALERT_ID}&index=myfakeindex`)
.auth(username, password)
.set('kbn-xsrf', 'true')
.send({
ids: [APM_ALERT_ID],
status: 'closed',
index: 'this index does not exist',
_version: Buffer.from(JSON.stringify([0, 1]), 'utf8').toString('base64'),
})
.expect(404);
});
});

unauthorizedUsers.forEach(({ username, password }) => {
Expand Down

0 comments on commit c22e179

Please sign in to comment.