Fix privileges flaky test because the order in arrays matters for equality (#58790)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Brandon Kobel 2020-02-28 08:58:24 -08:00 committed by GitHub
parent fd25ae6505
commit c5d17acab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,47 +3,71 @@
* or more contributor license agreements. Licensed under the Elastic License; * or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License. * you may not use this file except in compliance with the Elastic License.
*/ */
import util from 'util';
import { isEqual } from 'lodash';
import { FtrProviderContext } from '../../ftr_provider_context'; import { FtrProviderContext } from '../../ftr_provider_context';
export default function({ getService }: FtrProviderContext) { export default function({ getService }: FtrProviderContext) {
const supertest = getService('supertest'); const supertest = getService('supertest');
// FLAKY: https://github.com/elastic/kibana/issues/58785 describe('Privileges', () => {
describe.skip('Privileges', () => {
describe('GET /api/security/privileges', () => { describe('GET /api/security/privileges', () => {
it('should return a privilege map with all known privileges, without actions', async () => { it('should return a privilege map with all known privileges, without actions', async () => {
// If you're adding a privilege to the following, that's great!
// If you're removing a privilege, this breaks backwards compatibility
// Roles are associated with these privileges, and we shouldn't be removing them in a minor version.
const expected = {
features: {
discover: ['all', 'read'],
visualize: ['all', 'read'],
dashboard: ['all', 'read'],
dev_tools: ['all', 'read'],
advancedSettings: ['all', 'read'],
indexPatterns: ['all', 'read'],
savedObjectsManagement: ['all', 'read'],
timelion: ['all', 'read'],
graph: ['all', 'read'],
maps: ['all', 'read'],
canvas: ['all', 'read'],
infrastructure: ['all', 'read'],
logs: ['all', 'read'],
uptime: ['all', 'read'],
apm: ['all', 'read'],
siem: ['all', 'read'],
endpoint: ['all', 'read'],
},
global: ['all', 'read'],
space: ['all', 'read'],
reserved: ['ml', 'monitoring'],
};
await supertest await supertest
.get('/api/security/privileges') .get('/api/security/privileges')
.set('kbn-xsrf', 'xxx') .set('kbn-xsrf', 'xxx')
.send() .send()
.expect(200, { .expect(200)
// If you're adding a privilege to the following, that's great! .expect((res: any) => {
// If you're removing a privilege, this breaks backwards compatibility // when comparing privileges, the order of the privileges doesn't matter.
// Roles are associated with these privileges, and we shouldn't be removing them in a minor version. // supertest uses assert.deepStrictEqual.
features: { // expect.js doesn't help us here.
discover: ['all', 'read'], // and lodash's isEqual doesn't know how to compare Sets.
visualize: ['all', 'read'], const success = isEqual(res.body, expected, (value, other, key) => {
dashboard: ['all', 'read'], if (Array.isArray(value) && Array.isArray(other)) {
dev_tools: ['all', 'read'], return isEqual(value.sort(), other.sort());
advancedSettings: ['all', 'read'], }
indexPatterns: ['all', 'read'],
savedObjectsManagement: ['all', 'read'], // Lodash types aren't correct, `undefined` should be supported as a return value here and it
timelion: ['all', 'read'], // has special meaning.
graph: ['all', 'read'], return undefined as any;
maps: ['all', 'read'], });
canvas: ['all', 'read'],
infrastructure: ['all', 'read'], if (!success) {
logs: ['all', 'read'], throw new Error(
uptime: ['all', 'read'], `Expected ${util.inspect(res.body)} to equal ${util.inspect(expected)}`
apm: ['all', 'read'], );
siem: ['all', 'read'], }
endpoint: ['all', 'read'], })
}, .expect(200);
global: ['all', 'read'],
space: ['all', 'read'],
reserved: ['monitoring', 'ml'],
});
}); });
}); });
}); });