Skip to content

Commit

Permalink
Don't expose the value of a model's attribute in assertions (#7370)
Browse files Browse the repository at this point in the history
* don't expose the value of a model's attribute in production builds
  • Loading branch information
amk221 authored and igorT committed Dec 1, 2020
1 parent 2152af2 commit da4fb93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
21 changes: 18 additions & 3 deletions packages/-ember-data/tests/unit/model-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { computed, get, observer, set } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import { settled } from '@ember/test-helpers';
import { DEBUG } from '@glimmer/env';

import { module, test } from 'qunit';
import { reject, resolve } from 'rsvp';
Expand Down Expand Up @@ -141,9 +142,23 @@ module('unit/model - Model', function(hooks) {
'the deleted person is not removed from store (no unload called)'
);

assert.expectAssertion(() => {
set(record, 'isArchived', true);
}, /Attempted to set 'isArchived' to 'true' on the deleted record <person:1>/);
if (DEBUG) {
assert.throws(
() => {
set(record, 'isArchived', true);
},
/Attempted to set 'isArchived' to 'true' on the deleted record <person:1>/,
'Assertion includes more context when in DEBUG'
);
} else {
assert.throws(
() => {
set(record, 'isArchived', true);
},
/Attempted to set 'isArchived' on the deleted record <person:1>/,
"Assertion does not leak the 'value'"
);
}

currentState = record._internalModel.currentState;

Expand Down
6 changes: 5 additions & 1 deletion packages/store/addon/-private/system/model/internal-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,11 @@ export default class InternalModel {

setDirtyAttribute(key, value) {
if (this.isDeleted()) {
throw new EmberError(`Attempted to set '${key}' to '${value}' on the deleted record ${this}`);
if (DEBUG) {
throw new EmberError(`Attempted to set '${key}' to '${value}' on the deleted record ${this}`);
} else {
throw new EmberError(`Attempted to set '${key}' on the deleted record ${this}`);
}
}

let currentValue = this.getAttributeValue(key);
Expand Down

0 comments on commit da4fb93

Please sign in to comment.