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

Rbac phase1 functional UI tests #20949

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ <h1 class="kuiTitle">
ng-checked="includes(role.elasticsearch.cluster, privilege)"
ng-click="toggle(role.elasticsearch.cluster, privilege)"
ng-disabled="role.metadata._reserved || !isRoleEnabled(role)"
data-test-subj="clusterPrivileges-{{privilege}}"
/>
<span class="kuiOptionLabel">{{privilege}}</span>
</label>
Expand All @@ -123,6 +124,7 @@ <h1 class="kuiTitle">
type="checkbox"
ng-model="kibanaPrivilegesViewModel[key]"
ng-disabled="role.metadata._reserved || !isRoleEnabled(role)"
data-test-subj="kibanaPrivileges-{{key}}"
/>
<span class="kuiOptionLabel">{{key}}</span>
</label>
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional/apps/security/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default function ({ loadTestFile }) {
loadTestFile(require.resolve('./users'));
loadTestFile(require.resolve('./secure_roles_perm'));
loadTestFile(require.resolve('./field_level_security'));
loadTestFile(require.resolve('./rbac_phase1'));
});
}
124 changes: 124 additions & 0 deletions x-pack/test/functional/apps/security/rbac_phase1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from 'expect.js';
import { indexBy } from 'lodash';
export default function ({ getService, getPageObjects }) {

const PageObjects = getPageObjects(['security', 'settings', 'common', 'visualize', 'header']);
const log = getService('log');
const esArchiver = getService('esArchiver');
const remote = getService('remote');
const kibanaServer = getService('kibanaServer');

describe('rbac ', async function () {
before(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: generally we use a before for setup logic, but we're doing expect in here, it feels more like a test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, just wanted to make sure the before method did all the set up before the actual test kicked in. Would consider this as a part of set up logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer to @LeeDr on this one, I didn't see any expect calls in the other functional tests, which is what made me mention it here. The one downside is that the failure reasons when the test fail are going to be rather unclear if just the before fails as we have no context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kobelb I asked @rasroh to move the role and user creation code from tests (how she originally wrote it) to the before method because we already have other automated tests creating roles and users and didn't want these setup steps to count as additional passing tests when they would actually be duplicates. I realize we care more about getting the test coverage than the count of tests, but it just seemed more fair for it to be in the before method.
I think we should still get acceptable failure information if the expects in the before method fail vs having them in a test. There's debug logging before those expects including showing the list of users.
I asked @rasroh to change one of the expects in the before so it would fail. Seems like reasonable output;

       │ info  Saving page source to: /Users/rashmikulkarni/my_workspace/kibana/x-pack/test/functional/failure_debug/html/security app rbac  _before all_ hook.html
     └- ✖ fail: "security app rbac  "before all" hook"
     │       
     │         Error: expected [ 'rbac_all' ] to sort of equal [ '' ]
     │         + expected - actual
     │       
     │          [
     │         -  "rbac_all"
     │         +  ""
     │          ]
     │         
     │         at Assertion.assert (node_modules/expect.js/index.js:96:13)
     │         at Assertion.eql (node_modules/expect.js/index.js:230:10)
     │         at Context.before (test/functional/apps/security/rbac_phase1.js:54:41)
     │         at <anonymous>
     │       
     │       
       │
       │0 passing (52.1s)
       │1 failing

await remote.setWindowSize(1600, 1000);
log.debug('users');
await esArchiver.loadIfNeeded('logstash_functional');
log.debug('load kibana index with default index pattern');
await esArchiver.load('discover');
await kibanaServer.uiSettings.replace({ 'dateFormat:tz': 'UTC', 'defaultIndex': 'logstash-*' });
await PageObjects.settings.navigateTo();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we shouldn't need to navigate to the settings page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, without navigating to settings page, am unable to adding a role from the management page. I tried removing and it failed on me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, apologies.

await PageObjects.security.clickElasticsearchRoles();
await PageObjects.security.addRole('rbac_all', {
"kibana": ["all"],
"indices": [{
"names": [ "logstash-*" ],
"privileges": [ "read", "view_index_metadata" ]
}]
});

await PageObjects.security.clickElasticsearchRoles();
await PageObjects.security.addRole('rbac_read', {
"kibana": ["read"],
"indices": [{
"names": [ "logstash-*" ],
"privileges": [ "read", "view_index_metadata" ]
}]
});
await PageObjects.security.clickElasticsearchUsers();
log.debug('After Add user new: , userObj.userName');
await PageObjects.security.addUser({ username: 'kibanauser', password: 'changeme',
confirmPassword: 'changeme', fullname: 'kibanafirst kibanalast',
email: 'kibanauser@myEmail.com', save: true,
roles: ['rbac_all'] });
log.debug('After Add user: , userObj.userName');
const users = indexBy(await PageObjects.security.getElasticsearchUsers(), 'username');
log.debug('actualUsers = %j', users);
log.debug('roles: ', users.kibanauser.roles);
expect(users.kibanauser.roles).to.eql(['rbac_all']);
expect(users.kibanauser.fullname).to.eql('kibanafirst kibanalast');
expect(users.kibanauser.reserved).to.be(false);
await PageObjects.security.clickElasticsearchUsers();
log.debug('After Add user new: , userObj.userName');
await PageObjects.security.addUser({ username: 'kibanareadonly', password: 'changeme',
confirmPassword: 'changeme', fullname: 'kibanareadonlyFirst kibanareadonlyLast',
email: 'kibanareadonly@myEmail.com', save: true,
roles: ['rbac_read'] });
log.debug('After Add user: , userObj.userName');
const users1 = indexBy(await PageObjects.security.getElasticsearchUsers(), 'username');
const user = users1.kibanareadonly;
log.debug('actualUsers = %j', users1);
log.debug('roles: ', user.roles);
expect(user.roles).to.eql(['rbac_read']);
expect(user.fullname).to.eql('kibanareadonlyFirst kibanareadonlyLast');
expect(user.reserved).to.be(false);
await PageObjects.security.logout();
});


// this is to acertain that all role assigned to the user can perform actions like creating a Visualization
it('rbac all role can save a visualization', async function () {
const fromTime = '2015-09-19 06:31:44.000';
const toTime = '2015-09-23 18:31:44.000';
const vizName1 = 'Visualization VerticalBarChart';

log.debug('navigateToApp visualize');
await PageObjects.security.login('kibanauser', 'changeme');
await PageObjects.common.navigateToUrl('visualize', 'new');
log.debug('clickVerticalBarChart');
await PageObjects.visualize.clickVerticalBarChart();
await PageObjects.visualize.clickNewSearch();
log.debug('Set absolute time range from \"' + fromTime + '\" to \"' + toTime + '\"');
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.visualize.waitForVisualization();
const success = await PageObjects.visualize.saveVisualization(vizName1);
expect(success).to.be(true);
await PageObjects.security.logout();

});

it('rbac read only role can not save a visualization', async function () {
const fromTime = '2015-09-19 06:31:44.000';
const toTime = '2015-09-23 18:31:44.000';
const vizName1 = 'Viz VerticalBarChart';

log.debug('navigateToApp visualize');
await PageObjects.security.login('kibanareadonly', 'changeme');
await PageObjects.common.navigateToUrl('visualize', 'new');
log.debug('clickVerticalBarChart');
await PageObjects.visualize.clickVerticalBarChart();
await PageObjects.visualize.clickNewSearch();
log.debug('Set absolute time range from \"' + fromTime + '\" to \"' + toTime + '\"');
await PageObjects.header.setAbsoluteRange(fromTime, toTime);
await PageObjects.visualize.clickGo();
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.visualize.waitForVisualization();
const success = await PageObjects.visualize.saveVisualization(vizName1);
expect(success).to.be(false);
await PageObjects.security.logout();

});

after(async function () {
await PageObjects.security.logout();
});

});
}
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/security/secure_roles_perm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ({ getService, getPageObjects }) {



describe('security', function () {
describe('@security', function () {
before(async () => {
await remote.setWindowSize(1600, 1000);
log.debug('users');
Expand Down
25 changes: 25 additions & 0 deletions x-pack/test/functional/page_objects/security_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,31 @@ export function SecurityPageProvider({ getService, getPageObjects }) {
return testSubjects.setValue('queryInput0', userObj.indices[0].query);
}
})

//KibanaPriv
.then(function () {

function addKibanaPriv(priv) {

return priv.reduce(function (promise, privName) {
// We have to use non-test-subject selectors because this markup is generated by ui-select.
return promise

.then(function () {
log.debug('priv item = ' + privName);
remote.setFindTimeout(defaultFindTimeout)
.findByCssSelector(`[data-test-subj="kibanaPrivileges-${privName}"]`)
.click();
})
.then(function () {
return PageObjects.common.sleep(500);
});

}, Promise.resolve());
}
return userObj.kibana ? addKibanaPriv(userObj.kibana) : Promise.resolve();
})

.then(function () {

function addPriv(priv) {
Expand Down