|
6 | 6 |
|
7 | 7 | import expect from '@kbn/expect'; |
8 | 8 |
|
9 | | -import { DETECTION_ENGINE_RULES_URL } from '../../../../plugins/security_solution/common/constants'; |
| 9 | +import { |
| 10 | + DETECTION_ENGINE_RULES_URL, |
| 11 | + DETECTION_ENGINE_RULES_STATUS_URL, |
| 12 | +} from '../../../../plugins/security_solution/common/constants'; |
10 | 13 | import { FtrProviderContext } from '../../common/ftr_provider_context'; |
11 | 14 | import { |
12 | 15 | createSignalsIndex, |
@@ -65,6 +68,46 @@ export default ({ getService }: FtrProviderContext) => { |
65 | 68 | expect(bodyToCompare).to.eql(getSimpleRuleOutput()); |
66 | 69 | }); |
67 | 70 |
|
| 71 | + /* |
| 72 | + This test is to ensure no future regressions introduced by the following scenario |
| 73 | + a call to updateApiKey was invalidating the api key used by the |
| 74 | + rule while the rule was executing, or even before it executed, |
| 75 | + on the first rule run. |
| 76 | + this pr https://github.com/elastic/kibana/pull/68184 |
| 77 | + fixed this by finding the true source of a bug that required the manual |
| 78 | + api key update, and removed the call to that function. |
| 79 | +
|
| 80 | + When the api key is updated before / while the rule is executing, the alert |
| 81 | + executor no longer has access to a service to update the rule status |
| 82 | + saved object in Elasticsearch. Because of this, we cannot set the rule into |
| 83 | + a 'failure' state, so the user ends up seeing 'going to run' as that is the |
| 84 | + last status set for the rule before it erupts in an error that cannot be |
| 85 | + recorded inside of the executor. |
| 86 | +
|
| 87 | + This adds an e2e test for the backend to catch that in case |
| 88 | + this pops up again elsewhere. |
| 89 | + */ |
| 90 | + it('should create a single rule with a rule_id and validate it ran successfully', async () => { |
| 91 | + const simpleRule = getSimpleRule(); |
| 92 | + const { body } = await supertest |
| 93 | + .post(DETECTION_ENGINE_RULES_URL) |
| 94 | + .set('kbn-xsrf', 'true') |
| 95 | + .send(simpleRule) |
| 96 | + .expect(200); |
| 97 | + |
| 98 | + // wait for Task Manager to execute the rule and update status |
| 99 | + await new Promise((resolve) => setTimeout(resolve, 5000)); |
| 100 | + const { body: statusBody } = await supertest |
| 101 | + .post(DETECTION_ENGINE_RULES_STATUS_URL) |
| 102 | + .set('kbn-xsrf', 'true') |
| 103 | + .send({ ids: [body.id] }) |
| 104 | + .expect(200); |
| 105 | + |
| 106 | + const bodyToCompare = removeServerGeneratedProperties(body); |
| 107 | + expect(bodyToCompare).to.eql(getSimpleRuleOutput()); |
| 108 | + expect(statusBody[body.id].current_status.status).to.eql('succeeded'); |
| 109 | + }); |
| 110 | + |
68 | 111 | it('should create a single rule without an input index', async () => { |
69 | 112 | const { index, ...payload } = getSimpleRule(); |
70 | 113 | const { index: _index, ...expected } = getSimpleRuleOutput(); |
|
0 commit comments