Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[functional/security/test-user] use options object #126652

Merged
merged 2 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions test/common/services/security/test_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,33 @@ export class TestUser extends FtrService {
super(ctx);
}

async restoreDefaults(shouldRefreshBrowser: boolean = true) {
if (this.enabled) {
await this.setRoles(this.config.get('security.defaultRoles'), shouldRefreshBrowser);
async restoreDefaults(options?: { skipBrowserRefresh?: boolean }) {
if (!this.enabled) {
return;
}

await this.setRoles(this.config.get('security.defaultRoles'), options);
}

async setRoles(roles: string[], shouldRefreshBrowser: boolean = true) {
if (this.enabled) {
this.log.debug(`set roles = ${roles}`);
await this.user.create(TEST_USER_NAME, {
password: TEST_USER_PASSWORD,
roles,
full_name: 'test user',
});

if (this.browser && this.testSubjects && shouldRefreshBrowser) {
if (await this.testSubjects.exists('kibanaChrome', { allowHidden: true })) {
await this.browser.refresh();
// accept alert if it pops up
const alert = await this.browser.getAlert();
await alert?.accept();
await this.testSubjects.find('kibanaChrome', this.config.get('timeouts.find') * 10);
}
async setRoles(roles: string[], options?: { skipBrowserRefresh?: boolean }) {
if (!this.enabled) {
return;
}

this.log.debug(`set roles = ${roles}`);
await this.user.create(TEST_USER_NAME, {
password: TEST_USER_PASSWORD,
roles,
full_name: 'test user',
});

if (this.browser && this.testSubjects && !options?.skipBrowserRefresh) {
if (await this.testSubjects.exists('kibanaChrome', { allowHidden: true })) {
await this.browser.refresh();
// accept alert if it pops up
const alert = await this.browser.getAlert();
await alert?.accept();
await this.testSubjects.find('kibanaChrome', this.config.get('timeouts.find') * 10);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/functional/apps/discover/_huge_fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('test large number of fields in sidebar', function () {
before(async function () {
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/huge_fields');
await security.testUser.setRoles(['kibana_admin', 'test_testhuge_reader'], false);
await security.testUser.setRoles(['kibana_admin', 'test_testhuge_reader'], {
skipBrowserRefresh: true,
});
await kibanaServer.uiSettings.update({
'timepicker:timeDefaults': `{ "from": "2016-10-05T00:00:00", "to": "2016-10-06T00:00:00"}`,
});
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_tsvb_chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
beforeEach(async () => {
await security.testUser.setRoles(
['kibana_admin', 'test_logstash_reader', 'kibana_sample_admin'],
false
{ skipBrowserRefresh: true }
);
await visualize.navigateToNewVisualization();
await visualize.clickVisualBuilder();
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/accessibility/apps/security_solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// FLAKY: https://github.com/elastic/kibana/issues/95707
describe.skip('Security Solution', () => {
before(async () => {
await security.testUser.setRoles(['superuser'], false);
await security.testUser.setRoles(['superuser'], { skipBrowserRefresh: true });
await common.navigateToApp('security');
});

after(async () => {
await security.testUser.restoreDefaults(false);
await security.testUser.restoreDefaults({ skipBrowserRefresh: true });
});

describe('Detections', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -41,7 +41,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global dashboard read with manage_security', () => {
before(async () => {
await security.testUser.setRoles(['global_dashboard_read', 'manage_security'], true);
await security.testUser.setRoles(['global_dashboard_read', 'manage_security']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -47,7 +47,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global dashboard read with ccr_user', () => {
before(async () => {
await security.testUser.setRoles(['global_dashboard_read', 'ccr_user'], true);
await security.testUser.setRoles(['global_dashboard_read', 'ccr_user']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -47,7 +47,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global dashboard read with manage_ilm', () => {
before(async () => {
await security.testUser.setRoles(['global_dashboard_read', 'manage_ilm'], true);
await security.testUser.setRoles(['global_dashboard_read', 'manage_ilm']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

describe('Home page', function () {
before(async () => {
await security.testUser.setRoles(['manage_ilm'], true);
await security.testUser.setRoles(['manage_ilm']);
const isCloud = await deployment.isCloud();
if (!isCloud) {
await esClient.snapshot.createRepository({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -47,7 +47,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global dashboard read with index_management_user', () => {
before(async () => {
await security.testUser.setRoles(['global_dashboard_read', 'index_management_user'], true);
await security.testUser.setRoles(['global_dashboard_read', 'index_management_user']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -47,7 +47,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global dashboard read with ingest_pipelines_user', () => {
before(async () => {
await security.testUser.setRoles(['global_dashboard_read', 'ingest_pipelines_user'], true);
await security.testUser.setRoles(['global_dashboard_read', 'ingest_pipelines_user']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
11 changes: 6 additions & 5 deletions x-pack/test/functional/apps/lens/add_to_dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('dashboard no-access privileges', () => {
before(async () => {
await PageObjects.common.navigateToApp('visualize');
await security.testUser.setRoles(['test_logstash_reader', 'global_visualize_all'], true);
await security.testUser.setRoles(['test_logstash_reader', 'global_visualize_all']);
});

after(async () => {
Expand Down Expand Up @@ -317,10 +317,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

describe('dashboard read-only privileges', () => {
before(async () => {
await security.testUser.setRoles(
['test_logstash_reader', 'global_visualize_all', 'global_dashboard_read'],
true
);
await security.testUser.setRoles([
'test_logstash_reader',
'global_visualize_all',
'global_dashboard_read',
]);
});

after(async () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/lens/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'test_logstash_reader',
'global_visualize_all',
],
false
{ skipBrowserRefresh: true }
);
});
after(async () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/lens/error_handling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async () => {
await security.testUser.setRoles(
['global_discover_read', 'global_visualize_read', 'test_logstash_reader'],
false
{ skipBrowserRefresh: true }
);
// loading an object without reference fails, so we load data view + lens object and then unload data view
await kibanaServer.importExport.load(
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/lens/lens_reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'global_dashboard_read',
'reporting_user', // NOTE: the built-in role granting full reporting access is deprecated. See xpack.reporting.roles.enabled
],
false
{ skipBrowserRefresh: true }
);
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/lens/persistent_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async () => {
await security.testUser.setRoles(
['global_discover_read', 'global_visualize_read', 'test_logstash_reader'],
false
{ skipBrowserRefresh: true }
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -47,10 +47,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global dashboard read with license_management_user', () => {
before(async () => {
await security.testUser.setRoles(
['global_dashboard_read', 'license_management_user'],
true
);
await security.testUser.setRoles(['global_dashboard_read', 'license_management_user']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -47,7 +47,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global dashboard read with logstash_read_user', () => {
before(async () => {
await security.testUser.setRoles(['global_dashboard_read', 'logstash_read_user'], true);
await security.testUser.setRoles(['global_dashboard_read', 'logstash_read_user']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('no management privileges', () => {
before(async () => {
await security.testUser.setRoles(['global_dashboard_read'], true);
await security.testUser.setRoles(['global_dashboard_read']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand All @@ -47,7 +47,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('global all privileges (aka kibana_admin)', () => {
before(async () => {
await security.testUser.setRoles(['kibana_admin'], true);
await security.testUser.setRoles(['kibana_admin']);
});
after(async () => {
await security.testUser.restoreDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export default function ({ getPageObjects, getService }) {

describe('docvalue_fields', () => {
before(async () => {
await security.testUser.setRoles(['global_maps_read', 'test_logstash_reader'], false);
await security.testUser.setRoles(['global_maps_read', 'test_logstash_reader'], {
skipBrowserRefresh: true,
});
});

after(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function ({ getPageObjects, getService }) {
'antimeridian_points_reader',
'antimeridian_shapes_reader',
],
false
{ skipBrowserRefresh: true }
);
await PageObjects.maps.loadSavedMap('document example');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default function ({ getPageObjects, getService }) {
describe('geo top hits', () => {
describe('split on string field', () => {
before(async () => {
await security.testUser.setRoles(['global_maps_all', 'test_logstash_reader'], false);
await security.testUser.setRoles(['global_maps_all', 'test_logstash_reader'], {
skipBrowserRefresh: true,
});
await PageObjects.maps.loadSavedMap('document example top hits');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ({ getPageObjects, getService }) {
'global_dashboard_all',
'meta_for_geoshape_data_reader',
],
false
{ skipBrowserRefresh: true }
);
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/maps/embeddable/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function ({ getPageObjects, getService }) {
'meta_for_geoshape_data_reader',
'global_dashboard_read',
],
false
{ skipBrowserRefresh: true }
);
await kibanaServer.uiSettings.replace({
defaultIndex: 'c698b940-e149-11e8-a35a-370a8516603a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ({ getPageObjects, getService }) {
'global_dashboard_all',
'meta_for_geoshape_data_reader',
],
false
{ skipBrowserRefresh: true }
);
await kibanaServer.uiSettings.replace({
defaultIndex: 'c698b940-e149-11e8-a35a-370a8516603a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ({ getPageObjects, getService }) {
before(async () => {
await security.testUser.setRoles(
['test_logstash_reader', 'global_maps_all', 'global_dashboard_all'],
false
{ skipBrowserRefresh: true }
);
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.gotoDashboardEditMode('filter by map extent dashboard');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function ({ getPageObjects, getService }) {
'global_dashboard_all',
'meta_for_geoshape_data_reader',
],
false
{ skipBrowserRefresh: true }
);
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/maps/es_geo_grid_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function ({ getPageObjects, getService }) {
before(async () => {
await security.testUser.setRoles(
['global_maps_all', 'test_logstash_reader', 'geoshape_data_reader'],
false
{ skipBrowserRefresh: true }
);
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/maps/joins.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ({ getPageObjects, getService }) {
before(async () => {
await security.testUser.setRoles(
['global_maps_all', 'geoshape_data_reader', 'meta_for_geoshape_data_reader'],
false
{ skipBrowserRefresh: true }
);
await PageObjects.maps.loadSavedMap('join example');
});
Expand Down
Loading