Skip to content

Commit

Permalink
Merge pull request #325 from tiobe/34408-qserver_install
Browse files Browse the repository at this point in the history
Fixed TICSQServer installation bug (#34408)
  • Loading branch information
janssen-tiobe authored Jun 12, 2024
2 parents bfdafdf + 17df77b commit 3586e7a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 87 deletions.
37 changes: 30 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ const core_1 = __nccwpck_require__(42186);
const utils_1 = __nccwpck_require__(77721);
const logger_1 = __nccwpck_require__(26440);
const install_tics_1 = __nccwpck_require__(48569);
const environment_1 = __nccwpck_require__(65250);
var Mode;
(function (Mode) {
Mode["CLIENT"] = "client";
Expand Down Expand Up @@ -1306,24 +1307,27 @@ class TicsConfiguration {
*/
setVariables() {
// variable set to replace the loading bar with synchronising... in the install script
(0, core_1.exportVariable)('TICSCI', 1);
(0, environment_1.setVariable)('TICSCI', '1');
if (this.mode === Mode.CLIENT || this.mode === Mode.DIAGNOSTIC) {
(0, core_1.exportVariable)('TICSIDE', 'GITHUB');
(0, environment_1.setVariable)('TICSIDE', 'GITHUB');
}
else if (process.env.TICSIDE) {
(0, environment_1.unsetVariable)('TICSIDE');
}
// set ticsAuthToken
if (this.ticsAuthToken) {
(0, core_1.exportVariable)('TICSAUTHTOKEN', this.ticsAuthToken);
(0, environment_1.setVariable)('TICSAUTHTOKEN', this.ticsAuthToken);
}
// set hostnameVerification
(0, core_1.exportVariable)('TICSHOSTNAMEVERIFICATION', this.hostnameVerification);
(0, environment_1.setVariable)('TICSHOSTNAMEVERIFICATION', this.hostnameVerification.toString());
if (!this.hostnameVerification) {
(0, core_1.exportVariable)('NODE_TLS_REJECT_UNAUTHORIZED', 0);
(0, environment_1.setVariable)('NODE_TLS_REJECT_UNAUTHORIZED', '0');
logger_1.logger.debug('Hostname Verification disabled');
}
// set trustStrategy
(0, core_1.exportVariable)('TICSTRUSTSTRATEGY', this.trustStrategy);
(0, environment_1.setVariable)('TICSTRUSTSTRATEGY', this.trustStrategy);
if ((0, utils_1.isOneOf)(this.trustStrategy, TrustStrategy.SELFSIGNED, TrustStrategy.ALL)) {
(0, core_1.exportVariable)('NODE_TLS_REJECT_UNAUTHORIZED', 0);
(0, environment_1.setVariable)('NODE_TLS_REJECT_UNAUTHORIZED', '0');
logger_1.logger.debug(`Trust strategy set to ${this.trustStrategy}`);
}
}
Expand Down Expand Up @@ -1839,6 +1843,25 @@ var Status;
})(Status || (exports.Status = Status = {}));


/***/ }),

/***/ 65250:
/***/ ((__unused_webpack_module, exports) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.unsetVariable = exports.setVariable = void 0;
function setVariable(key, value) {
process.env[key] = value;
}
exports.setVariable = setVariable;
function unsetVariable(key) {
process.env[key] = '';
}
exports.unsetVariable = unsetVariable;


/***/ }),

/***/ 26440:
Expand Down
19 changes: 11 additions & 8 deletions src/configuration/tics.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getInput, getBooleanInput, exportVariable } from '@actions/core';
import { getInput, getBooleanInput } from '@actions/core';

import { isOneOf } from '../helper/utils';
import { logger } from '../helper/logger';
import { getBaseUrl } from '@tiobe/install-tics';
import { setVariable, unsetVariable } from '../helper/environment';

