Skip to content

Commit d20dc30

Browse files
authored
Merge pull request #15 from hughescr/master
Ensure `password:` prefix is anchored at start of line
2 parents 5025c85 + d1ab00f commit d20dc30

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

keychain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ KeychainAccess.prototype.getPassword = function(opts, fn) {
105105
//
106106
// e.g. password '∆˚ˆ©ƒ®∂çµ˚¬˙ƒ®†¥' becomes:
107107
// password: 0xE28886CB9ACB86C2A9C692C2AEE28882C3A7C2B5CB9AC2ACCB99C692C2AEE280A0C2A5
108-
if (/password: 0x([0-9a-fA-F]+)/.test(password)) {
108+
if (/^password: 0x([0-9a-fA-F]+)/.test(password)) {
109109
var hexPassword = password.match(/0x([0-9a-fA-F]+)/, '')[1];
110110
fn(null, Buffer.from(hexPassword, 'hex').toString());
111111
}

test/keychain.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('KeychainAccess', function(){
1010
var asciiPW = "test";
1111
var mixedPW = "∆elta";
1212
var unicodePW = "∆˚ˆ©ƒ®∂çµ˚¬˙ƒ®†¥";
13+
var asciiComplexPW = "password: 0x4e6573746564";
1314
var keychainName = "test.keychain";
1415

1516
it('should be running on a mac', function(){
@@ -79,6 +80,16 @@ describe('KeychainAccess', function(){
7980
});
8081
});
8182

83+
describe('when sent { account: "complexAccount", password: "' + asciiComplexPW + '", service: "' + testService + '" }', function(){
84+
it('should return "' + asciiComplexPW, function(done){
85+
keychain.setPassword({ account: "complexAccount", password: asciiComplexPW, service: testService }, function(err, pass) {
86+
if (err) throw err;
87+
pass.should.equal(asciiComplexPW);
88+
done();
89+
});
90+
});
91+
});
92+
8293
describe('when sent { account: "mixedAccount", password: "' + mixedPW + '", service: "' + testService + '" }', function(){
8394
it('should return "' + mixedPW, function(done){
8495
keychain.setPassword({ account: "mixedAccount", password: mixedPW, service: testService }, function(err, pass) {
@@ -162,6 +173,17 @@ describe('KeychainAccess', function(){
162173
});
163174
});
164175

176+
describe('when sent { account: "complexAccount", service: "' + testService +'" }', function(){
177+
it('should return ' + asciiComplexPW, function(done){
178+
keychain.getPassword({ account: "complexAccount", service: testService }, function(err, pass) {
179+
if (err) throw err;
180+
181+
pass.should.equal(asciiComplexPW);
182+
done();
183+
});
184+
});
185+
});
186+
165187
describe('when sent { account: "mixedAccount", service: "' + testService +'" }', function(){
166188
it('should return ' + mixedPW, function(done){
167189
keychain.getPassword({ account: "mixedAccount", service: testService }, function(err, pass) {

0 commit comments

Comments
 (0)