@codefresh-io/service-base 3.0.19 → 3.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/infra/config.js
CHANGED
|
@@ -116,7 +116,12 @@ base.logger = {
|
|
|
116
116
|
try {
|
|
117
117
|
const authEntity = getAuthenticatedEntity().toJson({ partial: true });
|
|
118
118
|
if (_.get(authEntity, 'activeAccount')) {
|
|
119
|
-
|
|
119
|
+
// eslint-disable-next-line max-len
|
|
120
|
+
authEntity.activeAccount = _.pick(authEntity.activeAccount, ['type', 'id', 'name', 'activeAccount.name', 'activeAccount.id']);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (_.get(authEntity, 'account')) {
|
|
124
|
+
authEntity.account = _.pick(authEntity.account, ['type', 'id', 'name', 'account.name', 'account.id']);
|
|
120
125
|
}
|
|
121
126
|
return authEntity;
|
|
122
127
|
} catch (err) {
|
package/infra/encryption/safe.js
CHANGED
|
@@ -51,11 +51,18 @@ Safe.prototype.read_crypto = function (ciphertext) { // eslint-disable-line
|
|
|
51
51
|
const iv = Buffer.alloc(16, this.safeModel.key);
|
|
52
52
|
|
|
53
53
|
const shouldParse = ciphertext.startsWith(STRINGIFY_CRYPTO_PREFIX);
|
|
54
|
-
const
|
|
54
|
+
const prefix = shouldParse ? STRINGIFY_CRYPTO_PREFIX : CRYPTO_PREFIX;
|
|
55
|
+
|
|
56
|
+
// don't try to encrypt empty strings
|
|
57
|
+
// this causes segfault with node.js >= 14.x.x
|
|
58
|
+
if (ciphertext === CRYPTO_PREFIX) {
|
|
59
|
+
deferred.resolve('');
|
|
60
|
+
return deferred.promise;
|
|
61
|
+
}
|
|
55
62
|
|
|
56
63
|
const encrypt = 0; // 0 = Decrypt
|
|
57
64
|
cryptoAsync.cipher(
|
|
58
|
-
ALGORITHM, encrypt, key, iv, Buffer.from(ciphertext.slice(
|
|
65
|
+
ALGORITHM, encrypt, key, iv, Buffer.from(ciphertext.slice(prefix.length), 'hex'),
|
|
59
66
|
(error, plaintext) => {
|
|
60
67
|
if (error) {
|
|
61
68
|
deferred.reject(error);
|
|
@@ -75,8 +82,16 @@ Safe.prototype.write_crypto = function (plaintext) { // eslint-disable-line
|
|
|
75
82
|
const iv = Buffer.alloc(16, this.safeModel.key);
|
|
76
83
|
|
|
77
84
|
const shouldStringify = !_.isString(plaintext);
|
|
85
|
+
const prefix = shouldStringify ? STRINGIFY_CRYPTO_PREFIX : CRYPTO_PREFIX;
|
|
78
86
|
const textToEncrypt = shouldStringify ? JSON.stringify(plaintext) : plaintext;
|
|
79
87
|
|
|
88
|
+
// don't try to encrypt empty strings
|
|
89
|
+
// this causes segfault with node.js >= 14.x.x
|
|
90
|
+
if (textToEncrypt === '') {
|
|
91
|
+
deferred.resolve(prefix);
|
|
92
|
+
return deferred.promise;
|
|
93
|
+
}
|
|
94
|
+
|
|
80
95
|
const encrypt = 1; // 1 = Encrypt
|
|
81
96
|
cryptoAsync.cipher(
|
|
82
97
|
ALGORITHM, encrypt, key, iv, Buffer.from(textToEncrypt),
|
|
@@ -85,7 +100,7 @@ Safe.prototype.write_crypto = function (plaintext) { // eslint-disable-line
|
|
|
85
100
|
deferred.reject(error);
|
|
86
101
|
return;
|
|
87
102
|
}
|
|
88
|
-
deferred.resolve(`${
|
|
103
|
+
deferred.resolve(`${prefix}${ciphertext.toString('hex')}`);
|
|
89
104
|
},
|
|
90
105
|
);
|
|
91
106
|
return deferred.promise;
|
|
@@ -65,13 +65,15 @@ const STRINGIFY_CRYPTO_PREFIX = '$$$crypto-obj$$$';
|
|
|
65
65
|
it('should encrypt all object', () => {
|
|
66
66
|
const objToEncrypt = {
|
|
67
67
|
keyToBeEncrypted: 'value-1',
|
|
68
|
-
keyToBeEncrypted2: 'value-2'
|
|
68
|
+
keyToBeEncrypted2: 'value-2',
|
|
69
|
+
keyToBeEncrypted3: '',
|
|
69
70
|
};
|
|
70
71
|
const keysToEncrypt = Object.keys(objToEncrypt);
|
|
71
72
|
return encryptObjectValues(generateSafeId(), objToEncrypt, keysToEncrypt)
|
|
72
73
|
.then((res) => {
|
|
73
74
|
expect(res.keyToBeEncrypted).to.have.string(CRYPTO_PREFIX);
|
|
74
75
|
expect(res.keyToBeEncrypted2).to.have.string(CRYPTO_PREFIX);
|
|
76
|
+
expect(res.keyToBeEncrypted3).to.equal(CRYPTO_PREFIX);
|
|
75
77
|
});
|
|
76
78
|
});
|
|
77
79
|
|
|
@@ -125,7 +127,8 @@ const STRINGIFY_CRYPTO_PREFIX = '$$$crypto-obj$$$';
|
|
|
125
127
|
it('should decrypt encrypted object', () => {
|
|
126
128
|
const objToEncrypt = {
|
|
127
129
|
keyToBeEncrypted: 'value-1',
|
|
128
|
-
keyToBeEncrypted2: 'value-2'
|
|
130
|
+
keyToBeEncrypted2: 'value-2',
|
|
131
|
+
keyToBeEncrypted3: '', // should be decrypted as empty string
|
|
129
132
|
};
|
|
130
133
|
const keysToEncrypt = Object.keys(objToEncrypt);
|
|
131
134
|
return encryptObjectValues(generateSafeId(), objToEncrypt, keysToEncrypt)
|
|
@@ -133,7 +136,9 @@ const STRINGIFY_CRYPTO_PREFIX = '$$$crypto-obj$$$';
|
|
|
133
136
|
return decryptObjectValues(generateSafeId(), res, keysToEncrypt);
|
|
134
137
|
})
|
|
135
138
|
.then((decrypted) => {
|
|
136
|
-
|
|
139
|
+
expect(decrypted.keyToBeEncrypted).to.be.deep.equal(objToEncrypt.keyToBeEncrypted);
|
|
140
|
+
expect(decrypted.keyToBeEncrypted2).to.be.deep.equal(objToEncrypt.keyToBeEncrypted2);
|
|
141
|
+
expect(decrypted.keyToBeEncrypted3).to.be.equal('');
|
|
137
142
|
});
|
|
138
143
|
});
|
|
139
144
|
|