Skip to content

Commit a1750cb

Browse files
CR-10360 -- security fixes (#733)
* CR-10360 -- security fixes * fix linter errors * fix Dockerfile * update node version + update pkg + update binary node version + update node-tester-image * check another image * fix node-tester-image * fix test * Revert "fix test" This reverts commit 4e9349b. * fix test * fix jq * fix docker file * update version * add small e2e tests * fix * rearrange e2e * refactor e2e tests * fix * add docker ignore for e2e
1 parent 42ac97a commit a1750cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1669
-975
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ codefresh.yml
1212
.coveralls.yml
1313
examples
1414
dist
15+
e2e

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# go hub binary
22
FROM golang:alpine as go
33
RUN apk --update add ca-certificates git
4-
RUN go get github.com/github/hub
4+
RUN go install github.com/github/hub@latest
55

66
# python yq binary
77
FROM six8/pyinstaller-alpine:alpine-3.6-pyinstaller-v3.4 as yq
@@ -11,9 +11,9 @@ RUN pip install yq==${YQ_VERSION}
1111
RUN pyinstaller --noconfirm --onefile --log-level DEBUG --clean --distpath /tmp/ $(which yq)
1212

1313
# Main
14-
FROM node:10.23.0-alpine3.11
14+
FROM node:12.22.11-alpine3.15
1515

16-
RUN apk --update add --no-cache ca-certificates git curl bash yarn jq=1.6-r0
16+
RUN apk --update add --no-cache ca-certificates git curl bash jq
1717

1818
COPY --from=go /go/bin/hub /usr/local/bin/hub
1919
COPY --from=yq /tmp/yq /usr/local/bin/yq
@@ -31,7 +31,6 @@ RUN yarn install --prod --frozen-lockfile && \
3131
COPY . /cf-cli
3232

3333
RUN yarn generate-completion
34-
RUN apk del yarn
3534

3635
RUN ln -s $(pwd)/lib/interface/cli/codefresh /usr/local/bin/codefresh
3736

codefresh.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,30 @@ steps:
1212

1313
install_dependencies:
1414
title: 'Installing testing dependencies'
15-
image: codefresh/node-tester-image:10.15.3
15+
image: quay.io/codefresh/node-tester-image:12.21.0
1616
commands:
1717
- yarn install --frozen-lockfile
1818

19-
eslint:
20-
title: 'Running linting logic'
21-
image: codefresh/node-tester-image:10.15.3
22-
commands:
23-
- yarn eslint
19+
parallel_tests:
20+
type: parallel
21+
steps:
22+
eslint:
23+
title: 'Running linting logic'
24+
image: quay.io/codefresh/node-tester-image:12.21.0
25+
commands:
26+
- yarn eslint
2427

25-
unit-tests:
26-
title: 'Running unit tests'
27-
image: codefresh/node-tester-image:10.15.3
28-
commands:
29-
- yarn test
28+
unit-tests:
29+
title: 'Running unit tests'
30+
image: quay.io/codefresh/node-tester-image:12.21.0
31+
commands:
32+
- yarn test
33+
34+
e2e-tests:
35+
title: 'Running e2e tests'
36+
image: quay.io/codefresh/node-tester-image:12.21.0
37+
commands:
38+
- yarn e2e
3039

3140
extract_version:
3241
title: "Exporting package.json version"

e2e/e2e.spec.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# fail if one of the commands returns non-zero code
2+
set -e
3+
set -o pipefail
4+
5+
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
6+
CODEFRESH_PATH="$SCRIPT_DIR/../lib/interface/cli/codefresh"
7+
8+
echo "Using $CODEFRESH_PATH"
9+
function codefresh() {
10+
$CODEFRESH_PATH $@
11+
}
12+
13+
codefresh version
14+
echo
15+
16+
for executable in $SCRIPT_DIR/scenarios/*.sh
17+
do
18+
source $executable > "$executable.log" &
19+
echo "[$!] Executing: $executable"
20+
done
21+
echo
22+
23+
for job in `jobs -p`
24+
do
25+
echo "Waiting for $job..."
26+
wait $job || exit 1
27+
done
28+
29+
echo
30+
echo "All tests executed successfully!"

e2e/scenarios/agents.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get agents

e2e/scenarios/annotations.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
echo "Skipping annotation.sh"
2+
#codefresh get annotation

e2e/scenarios/boards.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
codefresh get boards
2+
echo "Skipping sections.sh"
3+
#codefresh get sections

e2e/scenarios/builds.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get builds

e2e/scenarios/clusters.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get clusters

e2e/scenarios/compositions.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get compositions

e2e/scenarios/contexts.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get contexts

e2e/scenarios/environments.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get environments

e2e/scenarios/helm-repo.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get helm-repo

e2e/scenarios/images.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get images

e2e/scenarios/pipelines.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get pipelines

e2e/scenarios/projects.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get projects

e2e/scenarios/registry.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get registry

e2e/scenarios/repository.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
codefresh get repository
2+
codefresh get repository -a

e2e/scenarios/runtime-environment.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get runtime-environments

e2e/scenarios/step-types.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get step-types
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get system-runtime-environments

e2e/scenarios/teams.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get teams

e2e/scenarios/tokens.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
codefresh get tokens

e2e/scenarios/triggers.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
codefresh get triggers
2+
codefresh get trigger-events
3+
codefresh get trigger-types

lib/interface/cli/completion/completion.spec.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
const initCompletion = require('./index');
22
const { handleOptions: mockHandleOptions, fileDir: mockFileDir } = require('./helpers');
3-
const mockPath = require('path');
43

5-
const completions = initCompletion();
4+
const mockCompletions = initCompletion();
5+
6+
function mockCwd() {
7+
return process.cwd();
8+
}
69

710
function getCompletion(args) {
8-
return new Promise(resolve => completions.getCompletion(args, resolve));
11+
return new Promise(resolve => mockCompletions.getCompletion(args, resolve));
912
}
1013

1114
jest.mock('./tree', () => ({
@@ -67,11 +70,11 @@ jest.mock('./context/create.completion', () => { // eslint-disable-line
6770

6871
jest.mock('fs', () => {
6972
const existsSync = (p) => {
70-
if (p.startsWith(`${process.cwd()}/`)) {
71-
p = p.replace(`${process.cwd()}/`, '');
73+
if (p.startsWith(`${mockCwd()}/`)) {
74+
p = p.replace(`${mockCwd()}/`, '');
7275
}
73-
if (p.startsWith(process.cwd())) {
74-
p = p.replace(process.cwd(), '');
76+
if (p.startsWith(mockCwd())) {
77+
p = p.replace(mockCwd(), '');
7578
}
7679
switch (p) {
7780
case '':
@@ -89,11 +92,11 @@ jest.mock('fs', () => {
8992
const lstatSync = (p) => {
9093
let isFile = false;
9194
let isDir = true;
92-
if (p.startsWith(`${process.cwd()}/`)) {
93-
p = p.replace(`${process.cwd()}/`, '');
95+
if (p.startsWith(`${mockCwd()}/`)) {
96+
p = p.replace(`${mockCwd()}/`, '');
9497
}
95-
if (p.startsWith(process.cwd())) {
96-
p = p.replace(process.cwd(), '');
98+
if (p.startsWith(mockCwd())) {
99+
p = p.replace(mockCwd(), '');
97100
}
98101
switch (p) {
99102
case 'some.yaml':
@@ -116,11 +119,11 @@ jest.mock('fs', () => {
116119
};
117120

118121
const readdirSync = (p) => {
119-
if (p.startsWith(`${process.cwd()}/`)) {
120-
p = p.replace(`${process.cwd()}/`, '');
122+
if (p.startsWith(`${mockCwd()}/`)) {
123+
p = p.replace(`${mockCwd()}/`, '');
121124
}
122-
if (p.startsWith(process.cwd())) {
123-
p = p.replace(process.cwd(), '');
125+
if (p.startsWith(mockCwd())) {
126+
p = p.replace(mockCwd(), '');
124127
}
125128
switch (p) {
126129
case '':

lib/logic/cli-config/Manager.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ class CliConfigManager {
8282
}, {});
8383
}
8484

85-
8685
static set(propertyName, value) {
8786
const properties = Model.findProperties(propertyName);
8887
_validate(properties, propertyName);
@@ -135,9 +134,9 @@ class CliConfigManager {
135134
static meta(propertyName) {
136135
const meta = Model.meta();
137136
return _.keys(meta)
138-
.filter(key => !propertyName || !propertyName.length || key.includes(propertyName))
137+
.filter((key) => !propertyName || !propertyName.length || key.includes(propertyName))
139138
.sort()
140-
.map(key => Object.assign({ key }, _.get(meta, key)));
139+
.map((key) => ({ key, ..._.get(meta, key) }));
141140
}
142141

143142
static _preloadConfig() {
@@ -168,12 +167,12 @@ class CliConfigManager {
168167
try {
169168
Model.validate(CURRENT_CONFIG);
170169
} catch (e) {
171-
const errorPaths = e.errors.map(er => er.dataPath.replace('.', ''));
170+
const errorPaths = e.errors.map((er) => er.dataPath.replace('.', ''));
172171

173172
console.warn('---------------');
174173
console.warn('!!! Some properties are invalid -- replacing with defaults:');
175174

176-
errorPaths.forEach(ep => {
175+
errorPaths.forEach((ep) => {
177176
console.warn(ep);
178177
_.set(CURRENT_CONFIG, ep, undefined);
179178
});

lib/logic/cli-config/Model.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ let DEFAULTS;
1111
let PROPERTIES;
1212
let PROPERTIES_META;
1313

14-
1514
/**
1615
* Every schema object need to have default set to {} in order to init its properties with default value
1716
* */
1817
function _fillSchemaObjectsWithDefault(schema) {
1918
if (schema.type === 'object') {
19+
// eslint-disable-next-line no-param-reassign
2020
schema.default = schema.default || {};
2121
if (schema.properties) {
2222
_.values(schema.properties).forEach((value) => {
@@ -38,13 +38,13 @@ function _compileSchema() {
3838

3939
function _extractMeta(props) {
4040
return props.reduce((obj, prop) => {
41+
// eslint-disable-next-line no-param-reassign
4142
obj[prop] = prop.split('.')
4243
.reduce((prev, pathPart) => prev.properties[pathPart], cliConfigSchema);
4344
return obj;
4445
}, {});
4546
}
4647

47-
4848
class Model {
4949
static default() {
5050
return _.cloneDeep(DEFAULTS);
@@ -55,13 +55,13 @@ class Model {
5555
}
5656

5757
static findProperties(name) {
58-
return PROPERTIES.filter(prop => prop.includes(name));
58+
return PROPERTIES.filter((prop) => prop.includes(name));
5959
}
6060

61-
6261
static meta() {
6362
return _.cloneDeep(PROPERTIES_META);
6463
}
64+
6565
/**
6666
* also fills with default values and coerces types
6767
* */
@@ -79,4 +79,3 @@ PROPERTIES = _.keys(flatten(DEFAULTS));
7979
PROPERTIES_META = _extractMeta(PROPERTIES);
8080

8181
module.exports = Model;
82-

lib/logic/cli-config/manager.spec.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
const _ = require('lodash');
22
const path = require('path');
33

4+
const fs = require('fs');
45
const Manager = require('./Manager');
56
const Model = require('./Model');
67

78
const { CODEFRESH_PATH: mockCodefreshPath } = require('../../interface/cli/defaults');
9+
810
const mockDirPath = path.resolve(mockCodefreshPath, 'cli-config');
911
const mockFilePath = path.resolve(mockDirPath, 'config.yaml');
1012

11-
1213
jest.mock('fs', () => { // eslint-disable-line
1314
const readFileSync = () => this.configFile;
14-
const existsSync = (path) => {
15-
return {
16-
[mockCodefreshPath]: true,
17-
[mockDirPath]: true,
18-
[mockFilePath]: this.exists,
19-
}[path];
20-
};
15+
const existsSync = (targetPath) => ({
16+
[mockCodefreshPath]: true,
17+
[mockDirPath]: true,
18+
[mockFilePath]: this.exists,
19+
}[targetPath]);
2120
const openSync = () => null;
2221
const writeSync = (file, config) => {
2322
this.configFile = config;
@@ -47,8 +46,8 @@ jest.mock('fs', () => { // eslint-disable-line
4746
});
4847

4948
jest.mock('js-yaml', () => {
50-
const safeLoad = d => d;
51-
const safeDump = d => d;
49+
const safeLoad = (d) => d;
50+
const safeDump = (d) => d;
5251
return {
5352
safeLoad,
5453
safeDump,
@@ -67,7 +66,7 @@ jest.mock('./schema', () => { // eslint-disable-line
6766
pretty: {
6867
type: 'boolean',
6968
default: false,
70-
description: 'Defines whether to show data in table view in pretty mode or not'
69+
description: 'Defines whether to show data in table view in pretty mode or not',
7170
},
7271
test: {
7372
type: 'object',
@@ -92,8 +91,6 @@ jest.mock('./schema', () => { // eslint-disable-line
9291
};
9392
});
9493

95-
const fs = require('fs');
96-
9794
describe('CliConfigManager', () => {
9895
describe('config loading', () => {
9996
// this test case must be first due to node module cache

lib/logic/entities/Agent.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const _ = require('lodash');
2-
const Entity = require('./Entity');
32
const chalk = require('chalk');
3+
const Entity = require('./Entity');
44

55
class Agent extends Entity {
66
constructor(data) {
@@ -42,11 +42,9 @@ class Agent extends Entity {
4242
}
4343
}
4444

45-
4645
static fromResponse(response) {
4746
return new Agent(_.pick(response, 'id', 'name', 'runtimes', 'status', 'lastReported'));
4847
}
4948
}
5049

5150
module.exports = Agent;
52-

lib/logic/entities/CodefreshRepo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class CodefreshRepo extends Entity {
1010
}
1111

1212
static fromResponse(response) {
13-
const data = Object.assign({}, response);
13+
const data = { ...response };
1414
data.name_id = response.serviceName;
1515
data.git_context = response.provider;
1616
data.owner = response.owner.login;

0 commit comments

Comments
 (0)