1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/*!
* Matomo - free/libre analytics platform
*
* UsersManager screenshot tests.
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
describe('UsersManager_AnonymousUser', function () {
this.fixture = "Piwik\\Plugins\\UsersManager\\tests\\Fixtures\\AnonymousUser";
const url = "?module=UsersManager&action=index";
function getUserAccess(userName) {
return page.evaluate(
(userName) => {
return $(`#manageUsersTable #userLogin:contains(${userName}) + .access-cell li[role="option"][aria-selected="true"]`)
.text()
.trim()
},
userName
);
}
async function abortPasswordConfirmation() {
await page.$('.confirm-password-modal.open', { visible: true });
await page.waitForTimeout(300);
await (await page.jQuery('.confirm-password-modal.open .modal-close.modal-no:visible')).click();
await page.$('.confirm-password-modal.open', { hidden: true });
await page.waitForTimeout(300);
}
async function confirmPassword() {
await page.$('.confirm-password-modal.open', { visible: true });
await page.waitForTimeout(300);
await page.evaluate((superUserPassword) => {
$('.confirm-password-modal input[name=currentUserPassword]:visible')
.val(superUserPassword)
.change();
}, superUserPassword);
await page.waitForTimeout(250);
await (await page.jQuery('.confirm-password-modal.open .modal-close:not(.modal-no):visible')).click();
await page.$('.confirm-password-modal.open', { hidden: true });
await page.waitForTimeout(300);
await page.waitForNetworkIdle();
}
async function confirmRoleChange() {
await page.$('.change-user-role-confirm-modal.open', { visible: true });
await page.waitForTimeout(300);
await (await page.jQuery('.change-user-role-confirm-modal.open .modal-close:not(.modal-no):visible')).click();
await page.$('.change-user-role-confirm-modal.open', { hidden: true });
await page.waitForTimeout(300);
await page.waitForNetworkIdle();
}
it('should start with a known list of users', async function () {
await page.goto(url);
await page.waitForNetworkIdle();
expect(await getUserAccess('anonymous')).to.equal('No access');
expect(await getUserAccess('regularUser')).to.equal('No access');
});
describe('single user handling', function () {
async function setUserAccess(userName, accessString) {
await page.evaluate(
(userName, accessString) => {
$(`#manageUsersTable #userLogin:contains(${userName}) + .access-cell select`)
.val(accessString)
.change();
},
userName, accessString
)
}
it('should reset selected access if confirmation is aborted', async function () {
await setUserAccess('anonymous', 'string:view');
await abortPasswordConfirmation();
expect(await getUserAccess('anonymous')).to.equal('No access');
});
it('should show a password confirmation when giving access to anonymous user', async function () {
await setUserAccess('anonymous', 'string:view');
await confirmPassword();
expect(await getUserAccess('anonymous')).to.equal('View');
});
it('should not show a password confirmation when revoking access for anonymous user', async function () {
await setUserAccess('anonymous', 'string:noaccess');
await confirmRoleChange();
expect(await getUserAccess('anonymous')).to.equal('No access');
});
});
describe('bulk user handling', function() {
async function bulkRemovePermissions() {
await page.click('.bulk-actions.btn');
await page.waitForTimeout(350);
await (await page.jQuery('#user-list-bulk-actions a:contains(Remove Permissions)')).click();
await page.waitForTimeout(350);
}
async function bulkSelectAll() {
await page.click('th.select-cell input + span');
}
async function bulkSetViewAccess() {
await page.click('.bulk-actions.btn');
await page.waitForTimeout(350);
await (await page.jQuery('a[data-target=bulk-set-access]')).hover();
await page.waitForTimeout(350);
await (await page.jQuery('#bulk-set-access a:contains(View)')).click();
await page.waitForTimeout(350);
}
it('should reset selected access if confirmation is aborted', async function () {
await bulkSelectAll();
await bulkSetViewAccess();
await abortPasswordConfirmation();
expect(await getUserAccess('anonymous')).to.equal('No access');
expect(await getUserAccess('regularUser')).to.equal('No access');
});
it('should show a password confirmation giving access to multiple users including anonymous', async function () {
// all users already selected from previous test
await bulkSetViewAccess();
await confirmPassword();
expect(await getUserAccess('anonymous')).to.equal('View');
expect(await getUserAccess('regularUser')).to.equal('View');
});
it('should not show a password confirmation when revoking access for multiple users including anonymous', async function () {
await bulkSelectAll();
await bulkRemovePermissions();
await confirmRoleChange();
expect(await getUserAccess('anonymous')).to.equal('No access');
expect(await getUserAccess('regularUser')).to.equal('No access');
});
});
});
|