fix: BitbuckerUrlReader ignoring provided token #31348

Signed-off-by: RedlineTriad <39059512+RedlineTriad@users.noreply.github.com>
This commit is contained in:
RedlineTriad
2025-10-08 09:50:11 +00:00
parent 3ce99627d0
commit b2f6a5ab24
3 changed files with 41 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-defaults': patch
---
Fix #31348 issue where BitbucketUrlReader ignored provided token and instead always used integration credentials
@@ -130,6 +130,27 @@ describe('BitbucketUrlReader', () => {
expect(buffer.toString()).toBe('foo');
});
it('should be able to readUrl using provided token', async () => {
worker.use(
rest.get(
'https://api.bitbucket.org/2.0/repositories/backstage-verification/test-template/src/master/template.yaml',
(req, res, ctx) => {
expect(req.headers.get('authorization')).toBe(
'Bearer manual-token',
);
return res(ctx.status(200), ctx.body('foo'));
},
),
);
const result = await bitbucketProcessor.readUrl(
'https://bitbucket.org/backstage-verification/test-template/src/master/template.yaml',
{ token: 'manual-token' },
);
const buffer = await result.buffer();
expect(buffer.toString()).toBe('foo');
});
it('should be able to readUrl via stream without ETag', async () => {
worker.use(
rest.get(
@@ -93,13 +93,27 @@ export class BitbucketUrlReader implements UrlReaderService {
return response.buffer();
}
private getCredentials = async (options?: {
token?: string;
}): Promise<{ headers: Record<string, string> }> => {
if (options?.token) {
return {
headers: {
Authorization: `Bearer ${options.token}`,
},
};
}
return await getBitbucketRequestOptions(this.integration.config);
};
async readUrl(
url: string,
options?: UrlReaderServiceReadUrlOptions,
): Promise<UrlReaderServiceReadUrlResponse> {
const { etag, lastModifiedAfter, signal } = options ?? {};
const bitbucketUrl = getBitbucketFileFetchUrl(url, this.integration.config);
const requestOptions = getBitbucketRequestOptions(this.integration.config);
const requestOptions = await this.getCredentials(options);
let response: Response;
try {