Skip to content

Commit 5aec75c

Browse files
Merge pull request #86 from codefresh-io/CR-10126-sec
CR-10126-sec
2 parents 66139ac + 14485f5 commit 5aec75c

23 files changed

Lines changed: 3122 additions & 2143 deletions

__tests__/Config.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { Http } = require('../helpers/http');
88
const { ConfigManager, contexts } = require('../lib/auth');
99
const defaults = require('../lib/defaults');
1010

11-
jest.mock('swagger-client', () => jest.fn(options => options));
11+
jest.mock('swagger-client', () => jest.fn((options) => options));
1212

1313
jest.mock('../helpers/http', () => {
1414
let response = { test: 'test' };

__tests__/ConfigManager.spec.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jest.mock('fs', () => {
3232

3333
jest.mock('fs-extra', () => ({ mkdirp: jest.fn() }));
3434

35-
jest.mock('bluebird', () => ({ promisify: func => func }));
35+
jest.mock('bluebird', () => ({ promisify: (func) => func }));
3636

3737
jest.spyOn(manager, 'clearConfig');
3838
jest.spyOn(manager, '_getConfigFilePath');
@@ -41,7 +41,6 @@ jest.spyOn(manager, '_loadConfig');
4141
jest.spyOn(manager, 'addContext');
4242
jest.spyOn(manager, 'isConfigLoaded');
4343

44-
4544
const CONTEXTS = {
4645
contexts: {
4746
jwt: { type: JWTContext.TYPE, name: 'jwt' },
@@ -50,15 +49,14 @@ const CONTEXTS = {
5049
'current-context': 'jwt',
5150
};
5251

53-
5452
describe('ConfigManager', () => {
5553
beforeEach(() => {
5654
const testData = { test: 'test' };
5755
fs._readFile = jest.fn(() => testData);
5856
fs._writeFile = jest.fn();
5957
fse.mkdirp.mockClear();
60-
yaml.safeDump = jest.fn(data => data);
61-
yaml.safeLoad = jest.fn(data => data);
58+
yaml.safeDump = jest.fn((data) => data);
59+
yaml.safeLoad = jest.fn((data) => data);
6260
});
6361

6462
describe('#_loadConfig', () => {
@@ -275,7 +273,7 @@ describe('ConfigManager', () => {
275273
});
276274

277275
it('should do a fallback in case there was a failure during user validation', async () => {
278-
jest.resetModuleRegistry();
276+
jest.resetModules();
279277
const token = 'token';
280278
const url = 'url';
281279

__tests__/Sdk.spec.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const _ = require('lodash');
22
const { Codefresh, Config } = require('../index');
3-
const Clusters = require('../lib/logic/clusters.logic.js');
4-
const Workflows = require('../lib/logic/workflows.logic.js');
5-
3+
const Clusters = require('../lib/logic/clusters.logic');
4+
const Workflows = require('../lib/logic/workflows.logic');
65

76
jest.mock('fs', () => ({
87
readdirSync: () => [
@@ -18,7 +17,6 @@ jest.mock('fs-extra', () => ({ mkdirp: () => ({}) }));
1817
jest.mock('../lib/logic/clusters.logic.js');
1918
jest.mock('../lib/logic/workflows.logic.js');
2019

21-
2220
const swaggerApis = {
2321
clusters: { clusters_list: () => 'clusters_list' },
2422
workflows: { workflows_list: () => 'workflows_list' },
@@ -41,7 +39,6 @@ const spec = {
4139
},
4240
};
4341

44-
4542
describe('Sdk', () => {
4643
describe('loading', () => {
4744
it('should load Sdk from logic and api spec', async () => {

__tests__/helpers.spec.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const defaults = require('../lib/defaults');
44
const { postProcessApi, _resolveArgs, _wrapHandler } = require('../helpers/api');
55
const { handleErrors } = require('../helpers/error');
66
const { Http } = require('../helpers/http');
7-
const { version } = require('../package');
7+
const { version } = require('../package.json');
88

99
jest.mock('../helpers/error', () => ({ handleErrors: jest.fn() }));
1010

@@ -50,7 +50,6 @@ const swaggerApis = {
5050
},
5151
};
5252

53-
5453
describe('helpers', () => {
5554
describe('api', () => {
5655
describe('postProcessApi', () => {
@@ -147,7 +146,7 @@ describe('helpers', () => {
147146

148147
describe('http', () => {
149148
beforeEach(() => {
150-
JSON.parse = jest.fn(res => res);
149+
JSON.parse = jest.fn((res) => res);
151150
});
152151

153152
it('should use defaults when request options are not provided', () => {

__tests__/logs.helper.unit.spec.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ const mockedClose = jest.fn();
55
const mockedSubscribe = jest.fn();
66
jest.mock('@codefresh-io/cf-receiver', () => ({
77
CfReceiverService: class CfReceiverService {
8-
constructor() {
9-
return null;
10-
}
11-
128
watch() {
139
return this;
1410
}
@@ -23,7 +19,6 @@ jest.mock('@codefresh-io/cf-receiver', () => ({
2319
},
2420
}));
2521

26-
2722
describe('logs helpers', () => {
2823
beforeEach(() => {
2924
mockedClose.mockClear();
@@ -33,7 +28,7 @@ describe('logs helpers', () => {
3328
it('should close ws connection with flag -f and with failure result', async () => {
3429
const sdk = _.set({}, 'config.context', { url: String(), token: String() });
3530
mockedSubscribe.mockReturnValue(null);
36-
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, true, sdk).catch(err => err);
31+
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, true, sdk).catch((err) => err);
3732
expect(mockedClose.mock.calls.length).toEqual(1);
3833
expect(_.isError(result)).toEqual(true);
3934
});
@@ -42,7 +37,7 @@ describe('logs helpers', () => {
4237
const validMsg = { type: 'message', event: { data: JSON.stringify({ msgID: 'getStatus', payload: null }) } };
4338
const sdk = _.set({}, 'config.context', { url: String(), token: String() });
4439
mockedSubscribe.mockReturnValue(validMsg);
45-
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, true, sdk).catch(err => err);
40+
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, true, sdk).catch((err) => err);
4641
expect(mockedClose.mock.calls.length).toEqual(1);
4742
expect(_.isError(result)).toEqual(false);
4843
});
@@ -51,15 +46,15 @@ describe('logs helpers', () => {
5146
const validMsg = { type: 'message', event: { data: JSON.stringify({ slot: 'status', payload: 'success' }) } };
5247
const sdk = _.set({}, 'config.context', { url: String(), token: String() });
5348
mockedSubscribe.mockReturnValue(validMsg);
54-
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, true, sdk).catch(err => err);
49+
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, true, sdk).catch((err) => err);
5550
expect(mockedClose.mock.calls.length).toEqual(1);
5651
expect(_.isError(result)).toEqual(false);
5752
});
5853

5954
it('should close ws connection without flag -f and with failure result', async () => {
6055
const sdk = _.set({}, 'config.context', { url: String(), token: String() });
6156
mockedSubscribe.mockReturnValue(null);
62-
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, false, sdk).catch(err => err);
57+
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, false, sdk).catch((err) => err);
6358
expect(mockedClose.mock.calls.length).toEqual(1);
6459
expect(_.isError(result)).toEqual(true);
6560
});
@@ -68,7 +63,7 @@ describe('logs helpers', () => {
6863
const validMsg = { type: 'message', event: { data: JSON.stringify({ slot: 'keepAlive' }) } };
6964
const sdk = _.set({}, 'config.context', { url: String(), token: String() });
7065
mockedSubscribe.mockReturnValue(validMsg);
71-
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, false, sdk).catch(err => err);
66+
const result = await logsHelper.showWorkflowLogsByWebsocket(null, null, false, sdk).catch((err) => err);
7267
expect(mockedClose.mock.calls.length).toEqual(1);
7368
expect(_.isError(result)).toEqual(false);
7469
});

__tests__/test.unit.spec.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

__tests__/whoami.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ jest.mock('../helpers/http', () => {
3636
return { Http: HttpConstructor };
3737
});
3838

39-
4039
describe('whoami', () => {
4140
beforeEach(() => {
4241
Http.__reset();

codefresh.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ steps:
1515
install_dependencies:
1616
title: 'Installing testing dependencies'
1717
stage: CI
18-
image: codefresh/node-tester-image:10.13.0
18+
image: codefresh/node-tester-image:10.15.3
1919
commands:
2020
- yarn install --frozen-lockfile
2121

2222
eslint:
2323
title: 'Running linting logic'
2424
stage: CI
25-
image: codefresh/node-tester-image:10.13.0
25+
image: codefresh/node-tester-image:10.15.3
2626
commands:
2727
- yarn eslint
2828

2929
unit-tests:
3030
stage: CI
3131
title: 'Running unit tests'
32-
image: codefresh/node-tester-image:10.13.0
32+
image: codefresh/node-tester-image:10.15.3
3333
commands:
3434
- yarn test
3535

helpers/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const debug = require('debug')('codefresh:sdk:http');
44
const defaults = require('../lib/defaults');
55
const { version } = require('../package.json');
66

7-
const { handleErrors } = require('../helpers/error');
7+
const { handleErrors } = require('./error');
88

99
const RETRY_STATUS_CODES = [502, 503, 504];
1010
const RETRY_STRATEGY = (err, response) => {

helpers/jwt.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const debug = require('debug')('codefresh:sdk:jwt');
22
const jwt = require('jsonwebtoken');
33

4-
54
const testJwt = (token) => {
65
let isJwt = false;
76
try {

0 commit comments

Comments
 (0)