From f453fb7d8355e6dc74800b18d6f43c4e91d4acc9 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sat, 21 Mar 2020 13:46:37 -0700 Subject: [PATCH] chore!: remove deprecated methods (#906) --- src/auth/computeclient.ts | 14 -------- src/auth/googleauth.ts | 17 --------- src/auth/iam.ts | 27 -------------- src/auth/jwtaccess.ts | 29 --------------- src/auth/jwtclient.ts | 11 ------ src/auth/oauth2client.ts | 27 -------------- src/messages.ts | 76 --------------------------------------- test/test.compute.ts | 13 ------- test/test.googleauth.ts | 30 ---------------- test/test.iam.ts | 17 --------- test/test.jwt.ts | 74 -------------------------------------- test/test.jwtaccess.ts | 28 ++------------- test/test.oauth2.ts | 8 ----- 13 files changed, 2 insertions(+), 369 deletions(-) diff --git a/src/auth/computeclient.ts b/src/auth/computeclient.ts index 57b83def..80a27e6d 100644 --- a/src/auth/computeclient.ts +++ b/src/auth/computeclient.ts @@ -55,20 +55,6 @@ export class Compute extends OAuth2Client { this.scopes = arrify(options.scopes); } - /** - * Indicates whether the credential requires scopes to be created by calling - * createdScoped before use. - * @deprecated - * @return Boolean indicating if scope is required. - */ - createScopedRequired() { - // On compute engine, scopes are specified at the compute instance's - // creation time, and cannot be changed. For this reason, always return - // false. - messages.warn(messages.COMPUTE_CREATE_SCOPED_DEPRECATED); - return false; - } - /** * Refreshes the access token. * @param refreshToken Unused parameter diff --git a/src/auth/googleauth.ts b/src/auth/googleauth.ts index 93d231ec..11fce60c 100644 --- a/src/auth/googleauth.ts +++ b/src/auth/googleauth.ts @@ -137,23 +137,6 @@ export class GoogleAuth { this.clientOptions = opts.clientOptions; } - /** - * THIS METHOD HAS BEEN DEPRECATED. - * It will be removed in 3.0. Please use getProjectId instead. - */ - getDefaultProjectId(): Promise; - getDefaultProjectId(callback: ProjectIdCallback): void; - getDefaultProjectId( - callback?: ProjectIdCallback - ): Promise | void { - messages.warn(messages.DEFAULT_PROJECT_ID_DEPRECATED); - if (callback) { - this.getProjectIdAsync().then(r => callback(null, r), callback); - } else { - return this.getProjectIdAsync(); - } - } - /** * Obtains the default project ID for the application. * @param callback Optional callback diff --git a/src/auth/iam.ts b/src/auth/iam.ts index cfb8fefe..ede366fd 100644 --- a/src/auth/iam.ts +++ b/src/auth/iam.ts @@ -32,33 +32,6 @@ export class IAMAuth { this.token = token; } - /** - * Indicates whether the credential requires scopes to be created by calling - * createdScoped before use. - * @deprecated - * @return always false - */ - createScopedRequired() { - // IAM authorization does not use scopes. - messages.warn(messages.IAM_CREATE_SCOPED_DEPRECATED); - return false; - } - - /** - * Pass the selector and token to the metadataFn callback. - * @deprecated - * @param unused_uri is required of the credentials interface - * @param metadataFn a callback invoked with object containing request - * metadata. - */ - getRequestMetadata( - unusedUri: string | null, - metadataFn: (err: Error | null, metadata?: RequestMetadata) => void - ) { - messages.warn(messages.IAM_GET_REQUEST_METADATA_DEPRECATED); - metadataFn(null, this.getRequestHeaders()); - } - /** * Acquire the HTTP headers required to make an authenticated request. */ diff --git a/src/auth/jwtaccess.ts b/src/auth/jwtaccess.ts index 03cdd6d1..78f70a43 100644 --- a/src/auth/jwtaccess.ts +++ b/src/auth/jwtaccess.ts @@ -57,35 +57,6 @@ export class JWTAccess { this.keyId = keyId; } - /** - * Indicates whether the credential requires scopes to be created by calling - * createdScoped before use. - * @deprecated - * @return always false - */ - createScopedRequired(): boolean { - // JWT Header authentication does not use scopes. - messages.warn(messages.JWT_ACCESS_CREATE_SCOPED_DEPRECATED); - return false; - } - - /** - * Get a non-expired access token, after refreshing if necessary. - * - * @param authURI The URI being authorized. - * @param additionalClaims An object with a set of additional claims to - * include in the payload. - * @deprecated Please use `getRequestHeaders` instead. - * @returns An object that includes the authorization header. - */ - getRequestMetadata( - url: string, - additionalClaims?: Claims - ): RequestMetadataResponse { - messages.warn(messages.JWT_ACCESS_GET_REQUEST_METADATA_DEPRECATED); - return {headers: this.getRequestHeaders(url, additionalClaims)}; - } - /** * Get a non-expired access token, after refreshing if necessary. * diff --git a/src/auth/jwtclient.ts b/src/auth/jwtclient.ts index e4f173dc..f6a1ace9 100644 --- a/src/auth/jwtclient.ts +++ b/src/auth/jwtclient.ts @@ -174,17 +174,6 @@ export class JWT extends OAuth2Client implements IdTokenProvider { return gtoken.idToken; } - /** - * Indicates whether the credential requires scopes to be created by calling - * createScoped before use. - * @deprecated - * @return false if createScoped does not need to be called. - */ - createScopedRequired() { - messages.warn(messages.JWT_CREATE_SCOPED_DEPRECATED); - return !this.hasScopes(); - } - /** * Determine if there are currently scopes available. */ diff --git a/src/auth/oauth2client.ts b/src/auth/oauth2client.ts index 21b16fb7..163d15a7 100644 --- a/src/auth/oauth2client.ts +++ b/src/auth/oauth2client.ts @@ -759,33 +759,6 @@ export class OAuth2Client extends AuthClient { } } - /** - * Obtain the set of headers required to authenticate a request. - * - * @deprecated Use getRequestHeaders instead. - * @param url the Uri being authorized - * @param callback the func described above - */ - getRequestMetadata(url?: string | null): Promise; - getRequestMetadata( - url: string | null, - callback: RequestMetadataCallback - ): void; - getRequestMetadata( - url: string | null, - callback?: RequestMetadataCallback - ): Promise | void { - messages.warn(messages.OAUTH_GET_REQUEST_METADATA_DEPRECATED); - if (callback) { - this.getRequestMetadataAsync(url).then( - r => callback(null, r.headers, r.res), - callback - ); - } else { - return this.getRequestMetadataAsync(); - } - } - /** * The main authentication interface. It takes an optional url which when * present is the endpoint being accessed, and returns a Promise which diff --git a/src/messages.ts b/src/messages.ts index e7add3eb..57598e4e 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -40,79 +40,3 @@ export interface Warning { message: string; warned?: boolean; } - -export const DEFAULT_PROJECT_ID_DEPRECATED = { - code: 'google-auth-library:DEP002', - type: WarningTypes.DEPRECATION, - message: [ - 'The `getDefaultProjectId` method has been deprecated, and will be removed', - 'in the 3.0 release of google-auth-library. Please use the `getProjectId`', - 'method instead.', - ].join(' '), -}; - -export const COMPUTE_CREATE_SCOPED_DEPRECATED = { - code: 'google-auth-library:DEP003', - type: WarningTypes.DEPRECATION, - message: [ - 'The `createScopedRequired` method on the `Compute` class has been deprecated,', - 'and will be removed in the 3.0 release of google-auth-library.', - ].join(' '), -}; - -export const JWT_CREATE_SCOPED_DEPRECATED = { - code: 'google-auth-library:DEP004', - type: WarningTypes.DEPRECATION, - message: [ - 'The `createScopedRequired` method on the `JWT` class has been deprecated,', - 'and will be removed in the 3.0 release of google-auth-library.', - ].join(' '), -}; - -export const IAM_CREATE_SCOPED_DEPRECATED = { - code: 'google-auth-library:DEP005', - type: WarningTypes.DEPRECATION, - message: [ - 'The `createScopedRequired` method on the `IAM` class has been deprecated,', - 'and will be removed in the 3.0 release of google-auth-library.', - ].join(' '), -}; - -export const JWT_ACCESS_CREATE_SCOPED_DEPRECATED = { - code: 'google-auth-library:DEP006', - type: WarningTypes.DEPRECATION, - message: [ - 'The `createScopedRequired` method on the `JWTAccess` class has been deprecated,', - 'and will be removed in the 3.0 release of google-auth-library.', - ].join(' '), -}; - -export const OAUTH_GET_REQUEST_METADATA_DEPRECATED = { - code: 'google-auth-library:DEP004', - type: WarningTypes.DEPRECATION, - message: [ - 'The `getRequestMetadata` method on the `OAuth2` class has been deprecated,', - 'and will be removed in the 3.0 release of google-auth-library. Please use', - 'the `getRequestHeaders` method instead.', - ].join(' '), -}; - -export const IAM_GET_REQUEST_METADATA_DEPRECATED = { - code: 'google-auth-library:DEP005', - type: WarningTypes.DEPRECATION, - message: [ - 'The `getRequestMetadata` method on the `IAM` class has been deprecated,', - 'and will be removed in the 3.0 release of google-auth-library. Please use', - 'the `getRequestHeaders` method instead.', - ].join(' '), -}; - -export const JWT_ACCESS_GET_REQUEST_METADATA_DEPRECATED = { - code: 'google-auth-library:DEP006', - type: WarningTypes.DEPRECATION, - message: [ - 'The `getRequestMetadata` method on the `JWTAccess` class has been deprecated,', - 'and will be removed in the 3.0 release of google-auth-library. Please use', - 'the `getRequestHeaders` method instead.', - ].join(' '), -}; diff --git a/test/test.compute.ts b/test/test.compute.ts index 974f1daf..365ee60e 100644 --- a/test/test.compute.ts +++ b/test/test.compute.ts @@ -150,19 +150,6 @@ describe('compute', () => { scope.done(); }); - it('should emit warning for createScopedRequired', () => { - let called = false; - sandbox.stub(process, 'emitWarning').callsFake(() => (called = true)); - // tslint:disable-next-line deprecation - compute.createScopedRequired(); - assert.strictEqual(called, true); - }); - - it('should return false for createScopedRequired', () => { - // tslint:disable-next-line deprecation - assert.strictEqual(false, compute.createScopedRequired()); - }); - it('should return a helpful message on request response.statusCode 403', async () => { const scope = mockToken(403); const expected = new RegExp( diff --git a/test/test.googleauth.ts b/test/test.googleauth.ts index c125046d..11bcd62f 100644 --- a/test/test.googleauth.ts +++ b/test/test.googleauth.ts @@ -1407,36 +1407,6 @@ describe('googleauth', () => { assert.strictEqual(value, signedBlob); }); - it('should warn the user if using the getDefaultProjectId method', done => { - mockEnvVar('GCLOUD_PROJECT', STUB_PROJECT); - sandbox - .stub(process, 'emitWarning') - .callsFake((message, warningOrType) => { - assert.strictEqual( - message, - messages.DEFAULT_PROJECT_ID_DEPRECATED.message - ); - const warningType = - typeof warningOrType === 'string' - ? warningOrType - : // @types/node doesn't recognize the emitWarning syntax which - // tslint:disable-next-line no-any - (warningOrType as any).type; - assert.strictEqual(warningType, messages.WarningTypes.DEPRECATION); - done(); - }); - auth.getDefaultProjectId(); - }); - - it('should only emit warnings once', async () => { - // The warning was used above, so invoking it here should have no effect. - mockEnvVar('GCLOUD_PROJECT', STUB_PROJECT); - let count = 0; - sandbox.stub(process, 'emitWarning').callsFake(() => count++); - await auth.getDefaultProjectId(); - assert.strictEqual(count, 0); - }); - it('should pass options to the JWT constructor via constructor', async () => { const subject = 'science!'; const auth = new GoogleAuth({ diff --git a/test/test.iam.ts b/test/test.iam.ts index e382916a..d66fac7a 100644 --- a/test/test.iam.ts +++ b/test/test.iam.ts @@ -16,7 +16,6 @@ import * as assert from 'assert'; import {describe, it, beforeEach, afterEach} from 'mocha'; import * as sinon from 'sinon'; import {IAMAuth} from '../src'; -import * as messages from '../src/messages'; describe('iam', () => { const testSelector = 'a-test-selector'; @@ -38,20 +37,4 @@ describe('iam', () => { assert.strictEqual(creds!['x-goog-iam-authority-selector'], testSelector); assert.strictEqual(creds!['x-goog-iam-authorization-token'], testToken); }); - - it('should warn about deprecation of getRequestMetadata', done => { - const stub = sandbox.stub(messages, 'warn'); - // tslint:disable-next-line deprecation - client.getRequestMetadata(null, () => { - assert.strictEqual(stub.calledOnce, true); - done(); - }); - }); - - it('should emit warning for createScopedRequired', () => { - const stub = sandbox.stub(process, 'emitWarning'); - // tslint:disable-next-line deprecation - client.createScopedRequired(); - assert(stub.called); - }); }); diff --git a/test/test.jwt.ts b/test/test.jwt.ts index 3cfb3f5f..4b26a573 100644 --- a/test/test.jwt.ts +++ b/test/test.jwt.ts @@ -71,14 +71,6 @@ describe('jwt', () => { sandbox.restore(); }); - it('should emit warning for createScopedRequired', () => { - let called = false; - sandbox.stub(process, 'emitWarning').callsFake(() => (called = true)); - // tslint:disable-next-line deprecation - jwt.createScopedRequired(); - assert.strictEqual(called, true); - }); - it('should create a dummy refresh token string', () => { // It is important that the compute client is created with a refresh token // value filled in, or else the rest of the logic will not work. @@ -587,72 +579,6 @@ describe('jwt', () => { assert.notStrictEqual(jwt, clone); }); - it('createScopedRequired should return true when scopes is null', () => { - const jwt = new JWT({ - email: 'foo@serviceaccount.com', - keyFile: '/path/to/key.pem', - subject: 'bar@subjectaccount.com', - }); - // tslint:disable-next-line deprecation - assert.strictEqual(true, jwt.createScopedRequired()); - }); - - it('createScopedRequired should return true when scopes is an empty array', () => { - const jwt = new JWT({ - email: 'foo@serviceaccount.com', - keyFile: '/path/to/key.pem', - scopes: [], - subject: 'bar@subjectaccount.com', - }); - // tslint:disable-next-line deprecation - assert.strictEqual(true, jwt.createScopedRequired()); - }); - - it('createScopedRequired should return true when scopes is an empty string', () => { - const jwt = new JWT({ - email: 'foo@serviceaccount.com', - keyFile: '/path/to/key.pem', - scopes: '', - subject: 'bar@subjectaccount.com', - }); - // tslint:disable-next-line deprecation - assert.strictEqual(true, jwt.createScopedRequired()); - }); - - it('createScopedRequired should return false when scopes is a filled-in string', () => { - const jwt = new JWT({ - email: 'foo@serviceaccount.com', - keyFile: '/path/to/key.pem', - scopes: 'http://foo', - subject: 'bar@subjectaccount.com', - }); - // tslint:disable-next-line deprecation - assert.strictEqual(false, jwt.createScopedRequired()); - }); - - it('createScopedRequired should return false when scopes is a filled-in array', () => { - const jwt = new JWT({ - email: 'foo@serviceaccount.com', - keyFile: '/path/to/key.pem', - scopes: ['http://bar', 'http://foo'], - subject: 'bar@subjectaccount.com', - }); - - // tslint:disable-next-line deprecation - assert.strictEqual(false, jwt.createScopedRequired()); - }); - - it('createScopedRequired should return false when scopes is not an array or a string, but can be used as a string', () => { - const jwt = new JWT({ - email: 'foo@serviceaccount.com', - keyFile: '/path/to/key.pem', - scopes: '2', - subject: 'bar@subjectaccount.com', - }); - // tslint:disable-next-line deprecation - assert.strictEqual(false, jwt.createScopedRequired()); - }); - it('fromJson should error on null json', () => { assert.throws(() => { // Test verifies invalid parameter tests, which requires cast to any. diff --git a/test/test.jwtaccess.ts b/test/test.jwtaccess.ts index b76066cc..ca615b4b 100644 --- a/test/test.jwtaccess.ts +++ b/test/test.jwtaccess.ts @@ -38,21 +38,11 @@ describe('jwtaccess', () => { const email = 'foo@serviceaccount.com'; let client: JWTAccess; - let sandbox: sinon.SinonSandbox; + const sandbox = sinon.createSandbox(); beforeEach(() => { client = new JWTAccess(); - sandbox = sinon.createSandbox(); - }); - afterEach(() => { - sandbox.restore(); - }); - - it('should emit warning for createScopedRequired', () => { - const stub = sandbox.stub(process, 'emitWarning'); - // tslint:disable-next-line deprecation - client.createScopedRequired(); - assert(stub.called); }); + afterEach(() => sandbox.restore()); it('getRequestHeaders should create a signed JWT token as the access token', () => { const client = new JWTAccess(email, keys.private); @@ -106,12 +96,6 @@ describe('jwtaccess', () => { } }); - it('createScopedRequired should return false', () => { - const client = new JWTAccess('foo@serviceaccount.com', null); - // tslint:disable-next-line deprecation - assert.strictEqual(false, client.createScopedRequired()); - }); - it('fromJson should error on null json', () => { assert.throws(() => { // Test verifies invalid parameter tests, which requires cast to any. @@ -183,12 +167,4 @@ describe('jwtaccess', () => { assert.strictEqual(json.private_key, client.key); assert.strictEqual(json.client_email, client.email); }); - - it('should warn about deprecation of getRequestMetadata', () => { - const client = new JWTAccess(email, keys.private); - const stub = sandbox.stub(messages, 'warn'); - // tslint:disable-next-line deprecation - client.getRequestMetadata(testUri); - assert.strictEqual(stub.calledOnce, true); - }); }); diff --git a/test/test.oauth2.ts b/test/test.oauth2.ts index 2ddc95c5..f0b54947 100644 --- a/test/test.oauth2.ts +++ b/test/test.oauth2.ts @@ -1376,14 +1376,6 @@ describe('oauth2', () => { assert.deepStrictEqual(info.scopes, tokenInfo.scope.split(' ')); }); - it('should warn about deprecation of getRequestMetadata', done => { - const stub = sandbox.stub(messages, 'warn'); - client.getRequestMetadata(null, () => { - assert.strictEqual(stub.calledOnce, true); - done(); - }); - }); - it('should throw if tries to refresh but no refresh token is available', async () => { client.setCredentials({ access_token: 'initial-access-token',