Files
odoo_source/addons/auth_totp/static/tests/totp_flow.js
T
b63ee52552 [FIX] *: remove scss 'extend' from dropdown components
This commit removes all the 'extend' initially introduced to avoid code
repetition and ensure visual consistency across Bootstrap and Owl dropdowns.

Despite achieving the desired results, using 'extend' in this context
was seriously impacting the bundle generation time, probably due to an
underestimated amount of Apps' legacy-code applied on these elements.

In order to achieve the same results, the chosen strategy is to add
Bootstrap default classes directly into Owl dropdowns.
Also, it moves code related to bootstrap dropdown in 'webclient.scss',
leaving 'core/dropdown/dropdown.scss' for Owl code only.

Due to the discrepancies between Bootstrap and Owl html
structure, the '.dropdown-item' class could not have been added
directly to Owl's '.o_dropdown_item' itself, without refactoring
the Dropdown component structure.

// ==== Bootstrap 4.6 default Structure ================================
<div class="dropdown-menu">
  <button class="dropdown-item" type="button">Action</button>
  <a class="dropdown-item" href="#">Another action</a>
</div>

// ==== OWL default Structure before this commit =======================
<ul class="o_dropdown_menu">
  <li class="o_dropdown_item">
     <span>Action</span>
  </li>
  <li class="o_dropdown_item">
     <a href="#">Another action</a>
  </li>
</ul>

// ==== OWL Structure after this commit ================================
<div class="o-dropdown--menu dropdown-menu">
  <span class="dropdown-item">Action</span>
  <a class="dropdown-item" href="#">Another action</a>
</div>

// ==== web.assets_backend.css Bundle Generation Comparison ============
With all modules installed (enterprise edition over runbot):
Before this commit, bundle took ~2.5s and ~4s to generate and weighted ~322kB (~2.5MB uncompressed)
After this commit, it takes between ~1.2s and ~1.6s and weights ~257kB (~1.6MB uncompressed)

closes odoo/odoo#77649

X-original-commit: 84715436d87bb05b421bc9ccaacda67d07571690
Related: odoo/enterprise#21370
Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
Co-authored-by: Stefano Rigano <sri@odoo.com>
Co-authored-by: François Georis <fge@odoo.com>
Co-authored-by: Bruno Boi <boi@odoo.com>
2021-10-04 07:57:00 +00:00

309 lines
9.4 KiB
JavaScript

