Skip to content

Commit

Permalink
[Failing Test] Fixes intermittent failures in audit log integration t…
Browse files Browse the repository at this point in the history
…ests (#154935)

resolves #119267

## Summary
As [discussed in the
issue](#119267 (comment)),
we believed the issue to be timing between file write and read, however
this is not the case. I found that two 'saved_object_find' events were
being logged - the expected user one (for a 'dashboard'), and one by the
fleet app (for 'epm-packages'). Should the 'epm-packages' event get
logged before the 'dashboard' event, the test fails because the first
'saved_object_find' event it finds does not contain the expected user
data in the audit. This appears to happen much less frequently in CI
than locally for whatever reason.

## Fix
I have added additional criteria when looking for the
'saved_object_find' event so it will only find an event for a
'dashboard' object.

## Testing
Flaky Test Runner:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2150
  • Loading branch information
jeramysoucy authored Apr 19, 2023
1 parent e025496 commit 03a2cd7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions x-pack/test/security_api_integration/tests/audit/audit_log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export default function ({ getService }: FtrProviderContext) {
const retry = getService('retry');
const { username, password } = getService('config').get('servers.kibana');

// FLAKY: https://github.com/elastic/kibana/issues/119267
describe.skip('Audit Log', function () {
describe('Audit Log', function () {
const logFilePath = Path.resolve(__dirname, '../../plugins/audit_log/audit.log');
const logFile = new FileWrapper(logFilePath, retry);

Expand All @@ -27,12 +26,12 @@ export default function ({ getService }: FtrProviderContext) {
it('logs audit events when reading and writing saved objects', async () => {
await supertest.get('/audit_log?query=param').set('kbn-xsrf', 'foo').expect(204);
await retry.waitFor('logs event in the dest file', async () => await logFile.isNotEmpty());

const content = await logFile.readJSON();

const httpEvent = content.find((c) => c.event.action === 'http_request');
expect(httpEvent).to.be.ok();
expect(httpEvent.trace.id).to.be.ok();

expect(httpEvent.user.name).to.be(username);
expect(httpEvent.kibana.space_id).to.be('default');
expect(httpEvent.http.request.method).to.be('get');
Expand All @@ -45,7 +44,12 @@ export default function ({ getService }: FtrProviderContext) {
expect(createEvent.user.name).to.be(username);
expect(createEvent.kibana.space_id).to.be('default');

const findEvent = content.find((c) => c.event.action === 'saved_object_find');
// There are two 'saved_object_find' events in the log. One is by the fleet app for
// "epm - packages", the other is by the user for a dashboard (this is the one we are
// concerned with).
const findEvent = content.find(
(c) => c.event.action === 'saved_object_find' && c.kibana.saved_object.type === 'dashboard'
);
expect(findEvent).to.be.ok();
expect(findEvent.trace.id).to.be.ok();
expect(findEvent.user.name).to.be(username);
Expand All @@ -65,7 +69,6 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(200);
await retry.waitFor('logs event in the dest file', async () => await logFile.isNotEmpty());

const content = await logFile.readJSON();

const loginEvent = content.find((c) => c.event.action === 'user_login');
Expand All @@ -90,7 +93,6 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(401);
await retry.waitFor('logs event in the dest file', async () => await logFile.isNotEmpty());

const content = await logFile.readJSON();

const loginEvent = content.find((c) => c.event.action === 'user_login');
Expand Down

0 comments on commit 03a2cd7

Please sign in to comment.