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

FOUR-19778 Encrypted field does not have read-only mode #1765

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 7 additions & 5 deletions src/components/renderer/form-masked-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<input
v-else
v-model="localValue"
v-bind="componentConfig"
v-bind="componentConfigEncField"
v-uni-id="name"
:name="name"
class="form-control"
Expand Down Expand Up @@ -231,6 +231,7 @@ export default {
labelBtn: '',
errorEncryptedField: '',
concealExecuted: false,
componentConfigEncField: null,
};
},
computed: {
Expand Down Expand Up @@ -289,17 +290,18 @@ export default {
* "encrypted" attribute is enabled
*/
if (this.encryptedConfig?.encrypted) {
this.componentConfigEncField = JSON.parse(JSON.stringify(this.componentConfig));
if (uuidValidate(this.localValue)) {
this.inputType = "password";
this.iconBtn = "fas fa-eye";
this.labelBtn = this.$t("Reveal");
this.concealExecuted = true;
this.componentConfig.readonly = true;
this.componentConfigEncField.readonly = true;
} else {
this.inputType = "text";
this.iconBtn = "fas fa-eye-slash";
this.labelBtn = this.$t("Conceal");
this.componentConfig.readonly = false;
this.componentConfigEncField.readonly = this.componentConfig.readonly;
}
} else {
this.inputType = this.dataType;
Expand Down Expand Up @@ -381,7 +383,7 @@ export default {
this.iconBtn = "fas fa-eye";
this.labelBtn = this.$t("Reveal");
this.concealExecuted = true;
this.componentConfig.readonly = true;
this.componentConfigEncField.readonly = true;
this.errorEncryptedField = "";

// Assign uuid from encrypted data
Expand All @@ -392,7 +394,7 @@ export default {
this.inputType = this.dataType;
this.iconBtn = "fas fa-eye-slash";
this.labelBtn = this.$t("Conceal");
this.componentConfig.readonly = false;
this.componentConfigEncField.readonly = this.componentConfig.readonly;

// Assign value decrypted
this.localValue = decryptedValue;
Expand Down
42 changes: 41 additions & 1 deletion tests/e2e/specs/EncryptedField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,44 @@ describe("Encrypted Field", () => {
// After conceal the value should be the same
cy.get("[data-cy=preview-content] [name=form_input_1]").should("have.value", secretValue);
});
});

it("Encrypted field in preview with 'readonly' property enabled", () => {
visitAndOpenAcordeon();
dragFormInput();
// Enable "readonly" mode
cy.get("[data-cy=inspector-readonly]").click();
cy.get("[data-cy=accordion-Advanced]").click();
// Enable encrypted
cy.get("[data-cy=inspector-encryptedConfig]")
.children()
.children(".custom-control")
.each((control) => {
// forced click over the control
control.children("input").trigger("click");
});
// Display available users/groups
cy.get('[data-cy="inspector-encryptedConfig"] .multiselect').click();
// Select a group
cy.get('[data-cy="inspector-encryptedConfig"] #option-2-4').click();
// Go to preview mode
enterPreviewMode();
// Set initial data
cy.setPreviewDataInput('{"form_input_1":"Other value"}');
// Click in "Conceal" with data
cy.get('[data-cy=preview-content] [name=form_input_1]').siblings('button').click();
// After conceal should be keep the "readonly" mode
cy.get("[data-cy=preview-content] [name=form_input_1]").should("have.attr", "readonly");
// After conceal the value should be different
cy.get("[data-cy=preview-content] [name=form_input_1]").should("have.not.value", secretValue);
// The value in data should be the uuid returned
cy.assertPreviewData({
form_input_1: uuid,
});
// Click in "Reveal"
cy.get('[data-cy=preview-content] [name=form_input_1]').siblings('button').click();
// After conceal should be keep the "readonly" mode
cy.get("[data-cy=preview-content] [name=form_input_1]").should("have.attr", "readonly");
// After conceal the value should be the same
cy.get("[data-cy=preview-content] [name=form_input_1]").should("have.value", secretValue);
});
});
Loading