Skip to content

Commit

Permalink
Ensure $HOME is used when present on all platforms
Browse files Browse the repository at this point in the history
os.homedir uses USERPROFILE over HOME on Windows systems, which caused
the default behavior of AWS.SharedIniFileCredentials to change from
2.43.0 to 2.44.0
  • Loading branch information
jeskew committed Apr 26, 2017
1 parent 0a54ed2 commit 48aca4d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "SharedIniFileCredentials",
"description": "This fix reverts a regression introduced in version 2.44.0 in which the value returned by os.homedir would be used in preference over the value of the HOME environment variable"
}
8 changes: 4 additions & 4 deletions lib/shared_ini.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ module.exports = AWS.util.inherit({
},

getHomeDir: function getHomeDir() {
if (typeof os.homedir === 'function') {
return os.homedir();
}

var env = process.env;
var home = env.HOME ||
env.USERPROFILE ||
Expand All @@ -43,6 +39,10 @@ module.exports = AWS.util.inherit({
return home;
}

if (typeof os.homedir === 'function') {
return os.homedir();
}

throw AWS.util.error(
new Error('Cannot load credentials, HOME path not set')
);
Expand Down
10 changes: 10 additions & 0 deletions test/credentials.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ if AWS.util.isNode()
expect(AWS.util.readFileSync.calls[0].arguments[0]).to
.match(/[\/\\]foo[\/\\]bar[\/\\]baz[\/\\].aws[\/\\]credentials/)

it 'should prefer $HOME to os.homedir', ->
process.env.HOME = '/home/user'
helpers.spyOn(os, 'homedir').andReturn(process.env.HOME + '/foo/bar')

new AWS.SharedIniFileCredentials()
expect(os.homedir.calls.length).to.equal(0)
expect(AWS.util.readFileSync.calls.length).to.equal(1)
expect(AWS.util.readFileSync.calls[0].arguments[0]).to
.match(/[\/\\]home[\/\\]user[\/\\].aws[\/\\]credentials/)

it 'throws an error if HOME/HOMEPATH/USERPROFILE are not set', ->
expect(-> new AWS.SharedIniFileCredentials().refresh()).
to.throw('Cannot load credentials, HOME path not set')
Expand Down

0 comments on commit 48aca4d

Please sign in to comment.