diff --git a/handwritten/spanner/src/index.ts b/handwritten/spanner/src/index.ts index 5b63004d19d..7235b1f8d73 100644 --- a/handwritten/spanner/src/index.ts +++ b/handwritten/spanner/src/index.ts @@ -524,10 +524,7 @@ class Spanner extends GrpcService { this._isInSecureCredentials = options.sslCreds?._isSecure() === false; this.options = options; - this.auth = - options.auth instanceof GoogleAuth - ? options.auth - : new GoogleAuth(this.options); + this.auth = new GoogleAuth(this.options); this.clients_ = new Map(); this.instances_ = new Map(); this.instanceConfigs_ = new Map(); diff --git a/handwritten/spanner/test/index.ts b/handwritten/spanner/test/index.ts index 974fcd6cf82..491735c55a1 100644 --- a/handwritten/spanner/test/index.ts +++ b/handwritten/spanner/test/index.ts @@ -678,11 +678,15 @@ describe('Spanner', () => { } }); - it('should reuse a caller-provided GoogleAuth instance', () => { + it('should not share a caller-provided GoogleAuth instance with Spanner.auth or metrics exporter', () => { const callerAuth = Object.create(fakeGoogleAuth.prototype); callerAuth.getProjectId = cb => cb && cb(null, 'caller-project'); - const clientWithCallerAuth = new Spanner(asAny({auth: callerAuth})); - assert.strictEqual(clientWithCallerAuth.auth, callerAuth); + const clientWithCallerAuth = new Spanner( + asAny({projectId: 'caller-project', auth: callerAuth}), + ); + assert.notStrictEqual(clientWithCallerAuth.auth, callerAuth); + assert.strictEqual(recordedExporterCalls.length, 1); + assert.notStrictEqual(recordedExporterCalls[0].options.auth, callerAuth); assert.notStrictEqual(new Spanner().auth, callerAuth); });