From 6c2f4fafd51672cf1871d281e5ec3b50fbe18931 Mon Sep 17 00:00:00 2001 From: Andrew Kirwin Date: Mon, 30 Nov 2020 17:32:15 +0000 Subject: [PATCH] Don't expose the value of a model's attribute in assertions (#7370) * don't expose the value of a model's attribute in production builds --- packages/-ember-data/tests/unit/model-test.js | 21 ++++++++++++++++--- .../-private/system/model/internal-model.ts | 6 +++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/-ember-data/tests/unit/model-test.js b/packages/-ember-data/tests/unit/model-test.js index 2314d10856e..ee5e5efba00 100644 --- a/packages/-ember-data/tests/unit/model-test.js +++ b/packages/-ember-data/tests/unit/model-test.js @@ -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'; @@ -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 /); + if (DEBUG) { + assert.throws( + () => { + set(record, 'isArchived', true); + }, + /Attempted to set 'isArchived' to 'true' on the deleted record /, + 'Assertion includes more context when in DEBUG' + ); + } else { + assert.throws( + () => { + set(record, 'isArchived', true); + }, + /Attempted to set 'isArchived' on the deleted record /, + "Assertion does not leak the 'value'" + ); + } currentState = record._internalModel.currentState; diff --git a/packages/store/addon/-private/system/model/internal-model.ts b/packages/store/addon/-private/system/model/internal-model.ts index 69490ef4a6a..cf0b251a738 100644 --- a/packages/store/addon/-private/system/model/internal-model.ts +++ b/packages/store/addon/-private/system/model/internal-model.ts @@ -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);