Skip to content

Ensure password: prefix is anchored at start of line #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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