Skip to content

Commit

Permalink
fix(policy): fix deprecated link options when using link overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Apr 20, 2017
1 parent be48605 commit 25a8ded
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
3 changes: 3 additions & 0 deletions lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var EventEmitter = require('events').EventEmitter,

debug = require('debug')('amqp10:link'),
u = require('./utilities'),
pu = require('./policies/policy_utilities'),
frames = require('./frames'),
errors = require('./errors');

Expand Down Expand Up @@ -55,6 +56,8 @@ var stateMachine = function(link) {
*/
function Link(session, handle, linkPolicy) {
this.policy = linkPolicy;
pu.fixDeprecatedLinkOptions(this.policy);

this.session = session;
this.handle = handle;
this.remote = { handle: undefined };
Expand Down
3 changes: 2 additions & 1 deletion lib/policies/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ function Policy(overrides) {
},
});

putils.fixDeprecatedOptions(this);
putils.fixDeprecatedLinkOptions(this.senderLink);
putils.fixDeprecatedLinkOptions(this.receiverLink);
return this;
}

Expand Down
30 changes: 13 additions & 17 deletions lib/policies/policy_utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,26 @@ var SenderCallbackPolicy = {
module.exports.SenderCallbackPolicies = SenderCallbackPolicy; // deprecated
module.exports.SenderCallbackPolicy = SenderCallbackPolicy;

function fixDeprecatedOptions(policy) {
if (policy === undefined || policy === null) return;

if (policy.senderLink &&
policy.senderLink.attach &&
policy.senderLink.attach.hasOwnProperty('senderSettleMode')) {
policy.senderLink.attach.sndSettleMode =
policy.senderLink.attach.senderSettleMode;
delete policy.senderLink.attach.senderSettleMode;
}
function fixDeprecatedLinkOptions(policy) {
if (policy && policy.attach) {
if (policy.attach.hasOwnProperty('senderSettleMode')) {
policy.attach.sndSettleMode = policy.attach.senderSettleMode;
delete policy.attach.senderSettleMode;
}

if (policy.receiverLink &&
policy.receiverLink.attach &&
policy.receiverLink.attach.hasOwnProperty('receiverSettleMode')) {
policy.receiverLink.attach.rcvSettleMode = policy.receiverLink.attach.receiverSettleMode;
delete policy.receiverLink.attach.receiverSettleMode;
if (policy.attach.hasOwnProperty('receiverSettleMode')) {
policy.attach.rcvSettleMode = policy.attach.receiverSettleMode;
delete policy.attach.receiverSettleMode;
}
}
}

module.exports.fixDeprecatedOptions = fixDeprecatedOptions;
module.exports.fixDeprecatedLinkOptions = fixDeprecatedLinkOptions;

function merge(newPolicy, base) {
var policy = u.deepMerge(newPolicy, base);
fixDeprecatedOptions(policy);
fixDeprecatedLinkOptions(policy.senderLink);
fixDeprecatedLinkOptions(policy.receiverLink);
return policy;
}

Expand Down
11 changes: 11 additions & 0 deletions test/unit/policies/policy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var amqp = require('../../../lib'),
Sasl = require('../../../lib/sasl'),
ErrorCondition = require('../../../lib/types/error_condition'),

pu = require('../../../lib/policies/policy_utilities'),
expect = require('chai').expect,
test = require('../test-fixture');

Expand Down Expand Up @@ -76,6 +77,16 @@ describe('Default Policy', function() {
expect(policy2.senderLink.attach.senderSettleMode).to.not.exist;
expect(policy2.receiverLink.attach.rcvSettleMode).to.eql('biscuits');
expect(policy2.receiverLink.attach.receiverSettleMode).to.not.exist;

// for direct access, e.g. when passing overrides to `createLink`
var senderLinkPolicy = { attach: { senderSettleMode: 'llamas' } };
pu.fixDeprecatedLinkOptions(senderLinkPolicy);
expect(senderLinkPolicy.attach.senderSettleMode).to.not.exist;
expect(senderLinkPolicy.attach.sndSettleMode).to.eql('llamas');
var receiverLinkPolicy = { attach: { receiverSettleMode: 'biscuits' } };
pu.fixDeprecatedLinkOptions(receiverLinkPolicy);
expect(receiverLinkPolicy.attach.receiverSettleMode).to.not.exist;
expect(receiverLinkPolicy.attach.rcvSettleMode).to.eql('biscuits');
});

it('should not add a SASL layer for anonymous auth by default', function() {
Expand Down

0 comments on commit 25a8ded

Please sign in to comment.