Add cacerts parameter, which can copy existing cacerts into JDK

This commit is contained in:
Michal Dvorak 2022-01-17 17:11:15 +01:00 committed by Michal Dvořák
parent d53b046579
commit 0d42bcacb6
No known key found for this signature in database
GPG key ID: 42E7AE26FA8092D2
11 changed files with 2167 additions and 2075 deletions

View file

@ -11,6 +11,7 @@ import {
JavaInstallerOptions,
JavaInstallerResults
} from '../../src/distributions/base-models';
import fs from "fs";
class EmptyJavaBase extends JavaBase {
constructor(installerOptions: JavaInstallerOptions) {
@ -349,3 +350,43 @@ describe('getToolcacheVersionName', () => {
expect(actual).toBe(expected);
});
});
describe('initCacerts', () => {
const DummyJavaBase = JavaBase as any;
let spyFsCopyFileSync: jest.SpyInstance;
beforeEach(() => {
spyFsCopyFileSync = jest.spyOn(fs, 'copyFileSync').mockImplementation();
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
jest.restoreAllMocks();
});
it('should do nothing when not set', () => {
const mockJavaBase = new EmptyJavaBase({
version: '11',
packageType: 'jdk',
architecture: 'x64',
checkLatest: false,
cacerts: '',
});
DummyJavaBase.prototype.initCacerts.call(mockJavaBase, '/tmp/dummy_jdk');
expect(spyFsCopyFileSync).not.toHaveBeenCalled()
});
it('should copy cacerts file', () => {
const mockJavaBase = new EmptyJavaBase({
version: '11',
packageType: 'jdk',
architecture: 'x64',
checkLatest: false,
cacerts: '/etc/ssl/certs/java/cacerts',
});
DummyJavaBase.prototype.initCacerts.call(mockJavaBase, '/tmp/dummy_jdk');
expect(spyFsCopyFileSync).toHaveBeenCalledWith('/etc/ssl/certs/java/cacerts', path.join('/tmp/dummy_jdk', 'lib/security/cacerts'))
});
});