Skip to content

Commit 822dd03

Browse files
bug(cli): preserve base64 padding in environment variable parsing (#882)
## What ## Why ## Notes --------- Co-authored-by: Prabesh <sthapaprabesh2020@gmail.com>
1 parent 218c27a commit 822dd03

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

lib/interface/cli/helpers/general.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,12 @@ const prepareKeyValueObjectsFromCLIEnvOption = (environmentVariables) => {
9494
const envArray = _.isArray(environmentVariables) ? environmentVariables : [environmentVariables];
9595

9696
envArray.forEach((vars) => {
97-
const fields = vars.split('=');
98-
const key = fields[0];
99-
const value = fields[1];
97+
const index = vars.indexOf('=');
98+
if (index === -1) {
99+
throw new CFError('Invalid environment variable format. please enter [key]=[value]');
100+
}
101+
const key = vars.substring(0, index);
102+
const value = vars.substring(index + 1);
100103
if (_.isUndefined(key) || _.isUndefined(value)) {
101104
throw new CFError('Invalid environment variable format. please enter [key]=[value]');
102105
}

lib/interface/cli/helpers/helpers.unit.spec.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const _ = require('lodash');
2+
const CFError = require('cf-errors');
23
const helper = require('./image');
34
const { createEntity, entityList } = require('./entitiesManifests');
5+
const { prepareKeyValueObjectsFromCLIEnvOption } = require('./general');
46

57
const { extractImages } = helper;
68

@@ -32,6 +34,43 @@ describe('helpers unit tests', () => {
3234
}
3335
});
3436

37+
describe('general', () => {
38+
describe('prepareKeyValueObjectsFromCLIEnvOption', () => {
39+
it('should parse key value object from array', () => {
40+
const result = prepareKeyValueObjectsFromCLIEnvOption([
41+
'SECRET_PASS=YWJjZA===',
42+
'USERNAME=testUserName',
43+
]);
44+
expect(result).toEqual([
45+
{
46+
key: 'SECRET_PASS',
47+
value: 'YWJjZA===',
48+
},
49+
{
50+
key: 'USERNAME',
51+
value: 'testUserName',
52+
},
53+
]);
54+
});
55+
56+
it('should parse key value object from string', () => {
57+
const result = prepareKeyValueObjectsFromCLIEnvOption('TEST=testData');
58+
expect(result).toEqual([
59+
{
60+
key: 'TEST',
61+
value: 'testData',
62+
},
63+
]);
64+
});
65+
66+
it('should throw error when add incorrect environment variable', () => {
67+
expect(
68+
() => prepareKeyValueObjectsFromCLIEnvOption('TEST'),
69+
).toThrow(new CFError('Invalid environment variable format. please enter [key]=[value]'));
70+
});
71+
});
72+
});
73+
3574
describe('images', () => {
3675
describe('#extractImages', () => {
3776
beforeAll(() => {
@@ -93,10 +132,10 @@ describe('helpers unit tests', () => {
93132
},
94133
];
95134
const extracted = extractImages(images);
96-
const extractedDates = _.map(extracted, i => i.info.created);
135+
const extractedDates = _.map(extracted, (i) => i.info.created);
97136
const initialSortedDates = _.chain(images)
98137
.orderBy(['created'], ['desc'])
99-
.map(i => i.created)
138+
.map((i) => i.created)
100139
.value();
101140
expect(extractedDates).toEqual(initialSortedDates);
102141
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.89.0",
3+
"version": "0.89.1",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)