odoo.define('auth_totp.tours', function(require) {
"use strict";
const tour = require('web_tour.tour');
const ajax = require('web.ajax');
function openRoot() {
return [{
content: "return to client root to avoid race condition",
trigger: 'body',
run() {
$('body').addClass('wait');
window.location = '/web';
}
}, {
content: "wait for client reload",
trigger: 'body:not(.wait)',
run() {}
}];
}
function openUserProfileAtSecurityTab() {
return [{
content: 'Open user account menu',
trigger: '.o_user_menu .oe_topbar_name',
run: 'click',
}, {
content: "Open preferences / profile screen",
trigger: '[data-menu=settings]',
run: 'click',
}, {
content: "Switch to security tab",
trigger: 'a[role=tab]:contains("Account Security")',
run: 'click',
}];
}
tour.register('totp_tour_setup', {
test: true,
url: '/web'
}, [...openUserProfileAtSecurityTab(), {
content: "Open totp wizard",
trigger: 'button[name=action_totp_enable_wizard]',
}, {
content: "Check that we have to enter enhanced security mode",
trigger: 'div:contains("enter your password")',
run: () => {},
}, {
content: "Input password",
trigger: '[name=password]',
run: 'text demo', // FIXME: better way to do this?
}, {
content: "Confirm",
trigger: "button:contains(Confirm Password)",
}, {
content: "Check the wizard has opened",
trigger: 'li:contains("When requested to do so")',
run: () => {}
}, {
content: "Get secret from collapsed div",
trigger: 'a:contains("Cannot scan it?")',
run(helpers) {
const $secret = this.$anchor.closest('div').find('span[name=secret]');
const $copyBtn = $secret.find('button');
$copyBtn.remove();
const secret = $secret.text();
ajax.jsonRpc('/totphook', 'call', {
secret
}).then((token) => {
helpers._text(helpers._get_action_values('input[name=code]'), token);
helpers._click(helpers._get_action_values('button.btn-primary:contains(Activate)'));
$('body').addClass('got-token')
});
}
}, {
content: 'wait for rpc',
trigger: 'body.got-token',
run() {}
},
...openRoot(),
...openUserProfileAtSecurityTab(),
{
content: "Check that the button has changed",
trigger: 'button[name=action_totp_disable]',
run: () => {}
}]);
tour.register('totp_login_enabled', {
test: true,
url: '/'
}, [{
content: "check that we're on the login page or go to it",
trigger: 'input#login, a:contains(Sign in)'
}, {
content: "input login",
trigger: 'input#login',
run: 'text demo',
}, {
content: 'input password',
trigger: 'input#password',
run: 'text demo',
}, {
content: "click da button",
trigger: 'button:contains("Log in")',
}, {
content: "expect totp screen",
trigger: 'label:contains(Authentication Code)',
}, {
content: "input code",
trigger: 'input[name=totp_token]',
run(helpers) {
ajax.jsonRpc('/totphook', 'call', {}).then((token) => {
helpers._text(helpers._get_action_values(), token);
// FIXME: is there a way to put the button as its own step trigger without
// the tour straight blowing through and not waiting for this?
helpers._click(helpers._get_action_values('button:contains("Login")'));
});
}
}, {
content: "check we're logged in",
trigger: ".o_user_menu .oe_topbar_name",
run: () => {}
}]);
tour.register('totp_login_device', {
test: true,
url: '/'
}, [{
content: "check that we're on the login page or go to it",
trigger: 'input#login, a:contains(Sign in)'
}, {
content: "input login",
trigger: 'input#login',
run: 'text demo',
}, {
content: 'input password',
trigger: 'input#password',
run: 'text demo',
}, {
content: "click da button",
trigger: 'button:contains("Log in")',
}, {
content: "expect totp screen",
trigger: 'label:contains(Authentication Code)',
}, {
content: "check remember device box",
trigger: 'label[for=switch-remember]',
}, {
content: "input code",
trigger: 'input[name=totp_token]',
run(helpers) {
ajax.jsonRpc('/totphook', 'call', {}).then((token) => {
helpers._text(helpers._get_action_values(), token);
// FIXME: is there a way to put the button as its own step trigger without
// the tour straight blowing through and not waiting for this?
helpers._click(helpers._get_action_values('button:contains("Login")'));
});
}
}, {
content: "check we're logged in",
trigger: ".o_user_menu .oe_topbar_name",
run: 'click',
}, {
content: "click the Log out button",
trigger: '.dropdown-item[data-menu=logout]',
}, {
content: "check that we're back on the login page or go to it",
trigger: 'input#login, a:contains(Log in)'
}, {
content: "input login again",
trigger: 'input#login',
run: 'text demo',
}, {
content: 'input password again',
trigger: 'input#password',
run: 'text demo',
}, {
content: "click da button again",
trigger: 'button:contains("Log in")',
}, {
content: "check we're logged in without 2FA",
trigger: ".o_user_menu .oe_topbar_name",
run: () => {}
},
// now go and disable two-factor authentication would be annoying to do in a separate tour
// because we'd need to login & totp again as HttpCase.authenticate can't
// succeed w/ totp enabled
...openUserProfileAtSecurityTab(),
{
content: "Open totp wizard",
trigger: 'button[name=action_totp_disable]',
}, {
content: "Check that we have to enter enhanced security mode",
trigger: 'div:contains("enter your password")',
run: () => {},
}, {
content: "Input password",
trigger: '[name=password]',
run: 'text demo', // FIXME: better way to do this?
}, {
content: "Confirm",
trigger: "button:contains(Confirm Password)",
},
...openRoot(),
...openUserProfileAtSecurityTab(),
{
content: "Check that the button has changed",
trigger: 'button[name=action_totp_enable_wizard]',
run: () => {}
}]);
tour.register('totp_login_disabled', {
test: true,
url: '/'
}, [{
content: "check that we're on the login page or go to it",
trigger: 'input#login, a:contains(Sign in)'
}, {
content: "input login",
trigger: 'input#login',
run: 'text demo',
}, {
content: 'input password',
trigger: 'input#password',
run: 'text demo',
}, {
content: "click da button",
trigger: 'button:contains("Log in")',
},
// normally we'd end the tour here as it's all we care about but there are a
// bunch of ongoing queries from the loading of the web client which cause
// issues, so go and open the preferences / profile screen to make sure
// everything settles down
...openUserProfileAtSecurityTab(),
]);
const columns = {};
tour.register('totp_admin_disables', {
test: true,
url: '/web'
}, [tour.stepUtils.showAppsMenuItem(), {
content: 'Go to settings',
trigger: '[data-menu-xmlid="base.menu_administration"]'
}, {
content: 'Wait for page',
trigger: '.o_menu_brand:contains("Settings")',
run: () => {}
}, {
content: "Open Users menu",
trigger: '[data-menu-xmlid="base.menu_users"]'
}, {
content: "Open Users view",
trigger: '[data-menu-xmlid="base.menu_action_res_users"]',
run: function (helpers) {
// funny story: the users view we're trying to reach, sometimes we're
// already there, but if we re-click the next step executes before the
// action has the time to re-load, the one after that doesn't, and our
// selection get discarded by the action reloading, so here try to
// see if we're already on the users action through the breadcrumb and
// just close the menu if so
const $crumb = $('.breadcrumb');
if ($crumb.text().indexOf('Users') === -1) {
// on general settings page, click menu
helpers.click();
} else {
// else close menu
helpers.click($('[data-menu-xmlid="base.menu_users"]'));
}
}
}, {
content: "Find Demo User",
trigger: 'td.o_data_cell:contains("demo")',
run: function (helpers) {
const $titles = this.$anchor.closest('table').find('tr:first th');
for (let i=0; i<$titles.length; ++i) {
columns[$titles[i].getAttribute('data-name')] = i;
}
const $row = this.$anchor.closest('tr');
const sel = $row.find('.o_list_record_selector input[type=checkbox]');
helpers.click(sel);
}
}, {
content: "Open Actions menu",
trigger: 'button.dropdown-toggle:contains("Action")'
}, {
content: "Select totp remover",
trigger: 'a.dropdown-item:contains(Disable two-factor authentication)'
}, { // enhanced security yo
content: "Check that we have to enter enhanced security mode",
trigger: 'div:contains("enter your password")',
run: () => {},
}, {
content: "Input password",
trigger: '[name=password]',
run: 'text admin', // FIXME: better way to do this?
}, {
content: "Confirm",
trigger: "button:contains(Confirm Password)",
}, {
content: "open the user's form",
trigger: "td.o_data_cell:contains(demo)",
}, {
content: "go to Account security Tab",
trigger: "a.nav-link:contains(Account Security)",
}, {
content: "check that demo user has been de-totp'd",
trigger: "button[name=action_totp_enable_wizard]",
}])
});