fix(common): preserve DEFAULT_PROJECT_ID_TOKEN in joinURIComponents · akiliscodes/google-cloud-node@a410173 · GitHub
Skip to content

Commit a410173

Browse files
author
akiliscodes
committed
fix(common): preserve DEFAULT_PROJECT_ID_TOKEN in joinURIComponents
encodeURIPath encodes '{{projectId}}' as '%7B%7BprojectId%7D%7D', which prevents replaceProjectIdToken() from finding and substituting the placeholder later in the request lifecycle (decorateRequest → makeAuthenticatedRequest). Skip encoding when the trimmed component equals DEFAULT_PROJECT_ID_TOKEN so that ADC / lazy project-ID resolution continues to work for clients that do not supply an explicit projectId (e.g. new BigQuery()). Regression introduced by googleapis#9188. Fixes googleapis#9256.
1 parent 0f7707b commit a410173

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

‎core/common/src/util.ts‎

Lines changed: 8 additions & 2 deletions

‎core/common/test/service.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,21 @@ describe('Service', () => {
567567
service.request_(reqOpts, assert.ifError);
568568
});
569569

570+
it('should pass DEFAULT_PROJECT_ID_TOKEN unencoded to makeAuthenticatedRequest', done => {
571+
// Regression: #9188 caused {{projectId}} to be encoded as
572+
// %7B%7BprojectId%7D%7D, so replaceProjectIdToken() could no longer
573+
// find and substitute it, causing 404s for ADC clients.
574+
const config = extend({}, CONFIG, {projectIdRequired: true});
575+
const service = new Service(config, {}); // no projectId → DEFAULT_PROJECT_ID_TOKEN
576+
577+
service.makeAuthenticatedRequest = (reqOpts_: DecorateRequestOptions) => {
578+
assert.match(reqOpts_.uri, /projects\/\{\{projectId\}\}\//);
579+
done();
580+
};
581+
582+
service.request_({uri: 'queries'}, assert.ifError);
583+
});
584+
570585
it('should use projectId override', done => {
571586
const config = extend({}, CONFIG, {projectIdRequired: true});
572587
const service = new Service(config, OPTIONS);

‎core/common/test/util.ts‎

Lines changed: 37 additions & 0 deletions

0 commit comments

Comments
 (0)