Skip to content

Commit

Permalink
Fix Environment.getUserRootDirectory() on Non-Windows Platforms (#6581)
Browse files Browse the repository at this point in the history
fix: `Environment.getUserRootDirectory()` only ever executes Windows
code path

From the Azure msal-node
[docs](https://github.com/MicrosoftDocs/azure-docs/blob/e622cd3bded2530b8db7843cd9539fd16f0cd67c/articles/active-directory/develop/msal-node-extensions.md?plain=1#L50-L52):
```typescript
// You can use the helper functions provided through the Environment class to construct your cache path
// The helper functions provide consistent implementations across Windows, Mac and Linux.
const cachePath = path.join(Environment.getUserRootDirectory(), "./cache.json");
```
The existing (broken) code:


https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/9934e3b07118403898e65091035d26295e55f128/extensions/msal-node-extensions/src/utils/Environment.ts#L59-L63

msal-node-extensions: `Environment.getUserHomeDirOnUnix()` was never
called, because `!this.isWindowsPlatform` would always be false, since
`isWindowsPlatform()` is a static method and not a property getter (or
property)

---------

Signed-off-by: Janusz Dziurzynski <[email protected]>
  • Loading branch information
rzyns authored Nov 2, 2023
1 parent 33ae9c8 commit 25472ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Environment.getUserRootDirectory() only ever executes Windows code path",
"packageName": "@azure/msal-node-extensions",
"email": "[email protected]",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion extensions/msal-node-extensions/src/utils/Environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Environment {
}

static getUserRootDirectory(): string | null {
return !this.isWindowsPlatform
return !this.isWindowsPlatform()
? this.getUserHomeDirOnUnix()
: this.getUserHomeDirOnWindows();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Environment } from "../../src/utils/Environment";

describe("Environment", () => {
test("Environment.isWindowsPlatform() should be called by Environment.getUserRootDirectory()", () => {
const spy = jest.spyOn(Environment, "isWindowsPlatform");
Environment.getUserRootDirectory();
expect(spy).toHaveBeenCalled();
});
});

0 comments on commit 25472ea

Please sign in to comment.