Skip to content

Commit

Permalink
Fix async mode for bad acct packets.
Browse files Browse the repository at this point in the history
The code assumed it was running in non-async mode.
  • Loading branch information
Peter Sanford committed Feb 4, 2013
1 parent 0f5b102 commit 3d427a0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/radius.js
Expand Up @@ -291,10 +291,16 @@ for (var code in code_map)
reverse_code_map[code_map[code]] = code;

Radius.error = function(error_msg, callback) {
if (callback)
callback(error_msg, null);
else
throw new Error(error_msg);
var err = error_msg;
if (typeof(error_msg) === 'string') {
err = new Error(error_msg);
}

if (callback) {
callback(err, null);
} else {
throw err;
}
};

Radius.decode = function(args) {
Expand Down Expand Up @@ -339,7 +345,8 @@ Radius._decode = function(args) {
var hash = new Buffer(hasher.digest("binary"), "binary");

if (hash.toString() != this.authenticator.toString()) {
throw new Radius.InvalidSecretError("Shared secret does not match", ret);
this.error(new Radius.InvalidSecretError("Shared secret does not match", ret), args.callback);
return;
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/radius.test.js
Expand Up @@ -349,6 +349,23 @@ module.exports = testCase({
test.deepEqual( expected_attrs, err.decoded.attributes );
}
test.done();
},

test_invalid_accounting_packet_authenticator_async: function(test) {
var raw_acct_request = test_args.raw_acct_request;
var expected_attrs = test_args.expected_acct_attrs;

var decode_callback = function(err, packet) {
test.ok( err );
test.deepEqual( expected_attrs, err.decoded.attributes );
test.done();
};

radius.decode({
packet: raw_acct_request,
secret: 'not-secret',
callback: decode_callback
});
}
},

Expand Down

0 comments on commit 3d427a0

Please sign in to comment.