From d0bdfc7845b702d616b22ec5d6ec5ae198cb592e Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Tue, 25 Oct 2016 11:46:29 -0400 Subject: [PATCH] fix(policy): remove sealing to allow extension of policy methods Since we returned a sealed object from the PolicyBase function, we could not actually extend the `parseAddress` and `parseLinkAddress` methods. Removing that line fixes it, and two tests are included --- lib/policies/policy.js | 2 +- test/unit/policies/policy.test.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/policies/policy.js b/lib/policies/policy.js index f7a12f5..2f586c6 100644 --- a/lib/policies/policy.js +++ b/lib/policies/policy.js @@ -103,7 +103,7 @@ function Policy(overrides) { }, }); - return Object.seal(this); + return this; } /** diff --git a/test/unit/policies/policy.test.js b/test/unit/policies/policy.test.js index b3a35f9..0ee429e 100644 --- a/test/unit/policies/policy.test.js +++ b/test/unit/policies/policy.test.js @@ -43,6 +43,20 @@ describe('Default Policy', function() { }); }); + it('should allow redefinition of parseAddress', function() { + var policy = amqp.Policy.merge({}, amqp.Policy.DefaultPolicy); + policy.parseAddress = function() { return { name: 'llamas' }; }; + var addr = policy.parseAddress('testing'); + expect(addr).to.eql({ name: 'llamas' }); + }); + + it('should allow redefinition of parseLinkAddress', function() { + var policy = amqp.Policy.merge({}, amqp.Policy.DefaultPolicy); + policy.parseLinkAddress = function() { return { name: 'llamas' }; }; + var addr = policy.parseLinkAddress('testing'); + expect(addr).to.eql({ name: 'llamas' }); + }); + it('should not add a SASL layer for anonymous auth by default', function() { var policy = amqp.Policy.merge({ connect: {