Merge pull request #171 from gr2m/master

allow to set PRIVATE_KEY with "\\n" characters
This commit is contained in:
Gregor Martynus 2017-07-13 08:14:51 -07:00 committed by GitHub
commit ece26960ff
2 changed files with 16 additions and 1 deletions

View File

@ -16,7 +16,7 @@ function findPrivateKey(filepath) {
return fs.readFileSync(filepath);
}
if (process.env.PRIVATE_KEY) {
return process.env.PRIVATE_KEY;
return process.env.PRIVATE_KEY.replace(/\\n/g, '\n');
}
if (process.env.PRIVATE_KEY_PATH) {
return fs.readFileSync(process.env.PRIVATE_KEY_PATH);

View File

@ -48,6 +48,21 @@ describe('private-key', function () {
});
});
describe('when a PRIVATE_KEY has line breaks', function () {
beforeEach(function () {
process.env.PRIVATE_KEY = 'line 1\\nline 2';
});
afterEach(function () {
delete process.env.PRIVATE_KEY;
});
it('should return the key', function () {
expect(findPrivateKey())
.toEqual('line 1\nline 2');
});
});
describe('when a PRIVATE_KEY_PATH env var is provided', function () {
beforeEach(function () {
process.env.PRIVATE_KEY_PATH = keyfilePath;