mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 04:05:42 +00:00
Merge pull request #4693 from pooja-bruno/mv/isValidValue-in-common-file
Fixed a bug causing secrets to appear as null instead of an empty value. rm isValidValue and directly handle it in encryptString and `decryptString` function
This commit is contained in:
@@ -83,7 +83,7 @@ class SingleLineEditor extends Component {
|
||||
}
|
||||
});
|
||||
}
|
||||
this.editor.setValue(String(this.props.value) || '');
|
||||
this.editor.setValue(String(this.props.value ?? ''));
|
||||
this.editor.on('change', this._onEdit);
|
||||
this.addOverlay(variables);
|
||||
this._enableMaskedEditor(this.props.isSecret);
|
||||
@@ -129,7 +129,7 @@ class SingleLineEditor extends Component {
|
||||
}
|
||||
if (this.props.value !== prevProps.value && this.props.value !== this.cachedValue && this.editor) {
|
||||
this.cachedValue = String(this.props.value);
|
||||
this.editor.setValue(String(this.props.value) || '');
|
||||
this.editor.setValue(String(this.props.value ?? ''));
|
||||
}
|
||||
if (!isEqual(this.props.isSecret, prevProps.isSecret)) {
|
||||
// If the secret flag has changed, update the editor to reflect the change
|
||||
|
||||
@@ -27,17 +27,13 @@ class EnvironmentSecretsStore {
|
||||
});
|
||||
}
|
||||
|
||||
isValidValue(val) {
|
||||
return typeof val === 'string' && val.length >= 0;
|
||||
}
|
||||
|
||||
storeEnvSecrets(collectionPathname, environment) {
|
||||
const envVars = [];
|
||||
_.each(environment.variables, (v) => {
|
||||
if (v.secret) {
|
||||
envVars.push({
|
||||
name: v.name,
|
||||
value: this.isValidValue(v.value) ? encryptString(v.value) : ''
|
||||
value: encryptString(v.value)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,15 +10,11 @@ class GlobalEnvironmentsStore {
|
||||
});
|
||||
}
|
||||
|
||||
isValidValue(val) {
|
||||
return typeof val === 'string' && val.length >= 0;
|
||||
}
|
||||
|
||||
encryptGlobalEnvironmentVariables({ globalEnvironments }) {
|
||||
return globalEnvironments?.map(env => {
|
||||
const variables = env.variables?.map(v => ({
|
||||
...v,
|
||||
value: v?.secret ? (this.isValidValue(v.value) ? encryptString(v.value) : '') : v?.value
|
||||
value: v?.secret ? encryptString(v.value) : v?.value
|
||||
})) || [];
|
||||
|
||||
return {
|
||||
@@ -32,7 +28,7 @@ class GlobalEnvironmentsStore {
|
||||
return globalEnvironments?.map(env => {
|
||||
const variables = env.variables?.map(v => ({
|
||||
...v,
|
||||
value: v?.secret ? (this.isValidValue(v.value) ? decryptString(v.value) : '') : v?.value
|
||||
value: v?.secret ? decryptString(v.value) : v?.value
|
||||
})) || [];
|
||||
|
||||
return {
|
||||
|
||||
@@ -89,6 +89,9 @@ function encryptString(str) {
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error('Encrypt failed: invalid string');
|
||||
}
|
||||
if (str.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let encryptedString = '';
|
||||
|
||||
@@ -104,9 +107,12 @@ function encryptString(str) {
|
||||
}
|
||||
|
||||
function decryptString(str) {
|
||||
if (!str) {
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error('Decrypt failed: unrecognized string format');
|
||||
}
|
||||
if (str.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Find the index of the first colon
|
||||
const colonIndex = str.indexOf(':');
|
||||
|
||||
@@ -12,13 +12,23 @@ describe('Encryption and Decryption Tests', () => {
|
||||
expect(decrypted).toBe(plaintext);
|
||||
});
|
||||
|
||||
it('should handle empty strings in encryptString', () => {
|
||||
const result = encryptString('');
|
||||
expect(result).toBe('');
|
||||
});
|
||||
|
||||
it('should handle empty strings in decryptString', () => {
|
||||
const result = decryptString('');
|
||||
expect(result).toBe('');
|
||||
});
|
||||
|
||||
it('encrypt should throw an error for invalid string', () => {
|
||||
expect(() => encryptString(null)).toThrow('Encrypt failed: invalid string');
|
||||
expect(() => encryptString(undefined)).toThrow('Encrypt failed: invalid string');
|
||||
});
|
||||
|
||||
it('decrypt should throw an error for invalid string', () => {
|
||||
expect(() => decryptString(null)).toThrow('Decrypt failed: unrecognized string format');
|
||||
expect(() => decryptString('')).toThrow('Decrypt failed: unrecognized string format');
|
||||
expect(() => decryptString('garbage')).toThrow('Decrypt failed: unrecognized string format');
|
||||
});
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ const mapArrayListToKeyValPairs = (arrayList = []) => {
|
||||
|
||||
return {
|
||||
name,
|
||||
value: null,
|
||||
value: '',
|
||||
enabled
|
||||
};
|
||||
});
|
||||
|
||||
@@ -185,7 +185,7 @@ vars:secret [
|
||||
},
|
||||
{
|
||||
name: 'token',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: true,
|
||||
secret: true
|
||||
}
|
||||
@@ -220,19 +220,19 @@ vars:secret [
|
||||
},
|
||||
{
|
||||
name: 'access_token',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: true,
|
||||
secret: true
|
||||
},
|
||||
{
|
||||
name: 'access_secret',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: true,
|
||||
secret: true
|
||||
},
|
||||
{
|
||||
name: 'access_password',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: false,
|
||||
secret: true
|
||||
}
|
||||
@@ -262,7 +262,7 @@ vars:secret [access_key]
|
||||
},
|
||||
{
|
||||
name: 'access_key',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: true,
|
||||
secret: true
|
||||
}
|
||||
@@ -292,19 +292,19 @@ vars:secret [access_key,access_secret, access_password ]
|
||||
},
|
||||
{
|
||||
name: 'access_key',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: true,
|
||||
secret: true
|
||||
},
|
||||
{
|
||||
name: 'access_secret',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: true,
|
||||
secret: true
|
||||
},
|
||||
{
|
||||
name: 'access_password',
|
||||
value: null,
|
||||
value: '',
|
||||
enabled: true,
|
||||
secret: true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user