Skip to content

Commit

Permalink
Failing test: Add test showing prototype mutation leaking across visi…
Browse files Browse the repository at this point in the history
…t requests.

This shows that mutating the prototype of an object used in multiple
requests, leaks that mutation.
  • Loading branch information
rwjblue committed Oct 30, 2019
1 parent 148a75c commit b67703f
Show file tree
Hide file tree
Showing 9 changed files with 66,347 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/fastboot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,27 @@ describe('FastBoot', function() {
expect(html).to.match(/Other Config {"default":"bar"}/);
});
});

it('in app prototype mutations do not leak across visits', async function() {
this.timeout(3000);

var fastboot = new FastBoot({
distPath: fixture('app-with-prototype-mutations'),
});

let result = await fastboot.visit('/');
let html = await result.html();

expect(html).to.match(/Items: 1/);

result = await fastboot.visit('/');
html = await result.html();

expect(html).to.match(/Items: 1/);

result = await fastboot.visit('/');
html = await result.html();

expect(html).to.match(/Items: 1/);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
define('~fastboot/app-factory', ['app-with-mutable-prototype/app', 'app-with-mutable-prototype/config/environment'], function(App, config) {
App = App['default'];
config = config['default'];

return {
'default': function() {
return App.create(config.APP);
}
};
});

define("app-with-mutable-prototype/initializers/ajax", ["exports"], function (_exports) {
"use strict";

Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports.default = void 0;
const {
get
} = Ember;

var nodeAjax = function (options) {
let httpRegex = /^https?:\/\//;
let protocolRelativeRegex = /^\/\//;
let protocol = get(this, 'fastboot.request.protocol');

if (protocolRelativeRegex.test(options.url)) {
options.url = protocol + options.url;
} else if (!httpRegex.test(options.url)) {
try {
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url;
} catch (fbError) {
throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message);
}
}

if (najax) {
najax(options);
} else {
throw new Error('najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?');
}
};

var _default = {
name: 'ajax-service',
initialize: function (application) {
application.register('ajax:node', nodeAjax, {
instantiate: false
});
application.inject('adapter', '_ajaxRequest', 'ajax:node');
application.inject('adapter', 'fastboot', 'service:fastboot');
}
};
_exports.default = _default;
});
define("app-with-mutable-prototype/initializers/error-handler", ["exports"], function (_exports) {
"use strict";

Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports.default = void 0;

/**
* Initializer to attach an `onError` hook to your app running in fastboot. It catches any run loop
* exceptions and other errors and prevents the node process from crashing.
*
*/
var _default = {
name: 'error-handler',
initialize: function () {
if (!Ember.onerror) {
// if no onerror handler is defined, define one for fastboot environments
Ember.onerror = function (err) {
const errorMessage = "There was an error running your app in fastboot. More info about the error: \n ".concat(err.stack || err);
console.error(errorMessage);
};
}
}
};
_exports.default = _default;
});//# sourceMappingURL=app-with-mutable-prototype-fastboot.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b67703f

Please sign in to comment.