diff --git a/auth/utils/read-credentials-file.ts b/auth/utils/read-credentials-file.ts index 0252a781a..37baf7c27 100644 --- a/auth/utils/read-credentials-file.ts +++ b/auth/utils/read-credentials-file.ts @@ -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 { diff --git a/test/resources/symlink-creds.txt b/test/resources/symlink-creds.txt new file mode 120000 index 000000000..3c4dcb96a --- /dev/null +++ b/test/resources/symlink-creds.txt @@ -0,0 +1 @@ +ibm-credentials.env \ No newline at end of file diff --git a/test/unit/read-credentials-file.test.js b/test/unit/read-credentials-file.test.js index 86ee3c90e..dd67a1c3a 100644 --- a/test/unit/read-credentials-file.test.js +++ b/test/unit/read-credentials-file.test.js @@ -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', () => {