mirror of
https://github.com/actions/setup-java.git
synced 2026-09-09 20:24:21 +02:00
* Fix import-safe checks when scripts are run from a path with symlinks In v6, setup-java was made "import-safe" to facilitate testing. This prevents setup-java & cleanup-java from doing anything when their sources get imported. This works fine in the general case, but actually invoking the script (`node setup-java/index.js`) when the path to the script contains symlinks led to the script incorrectly believing it was imported, and refuse to actually run. To fix this, we pass `process.argv[1]` through `fs.realpathSync`, which resolves symlinks in the path. Fixes #1264 * Preserve import safety when resolving symlink entrypoints Share entrypoint detection between setup and cleanup, handle non-file entrypoints safely, and normalize both paths for preserved symlinks. Add real-process regression coverage and rebuild action bundles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 831c32f2-a275-45bd-a92b-c387372a1554 * Update js-yaml to fix merge-source denial of service Bump the transitive development dependency from 3.15.1 to 3.15.2 to address GHSA-2883-xcg3-v3hh without changing dependency ranges or CI checks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 831c32f2-a275-45bd-a92b-c387372a1554 --------- Co-authored-by: Bruno Borges <brborges@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 831c32f2-a275-45bd-a92b-c387372a1554
122 lines
3.6 KiB
TypeScript
122 lines
3.6 KiB
TypeScript
import {jest, describe, it, expect, beforeEach} from '@jest/globals';
|
|
|
|
jest.unstable_mockModule('@actions/core', () => ({
|
|
info: jest.fn(),
|
|
warning: jest.fn(),
|
|
debug: jest.fn(),
|
|
error: jest.fn(),
|
|
notice: jest.fn(),
|
|
setFailed: jest.fn(),
|
|
setOutput: jest.fn(),
|
|
getInput: jest.fn(),
|
|
getBooleanInput: jest.fn(),
|
|
getMultilineInput: jest.fn(),
|
|
addPath: jest.fn(),
|
|
exportVariable: jest.fn(),
|
|
saveState: jest.fn(),
|
|
getState: jest.fn(),
|
|
setSecret: jest.fn(),
|
|
isDebug: jest.fn(() => false),
|
|
startGroup: jest.fn(),
|
|
endGroup: jest.fn(),
|
|
group: jest.fn((_name: string, fn: () => Promise<unknown>) => fn()),
|
|
toPlatformPath: jest.fn((value: string) => value),
|
|
toWin32Path: jest.fn((value: string) => value),
|
|
toPosixPath: jest.fn((value: string) => value)
|
|
}));
|
|
|
|
jest.unstable_mockModule('fs', () => ({
|
|
default: {
|
|
...jest.requireActual<typeof import('fs')>('fs'),
|
|
readFileSync: jest.fn()
|
|
}
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/util.js', () => ({
|
|
getBooleanInput: jest.fn(),
|
|
getVersionFromFileContent: jest.fn(),
|
|
isJdkCacheEnabled: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/toolchains.js', () => ({
|
|
validateToolchainIds: jest.fn(),
|
|
configureToolchains: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule(
|
|
'../src/distributions/distribution-factory.js',
|
|
() => ({
|
|
getJavaDistribution: jest.fn()
|
|
})
|
|
);
|
|
|
|
jest.unstable_mockModule('../src/auth.js', () => ({
|
|
configureAuthentication: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/maven-args.js', () => ({
|
|
configureMavenArgs: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/problem-matcher.js', () => ({
|
|
configureProblemMatcher: jest.fn()
|
|
}));
|
|
|
|
// These modules should never be imported when `cache` input is empty.
|
|
jest.unstable_mockModule('../src/cache-feature.js', () => {
|
|
throw new Error('cache-feature module should not be loaded');
|
|
});
|
|
jest.unstable_mockModule('../src/cache.js', () => {
|
|
throw new Error('cache module should not be loaded');
|
|
});
|
|
|
|
const core = await import('@actions/core');
|
|
const util = await import('../src/util.js');
|
|
const toolchains = await import('../src/toolchains.js');
|
|
const factory = await import('../src/distributions/distribution-factory.js');
|
|
const {run} = await import('../src/setup-java.js');
|
|
|
|
describe('setup-java conditional module loading', () => {
|
|
const inputs = new Map<string, string>();
|
|
const multilineInputs = new Map<string, string[]>();
|
|
const booleanInputs = new Map<string, boolean>();
|
|
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
inputs.clear();
|
|
multilineInputs.clear();
|
|
booleanInputs.clear();
|
|
|
|
(core.getInput as jest.Mock).mockImplementation((name: unknown) => {
|
|
return inputs.get(name as string) ?? '';
|
|
});
|
|
(core.getMultilineInput as jest.Mock).mockImplementation(
|
|
(name: unknown) => {
|
|
return multilineInputs.get(name as string) ?? [];
|
|
}
|
|
);
|
|
(util.getBooleanInput as jest.Mock).mockImplementation(
|
|
(name: unknown, defaultValue: unknown) => {
|
|
return booleanInputs.get(name as string) ?? defaultValue;
|
|
}
|
|
);
|
|
(util.isJdkCacheEnabled as jest.Mock).mockReturnValue(false);
|
|
(toolchains.configureToolchains as jest.Mock).mockResolvedValue(undefined);
|
|
});
|
|
|
|
it('does not import cache modules when cache input is not provided', async () => {
|
|
inputs.set('distribution', 'temurin');
|
|
multilineInputs.set('java-version', ['21']);
|
|
(factory.getJavaDistribution as jest.Mock).mockResolvedValue({
|
|
setupJava: jest.fn(async () => ({
|
|
version: '21.0.4+7',
|
|
path: '/opt/java/21'
|
|
}))
|
|
});
|
|
|
|
await run();
|
|
|
|
expect(core.setFailed).not.toHaveBeenCalled();
|
|
});
|
|
});
|