Skip to content

bug(cli): preserve base64 padding in environment variable parsing #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/interface/cli/helpers/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ const prepareKeyValueObjectsFromCLIEnvOption = (environmentVariables) => {
const envArray = _.isArray(environmentVariables) ? environmentVariables : [environmentVariables];

envArray.forEach((vars) => {
const fields = vars.split('=');
const key = fields[0];
const value = fields[1];
const index = vars.indexOf('=');
if (index === -1) {
throw new CFError('Invalid environment variable format. please enter [key]=[value]');
}
const key = vars.substring(0, index);
const value = vars.substring(index + 1);
if (_.isUndefined(key) || _.isUndefined(value)) {
throw new CFError('Invalid environment variable format. please enter [key]=[value]');
}
Expand Down
43 changes: 41 additions & 2 deletions lib/interface/cli/helpers/helpers.unit.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const _ = require('lodash');
const CFError = require('cf-errors');
const helper = require('./image');
const { createEntity, entityList } = require('./entitiesManifests');
const { prepareKeyValueObjectsFromCLIEnvOption } = require('./general');

const { extractImages } = helper;

Expand Down Expand Up @@ -32,6 +34,43 @@ describe('helpers unit tests', () => {
}
});

describe('general', () => {
describe('prepareKeyValueObjectsFromCLIEnvOption', () => {
it('should parse key value object from array', () => {
const result = prepareKeyValueObjectsFromCLIEnvOption([
'SECRET_PASS=YWJjZA===',
'USERNAME=testUserName',
]);
expect(result).toEqual([
{
key: 'SECRET_PASS',
value: 'YWJjZA===',
},
{
key: 'USERNAME',
value: 'testUserName',
},
]);
});

it('should parse key value object from string', () => {
const result = prepareKeyValueObjectsFromCLIEnvOption('TEST=testData');
expect(result).toEqual([
{
key: 'TEST',
value: 'testData',
},
]);
});

it('should throw error when add incorrect environment variable', () => {
expect(
() => prepareKeyValueObjectsFromCLIEnvOption('TEST'),
).toThrow(new CFError('Invalid environment variable format. please enter [key]=[value]'));
});
});
});

describe('images', () => {
describe('#extractImages', () => {
beforeAll(() => {
Expand Down Expand Up @@ -93,10 +132,10 @@ describe('helpers unit tests', () => {
},
];
const extracted = extractImages(images);
const extractedDates = _.map(extracted, i => i.info.created);
const extractedDates = _.map(extracted, (i) => i.info.created);
const initialSortedDates = _.chain(images)
.orderBy(['created'], ['desc'])
.map(i => i.created)
.map((i) => i.created)
.value();
expect(extractedDates).toEqual(initialSortedDates);
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.89.0",
"version": "0.89.1",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down