Skip to content
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
9 changes: 9 additions & 0 deletions lib/jsonrpc-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = JsonRpcAdapter;

var EventEmitter = require('events').EventEmitter;
var debug = require('debug')('strong-remoting:jsonrpc-adapter');
var deprecated = require('depd')('strong-remoting');
var util = require('util');
var inherits = util.inherits;
var jayson = require('jayson');
Expand Down Expand Up @@ -145,6 +146,14 @@ JsonRpcAdapter.prototype.createHandler = function() {
var corsOptions = this.remotes.options.cors;
if (corsOptions === undefined) corsOptions = {origin: true, credentials: true};

if (corsOptions !== false) {
deprecated(g.f(
'The built-in CORS middleware provided by JsonRpc adapter ' +
'was deprecated. See %s for more details.',
'https://docs.strongloop.com/display/public/LB/Security+considerations'
));
}

// Optimize the cors handler
var corsHandler = function(req, res, next) {
var reqUrl = req.protocol + '://' + req.get('host');
Expand Down
9 changes: 9 additions & 0 deletions lib/rest-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RestAdapter.RestMethod = RestMethod;
var deprecated = require('depd')('strong-remoting');
var EventEmitter = require('events').EventEmitter;
var debug = require('debug')('strong-remoting:rest-adapter');
var deprecated = require('depd')('strong-remoting');
var util = require('util');
var inherits = util.inherits;
var assert = require('assert');
Expand Down Expand Up @@ -244,6 +245,14 @@ RestAdapter.prototype.createHandler = function() {
var corsOptions = this.remotes.options.cors;
if (corsOptions === undefined) corsOptions = {origin: true, credentials: true};

if (corsOptions !== false) {
deprecated(g.f(
'The built-in CORS middleware provided by REST adapter ' +
'was deprecated. See %s for more details.',
'https://docs.strongloop.com/display/public/LB/Security+considerations'
));
}

// Optimize the cors handler
var corsHandler = function(req, res, next) {
var reqUrl = req.protocol + '://' + req.get('host');
Expand Down
2 changes: 1 addition & 1 deletion test/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var User = require('./e2e/fixtures/user');

describe('support for HTTP Authentication', function() {
var server;
var remotes = RemoteObjects.create();
var remotes = RemoteObjects.create({cors: false});
remotes.exports.User = User;

before(function setupServer(done) {
Expand Down
2 changes: 1 addition & 1 deletion test/authorize-hook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('authorization hook', function() {

before(function setupServer(done) {
var app = express();
remotes = RemoteObjects.create();
remotes = RemoteObjects.create({cors: false});
remotes.exports.User = User;
app.use(remotes.handler('rest'));
server = app.listen(0, '127.0.0.1', done);
Expand Down
2 changes: 1 addition & 1 deletion test/jsonrpc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('strong-remoting-jsonrpc', function() {
// setup
beforeEach(function() {
if (server) server.close();
objects = RemoteObjects.create({json: {limit: '1kb'}});
objects = RemoteObjects.create({json: {limit: '1kb'}, cors: false});
remotes = objects.exports;
app = express();
});
Expand Down
4 changes: 2 additions & 2 deletions test/phase-handlers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('phase handlers', function() {

beforeEach(function setupServer(done) {
var app = express();
remotes = RemoteObjects.create();
remotes = RemoteObjects.create({cors: false});
remotes.exports.User = User;
app.use(function(req, res, next) {
// always build a new handler to pick new methods added by tests
Expand All @@ -23,7 +23,7 @@ describe('phase handlers', function() {
});

beforeEach(function setupClient() {
clientRemotes = RemoteObjects.create();
clientRemotes = RemoteObjects.create({cors: false});
clientRemotes.exports.User = User;
var url = 'http://127.0.0.1:' + server.address().port;
clientRemotes.connect(url, 'rest');
Expand Down
4 changes: 2 additions & 2 deletions test/rest-adapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('RestAdapter', function() {
var remotes;

beforeEach(function() {
remotes = RemoteObjects.create();
remotes = RemoteObjects.create({cors: false});
});

describe('getClasses()', function() {
Expand Down Expand Up @@ -383,7 +383,7 @@ describe('RestAdapter', function() {
var remotes, req, res;

beforeEach(function() {
remotes = RemoteObjects.create();
remotes = RemoteObjects.create({cors: false});
req = false;
res = false;

Expand Down
1 change: 1 addition & 0 deletions test/rest-coercion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('Coercion in RestAdapter', function() {
function setupRemoteObjects() {
ctx.remoteObjects = RemoteObjects.create({
errorHandler: { debug: true, log: false },
cors: false,
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/rest.browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('strong-remoting-rest', function() {

// setup
beforeEach(function() {
objects = RemoteObjects.create();
objects = RemoteObjects.create({cors: false});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to set CORS in all the tests? Should these tests not use the default settings?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default setting is to enable the built-in CORS middleware with { origin: true, credentials: true }, which triggers deprecation warnings. That was my intention, to poke 2.x users to rework the CORS settings in their application soon.

This applies to our tests too. If I didn't add {cors: false} to all the tests, then npm test prints a lot of deprecation warnings.

Considering the amount of changes in strongloop/loopback-component-explorer#178 too, perhaps it was not a good idea to add this deprecation message?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I didn't think about those messages crowding the test results!

I think you should leave them in.

remotes = objects.exports;

// connect to the app
Expand Down
10 changes: 8 additions & 2 deletions test/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ describe('strong-remoting-rest', function() {
if (process.env.NODE_ENV === 'production') {
process.env.NODE_ENV = 'test';
}
objects = RemoteObjects.create({json: {limit: '1kb'},
errorHandler: {disableStackTrace: false}});
objects = RemoteObjects.create({
json: {limit: '1kb'},
errorHandler: {disableStackTrace: false},
cors: false,
});
remotes = objects.exports;

// connect to the app
Expand Down Expand Up @@ -325,6 +328,9 @@ describe('strong-remoting-rest', function() {
describe('cors', function() {
var method;
beforeEach(function() {
delete objects.options.cors; // use the default setting
process.once('deprecation', function() { /* ignore */ });

method = givenSharedStaticMethod(
function greet(person, cb) {
if (person === 'error') {
Expand Down
4 changes: 2 additions & 2 deletions test/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('strong-remoting', function() {
var objects;

beforeEach(function() {
objects = RemoteObjects.create();
objects = RemoteObjects.create({cors: false});
remotes = objects.exports;
app = express();
app.disable('x-powered-by');
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('strong-remoting', function() {

describe('a function returning a ReadableStream', function() {
var Readable = require('stream').Readable;
var remotes = RemoteObjects.create();
var remotes = RemoteObjects.create({cors: false});
var streamClass;
var server;
var app;
Expand Down
2 changes: 1 addition & 1 deletion test/type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var RemoteObjects = require('../');
describe('types', function() {
var remotes;
beforeEach(function() {
remotes = RemoteObjects.create();
remotes = RemoteObjects.create({cors: false});
});
describe('remotes.defineType(name, fn)', function() {
it('should define a new type converter', function() {
Expand Down