Skip to content

Commit

Permalink
more pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
animehart committed Jun 29, 2023
1 parent 45567c4 commit 05f554e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import type { SuperTest, Test } from 'supertest';
import { Client } from '@elastic/elasticsearch';
import { SecurityService } from '../../../../../test/common/services/security/security';
import type { IndexDetails } from '../../../../../x-pack/plugins/cloud_security_posture/common/types';
import expect from '@kbn/expect/expect';

export const deleteIndex = (es: Client, indexToBeDeleted: string[]) => {
Promise.all([
Expand Down Expand Up @@ -141,3 +143,8 @@ export const deleteRole = async (security: SecurityService, roleName: string) =>
export const deleteUser = async (security: SecurityService, userName: string) => {
await security.user.delete(userName);
};

export const assertIndexStatus = (indicesDetails: IndexDetails[], indexName: string, expectedStatus: string) => {
const actualValue = indicesDetails.find((idx) => idx.index === indexName)?.status;
expect(actualValue).to.eql(expectedStatus, `expected ${indexName} to be ${expectedStatus} but got ${actualValue} instead`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
deleteRole,
deleteUser,
deleteIndex,
assertIndexStatus,
} from '../helper';

const UNPRIVILEGED_ROLE = 'unprivileged_test_role';
Expand Down Expand Up @@ -154,39 +155,13 @@ export default function (providerContext: FtrProviderContext) {
`expected unprivileged but got ${res.vuln_mgmt.status} instead`
);

expect(
res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status
).to.eql(
'empty',
`expected empty but got ${
res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status
).to.eql(
'empty',
`expected empty but got ${
res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status
).to.eql(
'unprivileged',
`expected unprivileged but got ${
res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS)
?.status
).to.eql(
'unprivileged',
`expected unprivileged but got ${
res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS)
?.status
} instead`
assertIndexStatus(res.indicesDetails, LATEST_FINDINGS_INDEX_DEFAULT_NS, 'empty');
assertIndexStatus(res.indicesDetails, FINDINGS_INDEX_PATTERN, 'empty');
assertIndexStatus(res.indicesDetails, BENCHMARK_SCORE_INDEX_DEFAULT_NS, 'unprivileged');
assertIndexStatus(
res.indicesDetails,
LATEST_VULNERABILITIES_INDEX_DEFAULT_NS,
'unprivileged'
);
});

Expand Down Expand Up @@ -223,39 +198,13 @@ export default function (providerContext: FtrProviderContext) {
`expected unprivileged but got ${res.vuln_mgmt.status} instead`
);

expect(
res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status
).to.eql(
'unprivileged',
`expected unprivileged but got ${
res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status
).to.eql(
'empty',
`expected empty but got ${
res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status
).to.eql(
'empty',
`expected empty but got ${
res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS)
?.status
).to.eql(
'unprivileged',
`expected unprivileged but got ${
res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS)
?.status
} instead`
assertIndexStatus(res.indicesDetails, LATEST_FINDINGS_INDEX_DEFAULT_NS, 'unprivileged');
assertIndexStatus(res.indicesDetails, FINDINGS_INDEX_PATTERN, 'empty');
assertIndexStatus(res.indicesDetails, BENCHMARK_SCORE_INDEX_DEFAULT_NS, 'empty');
assertIndexStatus(
res.indicesDetails,
LATEST_VULNERABILITIES_INDEX_DEFAULT_NS,
'unprivileged'
);
});

Expand Down Expand Up @@ -295,40 +244,10 @@ export default function (providerContext: FtrProviderContext) {
`expected not-installed but got ${res.vuln_mgmt.status} instead`
);

expect(
res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status
).to.eql(
'unprivileged',
`expected unprivileged but got ${
res.indicesDetails.find((idx) => idx.index === LATEST_FINDINGS_INDEX_DEFAULT_NS)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status
).to.eql(
'empty',
`expected empty but got ${
res.indicesDetails.find((idx) => idx.index === FINDINGS_INDEX_PATTERN)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status
).to.eql(
'unprivileged',
`expected unprivileged but got ${
res.indicesDetails.find((idx) => idx.index === BENCHMARK_SCORE_INDEX_DEFAULT_NS)?.status
} instead`
);
expect(
res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS)
?.status
).to.eql(
'empty',
`expected empty but got ${
res.indicesDetails.find((idx) => idx.index === LATEST_VULNERABILITIES_INDEX_DEFAULT_NS)
?.status
} instead`
);
assertIndexStatus(res.indicesDetails, LATEST_FINDINGS_INDEX_DEFAULT_NS, 'unprivileged');
assertIndexStatus(res.indicesDetails, FINDINGS_INDEX_PATTERN, 'empty');
assertIndexStatus(res.indicesDetails, BENCHMARK_SCORE_INDEX_DEFAULT_NS, 'unprivileged');
assertIndexStatus(res.indicesDetails, LATEST_VULNERABILITIES_INDEX_DEFAULT_NS, 'empty');
});
});
});
Expand Down

0 comments on commit 05f554e

Please sign in to comment.