Skip to content

Commit 6469eea

Browse files
Merge pull request googleapis#101 from jmdobry/fix-callback
Fix getApplicationDefault to also return projectId.
2 parents 4a0b7fc + 735d6e9 commit 6469eea

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/auth/googleauth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ function GoogleAuth() {
3737
}
3838

3939
// Executes the given callback if it is not null.
40-
function callback(c, err, res) {
40+
function callback(c) {
4141
if (c) {
42-
c(err, res);
42+
return c.apply(null, Array.prototype.slice.call(arguments, 1));
4343
}
4444
}
4545

test/test.googleauth.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,41 @@ describe('GoogleAuth', function() {
11061106
done();
11071107
});
11081108
});
1109+
1110+
it('should also get project ID', function (done) {
1111+
// We expect private.json to be the file that is used.
1112+
var fileContents = fs.readFileSync('./test/fixtures/private.json', 'utf-8');
1113+
var json = JSON.parse(fileContents);
1114+
var testProjectId = 'my-awesome-project';
1115+
1116+
// Set up the creds.
1117+
// * Environment variable is set up to point to private.json
1118+
// * Well-known file is set up to point to private2.json
1119+
// * Running on GCE is set to true.
1120+
var auth = new GoogleAuth();
1121+
insertEnvironmentVariableIntoAuth(auth, 'GOOGLE_APPLICATION_CREDENTIALS',
1122+
'./test/fixtures/private.json');
1123+
insertEnvironmentVariableIntoAuth(auth, 'GCLOUD_PROJECT', testProjectId);
1124+
insertEnvironmentVariableIntoAuth(auth, 'APPDATA', 'foo');
1125+
auth._pathJoin = pathJoin;
1126+
auth._osPlatform = returns('win32');
1127+
auth._fileExists = returns(true);
1128+
auth._checkIsGCE = callsBack(true);
1129+
insertWellKnownFilePathIntoAuth(auth, 'foo:gcloud:application_default_credentials.json',
1130+
'./test/fixtures/private2.json');
1131+
1132+
// Execute.
1133+
auth.getApplicationDefault(function (err, result, projectId) {
1134+
assert.equal(null, err);
1135+
assert.equal(json.private_key, result.key);
1136+
assert.equal(json.client_email, result.email);
1137+
assert.equal(projectId, testProjectId);
1138+
assert.equal(null, result.keyFile);
1139+
assert.equal(null, result.subject);
1140+
assert.equal(null, result.scope);
1141+
done();
1142+
});
1143+
});
11091144
});
11101145

11111146
describe('._checkIsGCE', function () {

0 commit comments

Comments
 (0)