Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getCredential(): load credentials with getClient() #648

Merged
merged 2 commits into from
Mar 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/auth/googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ export class GoogleAuth {
}

private async getCredentialsAsync(): Promise<CredentialBody> {
await this.getClient();

if (this.jsonContent) {
const credential: CredentialBody = {
client_email: this.jsonContent.client_email,
Expand Down
22 changes: 22 additions & 0 deletions test/test.googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,28 @@ describe('googleauth', () => {
assert.strictEqual(jwt.key, body!.private_key);
});

it('getCredentials should call getClient to load credentials', async () => {
// Set up a mock to return path to a valid credentials file.
blockGoogleApplicationCredentialEnvironmentVariable();
mockEnvVar(
'GOOGLE_APPLICATION_CREDENTIALS', './test/fixtures/private.json');

const spy = sinon.spy(auth, 'getClient');
const body = await auth.getCredentials();

const result =
await auth._tryGetApplicationCredentialsFromEnvironmentVariable();
if (!(result instanceof JWT)) {
throw new assert.AssertionError(
{message: 'Credentials are not a JWT object'});
}

assert.notEqual(null, body);
assert(spy.calledOnce);
assert.strictEqual(result.email, body!.client_email);
assert.strictEqual(result.key, body!.private_key);
});

it('getCredentials should handle valid file path', async () => {
// Set up a mock to return path to a valid credentials file.
blockGoogleApplicationCredentialEnvironmentVariable();
Expand Down