Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/drudge/node-keychain
Browse files Browse the repository at this point in the history
  • Loading branch information
drudge committed Jun 7, 2023
2 parents b4b29a9 + d20dc30 commit 28ac548
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keychain.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ KeychainAccess.prototype.getPassword = function(opts, fn) {
//
// e.g. password '∆˚ˆ©ƒ®∂çµ˚¬˙ƒ®†¥' becomes:
// password: 0xE28886CB9ACB86C2A9C692C2AEE28882C3A7C2B5CB9AC2ACCB99C692C2AEE280A0C2A5
if (/password: 0x([0-9a-fA-F]+)/.test(password)) {
if (/^password: 0x([0-9a-fA-F]+)/.test(password)) {
var hexPassword = password.match(/0x([0-9a-fA-F]+)/, '')[1];
fn(null, Buffer.from(hexPassword, 'hex').toString());
}
Expand Down
22 changes: 22 additions & 0 deletions test/keychain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('KeychainAccess', function(){
var asciiPW = "test";
var mixedPW = "∆elta";
var unicodePW = "∆˚ˆ©ƒ®∂çµ˚¬˙ƒ®†¥";
var asciiComplexPW = "password: 0x4e6573746564";
var keychainName = "test.keychain";

it('should be running on a mac', function(){
Expand Down Expand Up @@ -79,6 +80,16 @@ describe('KeychainAccess', function(){
});
});

describe('when sent { account: "complexAccount", password: "' + asciiComplexPW + '", service: "' + testService + '" }', function(){
it('should return "' + asciiComplexPW, function(done){
keychain.setPassword({ account: "complexAccount", password: asciiComplexPW, service: testService }, function(err, pass) {
if (err) throw err;
pass.should.equal(asciiComplexPW);
done();
});
});
});

describe('when sent { account: "mixedAccount", password: "' + mixedPW + '", service: "' + testService + '" }', function(){
it('should return "' + mixedPW, function(done){
keychain.setPassword({ account: "mixedAccount", password: mixedPW, service: testService }, function(err, pass) {
Expand Down Expand Up @@ -162,6 +173,17 @@ describe('KeychainAccess', function(){
});
});

describe('when sent { account: "complexAccount", service: "' + testService +'" }', function(){
it('should return ' + asciiComplexPW, function(done){
keychain.getPassword({ account: "complexAccount", service: testService }, function(err, pass) {
if (err) throw err;

pass.should.equal(asciiComplexPW);
done();
});
});
});

describe('when sent { account: "mixedAccount", service: "' + testService +'" }', function(){
it('should return ' + mixedPW, function(done){
keychain.getPassword({ account: "mixedAccount", service: testService }, function(err, pass) {
Expand Down

0 comments on commit 28ac548

Please sign in to comment.