Skip to content

Commit

Permalink
fix(amqp_error): accept non-standard values for error-condition
Browse files Browse the repository at this point in the history
fixes #293
  • Loading branch information
mbroadst committed Feb 7, 2017
1 parent cfc000b commit 9a560d2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/types/amqp_error.js
@@ -1,11 +1,11 @@
'use strict';
var ErrorCondition = require('./error_condition'),
defineComposite = require('./composite_type').defineComposite,
errors = require('../errors');
defineComposite = require('./composite_type').defineComposite;

function errorCondition(value) {
if (!ErrorCondition.hasOwnProperty(value))
throw new errors.EncodingError(value, 'invalid error condition: ' + value);
if (!ErrorCondition.hasOwnProperty(value)) {
return value;
}

return ErrorCondition.hasOwnProperty(ErrorCondition[value]) ?
ErrorCondition[ErrorCondition[value]] :
Expand Down
32 changes: 32 additions & 0 deletions test/unit/frames.test.js
Expand Up @@ -542,6 +542,38 @@ describe('FlowFrame', function() {
describe('DetachFrame', function() {
// @todo missing encode
// @todo missing decode
it('should decode performative correctly with nonstandard error condition (#293)', function() {
var buffer = tu.newBuffer([
0x00, 0x00, 0x01, 0x3c, 0x02, 0x00, 0x00, 0x00, 0x00, 0x53, 0x16, 0xd0, 0x00, 0x00,
0x01, 0x2c, 0x00, 0x00, 0x00, 0x03, 0x43, 0x41, 0x00, 0x53, 0x1d, 0xd0, 0x00, 0x00,
0x01, 0x1e, 0x00, 0x00, 0x00, 0x03, 0xa3, 0x23, 0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x69,
0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x3a, 0x61, 0x72, 0x67, 0x75, 0x6d, 0x65,
0x6e, 0x74, 0x2d, 0x6f, 0x75, 0x74, 0x2d, 0x6f, 0x66, 0x2d, 0x72, 0x61, 0x6e, 0x67,
0x65, 0xa1, 0xf2, 0x54, 0x68, 0x65, 0x20, 0x73, 0x70, 0x65, 0x63, 0x69, 0x66, 0x69,
0x65, 0x64, 0x20, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x69,
0x73, 0x20, 0x69, 0x6e, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x20, 0x66, 0x6f, 0x72, 0x20,
0x61, 0x6e, 0x20, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48, 0x75, 0x62, 0x20, 0x70, 0x61,
0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x73, 0x65, 0x6e, 0x64, 0x65, 0x72,
0x20, 0x6f, 0x72, 0x20, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x72, 0x2e, 0x20,
0x49, 0x74, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x62,
0x65, 0x74, 0x77, 0x65, 0x65, 0x6e, 0x20, 0x30, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x37,
0x2e, 0x0d, 0x0a, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x20, 0x6e,
0x61, 0x6d, 0x65, 0x3a, 0x20, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e,
0x49, 0x64, 0x20, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x69, 0x6e, 0x67, 0x49, 0x64, 0x3a,
0x63, 0x32, 0x31, 0x38, 0x65, 0x33, 0x36, 0x31, 0x61, 0x35, 0x35, 0x32, 0x34, 0x63,
0x39, 0x66, 0x61, 0x64, 0x66, 0x34, 0x36, 0x33, 0x31, 0x61, 0x32, 0x64, 0x61, 0x65,
0x32, 0x37, 0x65, 0x63, 0x5f, 0x47, 0x34, 0x37, 0x2c, 0x20, 0x53, 0x79, 0x73, 0x74,
0x65, 0x6d, 0x54, 0x72, 0x61, 0x63, 0x6b, 0x65, 0x72, 0x3a, 0x67, 0x61, 0x74, 0x65,
0x77, 0x61, 0x79, 0x36, 0x2c, 0x20, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
0x70, 0x3a, 0x32, 0x2f, 0x37, 0x2f, 0x32, 0x30, 0x31, 0x37, 0x20, 0x37, 0x3a, 0x32,
0x37, 0x3a, 0x32, 0x30, 0x20, 0x50, 0x4d, 0x40
]);

var detach = frames.readFrame(buffer);
expect(detach).to.exist;
expect(detach).to.be.an.instanceOf(frames.DetachFrame);
expect(detach.error.condition).to.eql('com.microsoft:argument-out-of-range');
});
}); // DetachFrame

describe('EndFrame', function() {
Expand Down

0 comments on commit 9a560d2

Please sign in to comment.