export enum Mode {
CLIENT = 'client',
Expand Down Expand Up @@ -155,30 +156,32 @@ export class TicsConfiguration {
*/
private setVariables() {
// variable set to replace the loading bar with synchronising... in the install script
exportVariable('TICSCI', 1);
setVariable('TICSCI', '1');

if (this.mode === Mode.CLIENT || this.mode === Mode.DIAGNOSTIC) {
exportVariable('TICSIDE', 'GITHUB');
setVariable('TICSIDE', 'GITHUB');
} else if (process.env.TICSIDE) {
unsetVariable('TICSIDE')
}

// set ticsAuthToken
if (this.ticsAuthToken) {
exportVariable('TICSAUTHTOKEN', this.ticsAuthToken);
setVariable('TICSAUTHTOKEN', this.ticsAuthToken);
}

// set hostnameVerification
exportVariable('TICSHOSTNAMEVERIFICATION', this.hostnameVerification);
setVariable('TICSHOSTNAMEVERIFICATION', this.hostnameVerification.toString());

if (!this.hostnameVerification) {
exportVariable('NODE_TLS_REJECT_UNAUTHORIZED', 0);
setVariable('NODE_TLS_REJECT_UNAUTHORIZED', '0');
logger.debug('Hostname Verification disabled');
}

// set trustStrategy
exportVariable('TICSTRUSTSTRATEGY', this.trustStrategy);
setVariable('TICSTRUSTSTRATEGY', this.trustStrategy);

if (isOneOf(this.trustStrategy, TrustStrategy.SELFSIGNED, TrustStrategy.ALL)) {
exportVariable('NODE_TLS_REJECT_UNAUTHORIZED', 0);
setVariable('NODE_TLS_REJECT_UNAUTHORIZED', '0');
logger.debug(`Trust strategy set to ${this.trustStrategy}`);
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/helper/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function setVariable(key: string, value: string): void {
process.env[key] = value;
}

export function unsetVariable(key: string): void {
process.env[key] = '';
}
1 change: 0 additions & 1 deletion test/.setup/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ jest.mock('@actions/github', () => {

jest.mock('@actions/core', () => {
return {
exportVariable: jest.fn(),
info: jest.fn(),
debug: jest.fn(),
notice: jest.fn(),
Expand Down
143 changes: 72 additions & 71 deletions test/unit/configuration/tics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Mode, TicsConfiguration, TrustStrategy } from '../../../src/configurati

describe('TICS Configuration', () => {
let values: Record<string, string>;
const environment = process.env;

let expectDefault = {
filelist: '',
Expand All @@ -18,6 +19,7 @@ describe('TICS Configuration', () => {
};

beforeEach(() => {
jest.resetModules()
jest.spyOn(core, 'getInput').mockImplementation((name, _options): string => {
for (const value in values) {
if (value === name) {
Expand All @@ -41,6 +43,7 @@ describe('TICS Configuration', () => {

afterEach(() => {
jest.resetAllMocks();
process.env = { ...environment }
});

describe('Validate URLs', () => {
Expand Down Expand Up @@ -375,78 +378,76 @@ describe('TICS Configuration', () => {
});
});

test('Should set every value correctly and set the variables (Client)', () => {
const exportSpy = jest.spyOn(core, 'exportVariable');

values = {
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: 'false',
installTics: 'true',
mode: 'client',
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: 'self-signed',
displayUrl: 'http://viewer.url'
};

const ticsConfig = new TicsConfiguration();

expect(ticsConfig).toMatchObject({
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: false,
installTics: true,
mode: Mode.CLIENT,
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: TrustStrategy.SELFSIGNED,
baseUrl: 'http://localhost/tiobeweb/TICS',
displayUrl: 'http://viewer.url/'
describe('Environment tests', () => {
test('Should set every value correctly and set the variables (Client)', () => {
values = {
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: 'false',
installTics: 'true',
mode: 'client',
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: 'self-signed',
displayUrl: 'http://viewer.url'
};

const ticsConfig = new TicsConfiguration();

expect(ticsConfig).toMatchObject({
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: false,
installTics: true,
mode: Mode.CLIENT,
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: TrustStrategy.SELFSIGNED,
baseUrl: 'http://localhost/tiobeweb/TICS',
displayUrl: 'http://viewer.url/'
});
expect(process.env.TICSCI).toEqual('1')
expect(process.env.TICSIDE).toEqual('GITHUB');
expect(process.env.TICSAUTHTOKEN).toEqual('auth-token');
expect(process.env.TICSHOSTNAMEVERIFICATION).toEqual('false');
expect(process.env.TICSTRUSTSTRATEGY).toEqual('self-signed');
expect(process.env.NODE_TLS_REJECT_UNAUTHORIZED).toEqual('0');
});
expect(exportSpy).toHaveBeenCalledTimes(7);
expect(exportSpy).toHaveBeenCalledWith('TICSCI', 1);
expect(exportSpy).toHaveBeenCalledWith('TICSIDE', 'GITHUB');
expect(exportSpy).toHaveBeenCalledWith('TICSAUTHTOKEN', 'auth-token');
expect(exportSpy).toHaveBeenCalledWith('TICSHOSTNAMEVERIFICATION', false);
expect(exportSpy).toHaveBeenCalledWith('TICSTRUSTSTRATEGY', 'self-signed');
expect(exportSpy).toHaveBeenCalledWith('NODE_TLS_REJECT_UNAUTHORIZED', 0);
});

test('Should set every value correctly and set the variables (QServer)', () => {
values = {
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: 'false',
installTics: 'true',
mode: 'qserver',
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: 'self-signed',
displayUrl: 'http://viewer.url'
};

const ticsConfig = new TicsConfiguration();

expect(ticsConfig).toMatchObject({
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: false,
installTics: true,
mode: Mode.QSERVER,
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: TrustStrategy.SELFSIGNED,
baseUrl: 'http://localhost/tiobeweb/TICS',
displayUrl: 'http://viewer.url/'
});

test('Should set every value correctly and set the variables (QServer)', () => {
const exportSpy = jest.spyOn(core, 'exportVariable');

values = {
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: 'false',
installTics: 'true',
mode: 'qserver',
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: 'self-signed',
displayUrl: 'http://viewer.url'
};

const ticsConfig = new TicsConfiguration();

expect(ticsConfig).toMatchObject({
filelist: './filelist',
githubToken: 'github-token',
hostnameVerification: false,
installTics: true,
mode: Mode.QSERVER,
ticsAuthToken: 'auth-token',
viewerUrl: 'http://localhost/tiobeweb/TICS/api/cfg?name=default',
trustStrategy: TrustStrategy.SELFSIGNED,
baseUrl: 'http://localhost/tiobeweb/TICS',
displayUrl: 'http://viewer.url/'
expect(process.env.TICSCI).toEqual('1')
expect(process.env.TICSIDE).toEqual(undefined);
expect(process.env.TICSAUTHTOKEN).toEqual('auth-token');
expect(process.env.TICSHOSTNAMEVERIFICATION).toEqual('false');
expect(process.env.TICSTRUSTSTRATEGY).toEqual('self-signed');
expect(process.env.NODE_TLS_REJECT_UNAUTHORIZED).toEqual('0');
});
expect(exportSpy).toHaveBeenCalledTimes(6);
expect(exportSpy).toHaveBeenCalledWith('TICSCI', 1);
expect(exportSpy).toHaveBeenCalledWith('TICSAUTHTOKEN', 'auth-token');
expect(exportSpy).toHaveBeenCalledWith('TICSHOSTNAMEVERIFICATION', false);
expect(exportSpy).toHaveBeenCalledWith('TICSTRUSTSTRATEGY', 'self-signed');
expect(exportSpy).toHaveBeenCalledWith('NODE_TLS_REJECT_UNAUTHORIZED', 0);
});
})
});

0 comments on commit 3586e7a

Please sign in to comment.