Unverified Commit b96213d9 authored by John's avatar John Committed by GitHub
Browse files

Set default signature verification for supported distributions (#1246)

* Default signature verification for supported distributions

* Delegate signature defaults to installers
parent 1dbac3c9
Loading
Loading
Loading
Loading
+1 −1
Changes for README.md: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -159,7 +159,7 @@ steps:
| `force-download` | Always download Java and replace any matching version in the tool cache. | `false` |
| `set-default` | Add Java to `PATH` and set `JAVA_HOME`. When `false`, only version-specific `JAVA_HOME_<major>_<arch>` variables are set. | `true` |
| `problem-matcher` | Register Java compiler and uncaught exception problem matchers. | `true` |
| `verify-signature` | Verify downloaded Java package signatures when supported. Currently supported for `temurin` and `microsoft`. | `false` |
| `verify-signature` | Verify downloaded Java package signatures when supported. Defaults to `true` for `temurin` and `microsoft`, and `false` for other distributions. | Automatically enabled for `temurin` and `microsoft` |
| `verify-signature-public-key` | ASCII-armored GPG public key to use for signature verification. Overrides the bundled key. | |
| `token` | Token for fetching GitHub.com-hosted version manifests, useful on GitHub Enterprise Server when unauthenticated requests are rate-limited. | `${{ github.token }}` on GitHub.com; empty string on GHES |
| `cache` | Enable dependency caching for `maven`, `gradle`, or `sbt`. | |
+2 −3
Changes for __tests__/distributors/microsoft-installer.test.ts: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -398,13 +398,12 @@ describe('downloadTool', () => {
    jest.restoreAllMocks();
  });

  it('verifies signature when enabled', async () => {
  it('verifies signatures by default', async () => {
    const signedDistribution = new MicrosoftDistributions({
      version: '17',
      architecture: 'x64',
      packageType: 'jdk',
      checkLatest: false,
      verifySignature: true
      checkLatest: false
    });

    await signedDistribution['downloadTool']({
+25 −4
Changes for __tests__/distributors/temurin-installer.test.ts: 25 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -457,14 +457,13 @@ describe('downloadTool', () => {
    jest.restoreAllMocks();
  });

  it('verifies signature when enabled', async () => {
  it('verifies signatures by default', async () => {
    const distribution = new TemurinDistribution(
      {
        version: '17',
        architecture: 'x64',
        packageType: 'jdk',
        checkLatest: false,
        verifySignature: true
        checkLatest: false
      },
      TemurinImplementation.Hotspot
    );
@@ -482,6 +481,27 @@ describe('downloadTool', () => {
    );
  });

  it('does not verify signatures when explicitly disabled', async () => {
    const distribution = new TemurinDistribution(
      {
        version: '17',
        architecture: 'x64',
        packageType: 'jdk',
        checkLatest: false,
        verifySignature: false
      },
      TemurinImplementation.Hotspot
    );

    await distribution['downloadTool']({
      version: '17.0.14+7',
      url: 'https://example.com/jdk.tar.gz',
      signatureUrl: 'https://example.com/jdk.tar.gz.sig'
    });

    expect(spyVerifySignature).not.toHaveBeenCalled();
  });

  it('downloads and adds matching JMODs to the JDK', async () => {
    spyDownloadTool
      .mockResolvedValueOnce('/tmp/jdk.tar.gz')
@@ -499,7 +519,8 @@ describe('downloadTool', () => {
        version: '25',
        architecture: 'x64',
        packageType: 'jdk+jmods',
        checkLatest: false
        checkLatest: false,
        verifySignature: false
      },
      TemurinImplementation.Hotspot
    );
+32 −2
Changes for __tests__/setup-java.test.ts: 32 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -161,6 +161,37 @@ describe('setup action orchestration', () => {
    expect(factory.getJavaDistribution).not.toHaveBeenCalled();
  });

  it.each([
    ['temurin', undefined, undefined],
    ['zulu', undefined, undefined],
    ['temurin', false, false],
    ['zulu', true, true]
  ])(
    'passes signature verification input for %s with explicit value %s as %s',
    async (distribution, explicitValue, expectedValue) => {
      inputs.set('distribution', distribution);
      multilineInputs.set('java-version', ['21']);
      if (explicitValue !== undefined) {
        inputs.set('verify-signature', String(explicitValue));
        booleanInputs.set('verify-signature', explicitValue);
      }
      (factory.getJavaDistribution as jest.Mock).mockReturnValue({
        setupJava: jest.fn(async () => ({
          version: '21.0.4+7',
          path: '/opt/java/21'
        }))
      });

      await run();

      expect(factory.getJavaDistribution).toHaveBeenCalledWith(
        distribution,
        expect.objectContaining({verifySignature: expectedValue}),
        ''
      );
    }
  );

  it('requires distribution when it cannot be inferred from the version file', async () => {
    inputs.set('java-version-file', '.java-version');
    (fs.readFileSync as jest.Mock).mockReturnValue(Buffer.from('21'));
@@ -200,7 +231,6 @@ describe('setup action orchestration', () => {
    booleanInputs.set('check-latest', true);
    booleanInputs.set('force-download', true);
    booleanInputs.set('set-default', false);
    booleanInputs.set('verify-signature', true);
    inputs.set('verify-signature-public-key', 'public-key');
    (fs.readFileSync as jest.Mock).mockReturnValue(
      Buffer.from('java=21.0.5-tem')
@@ -232,7 +262,7 @@ describe('setup action orchestration', () => {
        forceDownload: true,
        cacheJdk: false,
        setDefault: false,
        verifySignature: true,
        verifySignature: undefined,
        verifySignaturePublicKey: 'public-key'
      },
      '/tmp/java.tar.gz'
−1
Changes for action.yml: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ inputs:
  verify-signature:
    description: 'Verify downloaded Java package signatures when supported by the selected distribution'
    required: false
    default: false
  verify-signature-public-key:
    description: 'ASCII-armored GPG public key used to verify the downloaded package signature. Overrides the default bundled key for the selected distribution.'
    required: false
Loading