Skip to content

Commit

Permalink
fix: enable symbolic-link credentials files (#129)
Browse files Browse the repository at this point in the history
Currently, credentials files are explicitly required to real files (not symbolic links).
This was to exclude directories, not to exclude symbolic links, so it is a bug.

This PR adds explicit support for symbolic links. This should be a robust solution, as
I do not believe we want to support any of the other types the file could be (sockets,
block devices, etc).
  • Loading branch information
dpopp07 committed Mar 16, 2021
1 parent 4642636 commit 4b87d42
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion auth/utils/read-credentials-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ export function readCredentialsFile() {
}

export function fileExistsAtPath(filepath): boolean {
return fs.existsSync(filepath) && fs.lstatSync(filepath).isFile();
if (fs.existsSync(filepath)) {
const stats = fs.lstatSync(filepath);
return stats.isFile() || stats.isSymbolicLink();
}

return false;
}

export function constructFilepath(filepath): string {
Expand Down
1 change: 1 addition & 0 deletions test/resources/symlink-creds.txt
5 changes: 5 additions & 0 deletions test/unit/read-credentials-file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ describe('read ibm credentials file', () => {
const path = '/path/to/file/wrong-file.env';
expect(fileExistsAtPath(path)).toBe(false);
});

it('should return true for a symbolic link', () => {
const path = __dirname + '/../resources/symlink-creds.txt';
expect(fileExistsAtPath(path)).toBe(true);
});
});

describe('read credentials file', () => {
Expand Down

0 comments on commit 4b87d42

Please sign in to comment.