Skip to content

Commit

Permalink
Merge pull request #451 from jfromaniello/add_amqplain_credentials
Browse files Browse the repository at this point in the history
add amqplain credentials
  • Loading branch information
squaremo committed Oct 12, 2018
2 parents 6ee18f2 + ddc0553 commit fd0bf21
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// * EXTERNAL (assume the server will figure out who you are from
// context, i.e., your SSL certificate)
var Buffer = require('safe-buffer').Buffer
var codec = require('./codec')

module.exports.plain = function(user, passwd) {
return {
Expand All @@ -21,6 +22,19 @@ module.exports.plain = function(user, passwd) {
}
}

module.exports.amqplain = function(user, passwd) {
return {
mechanism: 'AMQPLAIN',
response: function() {
const buffer = Buffer.alloc(16384);
const size = codec.encodeTable(buffer, { LOGIN: user, PASSWORD: passwd}, 0);
return buffer.slice(4, size);
},
username: user,
password: passwd
}
}

module.exports.external = function() {
return {
mechanism: 'EXTERNAL',
Expand Down
12 changes: 12 additions & 0 deletions test/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ suite("Connect API", function() {
kCallback(succeed(done), fail(done)));
});

test("using amqplain credentials", function(done) {
var url = require('url');
var parts = url.parse(URL, true);
var u = 'guest', p = 'guest';
if (parts.auth) {
var auth = parts.auth.split(":");
u = auth[0], p = auth[1];
}
connect(URL, {credentials: require('../lib/credentials').amqplain(u, p)},
kCallback(succeed(done), fail(done)));
});

test("using unsupported mechanism", function(done) {
var creds = {
mechanism: 'UNSUPPORTED',
Expand Down

0 comments on commit fd0bf21

Please sign in to comment.