Add 1000-page safeguard for JetBrains pagination

This commit is contained in:
copilot-swe-agent[bot] 2026-06-03 15:50:15 +00:00 committed by GitHub
parent ff272af875
commit 7ee69becdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View File

@ -9,6 +9,8 @@ import * as core from '@actions/core';
describe('getAvailableVersions', () => { describe('getAvailableVersions', () => {
let spyHttpClient: jest.SpyInstance; let spyHttpClient: jest.SpyInstance;
let spyCoreError: jest.SpyInstance; let spyCoreError: jest.SpyInstance;
let spyCoreWarning: jest.SpyInstance;
let spyHeadRequest: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson'); spyHttpClient = jest.spyOn(HttpClient.prototype, 'getJson');
@ -21,6 +23,14 @@ describe('getAvailableVersions', () => {
// Mock core.error to suppress error logs // Mock core.error to suppress error logs
spyCoreError = jest.spyOn(core, 'error'); spyCoreError = jest.spyOn(core, 'error');
spyCoreError.mockImplementation(() => {}); spyCoreError.mockImplementation(() => {});
spyCoreWarning = jest.spyOn(core, 'warning');
spyCoreWarning.mockImplementation(() => {});
spyHeadRequest = jest.spyOn(HttpClient.prototype, 'head');
spyHeadRequest.mockResolvedValue({
message: {
statusCode: 404
}
} as any);
}); });
afterEach(() => { afterEach(() => {
@ -50,6 +60,27 @@ describe('getAvailableVersions', () => {
os.platform() === 'win32' ? manifestData.length : manifestData.length + 2; os.platform() === 'win32' ? manifestData.length : manifestData.length + 2;
expect(availableVersions.length).toBe(length); expect(availableVersions.length).toBe(length);
}, 10_000); }, 10_000);
it('stops pagination after 1000 pages as a safeguard', async () => {
spyHttpClient.mockResolvedValue({
statusCode: 200,
headers: {},
result: [{tag_name: 'jbr17-b87.7', name: 'jbr17-b87.7', prerelease: false}]
});
const distribution = new JetBrainsDistribution({
version: '17',
architecture: 'x64',
packageType: 'jdk',
checkLatest: false
});
await distribution['getAvailableVersions']();
expect(spyHttpClient).toHaveBeenCalledTimes(1000);
expect(spyCoreWarning).toHaveBeenCalledWith(
expect.stringContaining('Reached pagination safeguard limit (1000 pages)')
);
}, 20_000);
}); });
describe('findPackageForDownload', () => { describe('findPackageForDownload', () => {

View File

@ -16,6 +16,8 @@ import {extractJdkFile, isVersionSatisfies} from '../../util';
import {OutgoingHttpHeaders} from 'http'; import {OutgoingHttpHeaders} from 'http';
import {HttpCodes} from '@actions/http-client'; import {HttpCodes} from '@actions/http-client';
const MAX_PAGINATION_PAGES = 1000;
export class JetBrainsDistribution extends JavaBase { export class JetBrainsDistribution extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) { constructor(installerOptions: JavaInstallerOptions) {
super('JetBrains', installerOptions); super('JetBrains', installerOptions);
@ -93,7 +95,7 @@ export class JetBrainsDistribution extends JavaBase {
const rawVersions: IJetBrainsRawVersion[] = []; const rawVersions: IJetBrainsRawVersion[] = [];
const bearerToken = process.env.GITHUB_TOKEN; const bearerToken = process.env.GITHUB_TOKEN;
while (true) { while (page_index <= MAX_PAGINATION_PAGES) {
const requestArguments = `per_page=100&page=${page_index}`; const requestArguments = `per_page=100&page=${page_index}`;
const requestHeaders: OutgoingHttpHeaders = {}; const requestHeaders: OutgoingHttpHeaders = {};
@ -129,6 +131,12 @@ export class JetBrainsDistribution extends JavaBase {
page_index++; page_index++;
} }
if (page_index > MAX_PAGINATION_PAGES) {
core.warning(
`Reached pagination safeguard limit (${MAX_PAGINATION_PAGES} pages) while listing JetBrains runtime releases.`
);
}
if (this.stable) { if (this.stable) {
// Add versions not available from the API but are downloadable // Add versions not available from the API but are downloadable
const hidden = ['11_0_10b1145.115', '11_0_11b1341.60']; const hidden = ['11_0_10b1145.115', '11_0_11b1341.60'];