Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Dec 7, 2020
1 parent 9628647 commit d22f967
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 273 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,47 +314,47 @@ export default function createDeleteTests({ getService }: FtrProviderContext) {
},
})
.expect(200);
});

const response = await supertestWithoutAuth
.delete(`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password);
const response = await supertestWithoutAuth
.delete(`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password);

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(
'delete',
'test.noop',
'alertsFixture'
),
statusCode: 403,
});
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');
// Ensure task still exists
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(
'delete',
'test.noop',
'alertsFixture'
),
statusCode: 403,
});
objectRemover.add(space.id, createdAlert.id, 'alert', 'alerts');
// Ensure task still exists
await getScheduledTask(createdAlert.scheduledTaskId);
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(204);
expect(response.body).to.eql('');
try {
await getScheduledTask(createdAlert.scheduledTaskId);
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(204);
expect(response.body).to.eql('');
try {
await getScheduledTask(createdAlert.scheduledTaskId);
throw new Error('Should have removed scheduled task');
} catch (e) {
expect(e.status).to.eql(404);
}
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});
throw new Error('Should have removed scheduled task');
} catch (e) {
expect(e.status).to.eql(404);
}
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,50 +300,50 @@ export default function createDisableAlertTests({ getService }: FtrProviderConte
},
})
.expect(200);
});

const response = await alertUtils.getDisableRequest(createdAlert.id);
const response = await alertUtils.getDisableRequest(createdAlert.id);

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(
'disable',
'test.noop',
'alertsFixture'
),
statusCode: 403,
});
// Ensure task still exists
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(
'disable',
'test.noop',
'alertsFixture'
),
statusCode: 403,
});
// Ensure task still exists
await getScheduledTask(createdAlert.scheduledTaskId);
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(204);
expect(response.body).to.eql('');
try {
await getScheduledTask(createdAlert.scheduledTaskId);
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(204);
expect(response.body).to.eql('');
try {
await getScheduledTask(createdAlert.scheduledTaskId);
throw new Error('Should have removed scheduled task');
} catch (e) {
expect(e.status).to.eql(404);
}
// Ensure AAD isn't broken
await checkAAD({
supertest,
spaceId: space.id,
type: 'alert',
id: createdAlert.id,
});
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});
throw new Error('Should have removed scheduled task');
} catch (e) {
expect(e.status).to.eql(404);
}
// Ensure AAD isn't broken
await checkAAD({
supertest,
spaceId: space.id,
type: 'alert',
id: createdAlert.id,
});
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});

it(`shouldn't disable alert from another space`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,57 +317,55 @@ export default function createEnableAlertTests({ getService }: FtrProviderContex
},
})
.expect(200);
});

const response = await alertUtils.getEnableRequest(createdAlert.id);
const response = await alertUtils.getEnableRequest(createdAlert.id);

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(
'enable',
'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(204);
expect(response.body).to.eql('');
const { body: updatedAlert } = await supertestWithoutAuth
.get(`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.expect(200);
expect(typeof updatedAlert.scheduledTaskId).to.eql('string');
const { _source: taskRecord } = await getScheduledTask(
updatedAlert.scheduledTaskId
);
expect(taskRecord.type).to.eql('task');
expect(taskRecord.task.taskType).to.eql('alerting:test.noop');
expect(JSON.parse(taskRecord.task.params)).to.eql({
alertId: createdAlert.id,
spaceId: space.id,
});
// Ensure AAD isn't broken
await checkAAD({
supertest,
spaceId: space.id,
type: 'alert',
id: createdAlert.id,
});
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});
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(
'enable',
'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(204);
expect(response.body).to.eql('');
const { body: updatedAlert } = await supertestWithoutAuth
.get(`${getUrlPrefix(space.id)}/api/alerts/alert/${createdAlert.id}`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.expect(200);
expect(typeof updatedAlert.scheduledTaskId).to.eql('string');
const { _source: taskRecord } = await getScheduledTask(updatedAlert.scheduledTaskId);
expect(taskRecord.type).to.eql('task');
expect(taskRecord.task.taskType).to.eql('alerting:test.noop');
expect(JSON.parse(taskRecord.task.params)).to.eql({
alertId: createdAlert.id,
spaceId: space.id,
});
// Ensure AAD isn't broken
await checkAAD({
supertest,
spaceId: space.id,
type: 'alert',
id: createdAlert.id,
});
break;
default:
throw new Error(`Scenario untested: ${JSON.stringify(scenario)}`);
}
});

it(`shouldn't enable alert from another space`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,38 +48,38 @@ export default function eventLogTests({ getService }: FtrProviderContext) {
},
})
.expect(200);
});

const events = await retry.try(async () => {
// there can be a successful execute before the error one
const someEvents = await getEventLog({
getService,
spaceId,
type: 'alert',
id: alertId,
provider: 'alerting',
actions: new Map([['execute', { gte: 1 }]]),
});
const errorEvents = someEvents.filter(
(event) => event?.kibana?.alerting?.status === 'error'
);
if (errorEvents.length === 0) {
throw new Error('no execute/error events yet');
}
return errorEvents;
const events = await retry.try(async () => {
// there can be a successful execute before the error one
const someEvents = await getEventLog({
getService,
spaceId,
type: 'alert',
id: alertId,
provider: 'alerting',
actions: new Map([['execute', { gte: 1 }]]),
});
const errorEvents = someEvents.filter(
(event) => event?.kibana?.alerting?.status === 'error'
);
if (errorEvents.length === 0) {
throw new Error('no execute/error events yet');
}
return errorEvents;
});

const event = events[0];
expect(event).to.be.ok();
const event = events[0];
expect(event).to.be.ok();

validateEvent(event, {
spaceId,
savedObjects: [{ type: 'alert', id: alertId, rel: 'primary' }],
outcome: 'failure',
message: `test.noop:${alertId}: execution failed`,
errorMessage: 'Unable to decrypt attribute "apiKey"',
status: 'error',
reason: 'decrypt',
});
validateEvent(event, {
spaceId,
savedObjects: [{ type: 'alert', id: alertId, rel: 'primary' }],
outcome: 'failure',
message: `test.noop:${alertId}: execution failed`,
errorMessage: 'Unable to decrypt attribute "apiKey"',
status: 'error',
reason: 'decrypt',
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon
let executionStatus = await waitForStatus(alertId, new Set(['ok']), 10000);

await retry.try(async () => {
// Delay before performing update to avoid 409 errors
await new Promise((resolve) => setTimeout(resolve, 1000));

// break AAD
await supertest
.put(`${getUrlPrefix(spaceId)}/api/alerts_fixture/saved_object/alert/${alertId}`)
Expand All @@ -52,12 +49,12 @@ export default function executionStatusAlertTests({ getService }: FtrProviderCon
},
})
.expect(200);

executionStatus = await waitForStatus(alertId, new Set(['error']));
expect(executionStatus.error).to.be.ok();
expect(executionStatus.error.reason).to.be(AlertExecutionStatusErrorReasons.Decrypt);
expect(executionStatus.error.message).to.be('Unable to decrypt attribute "apiKey"');
});

executionStatus = await waitForStatus(alertId, new Set(['error']));
expect(executionStatus.error).to.be.ok();
expect(executionStatus.error.reason).to.be(AlertExecutionStatusErrorReasons.Decrypt);
expect(executionStatus.error.message).to.be('Unable to decrypt attribute "apiKey"');
});
});

Expand Down
Loading

0 comments on commit d22f967

Please sign in to comment.