diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-07-26 17:37:36 +0200 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-07-27 15:02:49 +0200 |
| commit | 4b3588feb2b7e260bf237b0f3944c90cdc47c3b5 (patch) | |
| tree | fa3a399983c0c8d8269a0cb217d45584c998fad4 | |
| parent | 2b3017974bc7cd4b3a74f83c956224cfe4e5a918 (diff) | |
[FIX] web: edited password fields should not contain '*'
Before this commit, when someone was editing a password, the stored
password may not be the expected one by the user.
Steps to reproduce:
1. Open "Outgoing Mail Servers" form.
2. Set a password (e.g. "yop").
3. Save, then edit.
4. Add "y" at the end of the password field.
> Expected value: "yopy"
> Actual value: "***y"
This is due to the use of the char field formatter, which displays passwords
by replacing the characters with '*'. It is not necessary to do this in edit
mode, because it uses an input field of type 'password'. The browser
automatically hides the value of such inputs.
Any changes on a input field in edit mode uses the value of the input, so the
value of an password input should contain the password, without '*'.
This commit fixes the issue by using the formatter in edit mode for the input
of type 'password'.
Task-ID 1869565
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 22 | ||||
| -rw-r--r-- | addons/web/static/tests/fields/basic_fields_tests.js | 28 | ||||
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 8 |
3 files changed, 46 insertions, 12 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index bd13305df0c..d4af202d39f 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -243,14 +243,20 @@ var InputField = DebouncedField.extend({ _prepareInput: function ($input) { this.$input = $input || $("<input/>"); this.$input.addClass('o_input'); - this.$input.attr({ - type: this.nodeOptions.isPassword ? 'password' : 'text', - placeholder: this.attrs.placeholder || "", - autocomplete: this.nodeOptions.isPassword ? - 'new-password' : - this.attrs.autocomplete, - }); - this.$input.val(this._formatValue(this.value)); + + var inputAttrs = { placeholder: this.attrs.placeholder || "" }; + var inputVal; + if (this.nodeOptions.isPassword) { + inputAttrs = _.extend(inputAttrs, { type: 'password', autocomplete: 'new-password' }); + inputVal = this.value; + } else { + inputAttrs = _.extend(inputAttrs, { type: 'text', autocomplete: this.attrs.autocomplete }); + inputVal = this._formatValue(this.value); + } + + this.$input.attr(inputAttrs); + this.$input.val(inputVal); + return this.$input; }, /** diff --git a/addons/web/static/tests/fields/basic_fields_tests.js b/addons/web/static/tests/fields/basic_fields_tests.js index 443fb194d87..9ed633ad4c2 100644 --- a/addons/web/static/tests/fields/basic_fields_tests.js +++ b/addons/web/static/tests/fields/basic_fields_tests.js @@ -1183,6 +1183,34 @@ QUnit.module('basic_fields', { form.destroy(); }); + QUnit.test('input field: change password value', function (assert) { + assert.expect(4); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '<form>' + + '<field name="foo" password="True"/>' + + '</form>', + res_id: 1, + }); + + assert.notOk(form.$('.o_field_char').text() === "yop", + "password field value should not be visible in read mode"); + assert.strictEqual(form.$('.o_field_char').text(), "***", + "password field value should be hidden with '*' in read mode"); + + form.$buttons.find('.o_form_button_edit').click(); + + assert.strictEqual(form.$('input.o_field_char').attr('type'), 'password', + "password field input should be with type 'password' in edit mode"); + assert.strictEqual(form.$('input.o_field_char').val(), 'yop', + "password field input value should be the (non-hidden) password value"); + + form.destroy(); + }); + QUnit.module('UrlWidget'); QUnit.test('url widget in form view', function (assert) { diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 1c817e0bfeb..9d4f6a0e9ad 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -6046,8 +6046,8 @@ QUnit.module('Views', { assert.strictEqual(form.$('span[name="foo"]').text(), '***', "password should be displayed with stars"); form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[name="foo"]').val(), '***', - "password should be displayed with stars"); + assert.strictEqual(form.$('input[name="foo"]').val(), 'yop', + "input value should be the password"); assert.strictEqual(form.$('input[name="foo"]').prop('type'), 'password', "input should be of type password"); form.destroy(); @@ -6068,8 +6068,8 @@ QUnit.module('Views', { }); form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[name="foo"]').val(), '***', - "password should be displayed with stars"); + assert.strictEqual(form.$('input[name="foo"]').prop('type'), 'password', + "input should be of type password"); assert.strictEqual(form.$('input[name="display_name"]').attr('autocomplete'), 'coucou', "attribute autocomplete should be set"); assert.strictEqual(form.$('input[name="foo"]').attr('autocomplete'), 'new-password', |
