@codefresh-io/service-base 3.0.18 → 3.0.20

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/index.js CHANGED
@@ -10,14 +10,14 @@ const {
10
10
  } = require('@codefresh-io/http-infra');
11
11
  const Promise = require('bluebird');
12
12
  const express = require('express');
13
- const monitor = require('cf-monitor');
13
+ const monitor = require('@codefresh-io/cf-monitor');
14
14
  const logging = require('./infra/logging');
15
15
  const { openapi } = require('@codefresh-io/cf-openapi');
16
16
 
17
17
  const OPTIONAL_COMPONENTS = {
18
18
  mongo: { name: 'mongoClient' },
19
- redis: { },
20
- eventbus: { },
19
+ redis: {},
20
+ eventbus: {},
21
21
  encryption: { dependencies: ['mongo'] },
22
22
  };
23
23
 
@@ -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 prefixLength = (shouldParse ? STRINGIFY_CRYPTO_PREFIX : CRYPTO_PREFIX).length;
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(prefixLength), 'hex'),
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(`${shouldStringify ? STRINGIFY_CRYPTO_PREFIX : CRYPTO_PREFIX}${ciphertext.toString('hex')}`);
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
- expect(decrypted).to.be.deep.equal(objToEncrypt);
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
 
package/infra/eventbus.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const Promise = require('bluebird');
4
4
  const eventBus = require('@codefresh-io/eventbus');
5
- const monitor = require('cf-monitor');
5
+ const monitor = require('@codefresh-io/cf-monitor');
6
6
  const CFError = require('cf-errors');
7
7
 
8
8
  class Eventbus {
package/infra/express.js CHANGED
@@ -6,7 +6,7 @@ const bodyParser = require('body-parser');
6
6
  const methodOverride = require('method-override');
7
7
  const cookieParser = require('cookie-parser');
8
8
  const morgan = require('morgan');
9
- const monitor = require('cf-monitor');
9
+ const monitor = require('@codefresh-io/cf-monitor');
10
10
  const { newDomainMiddleware } = require('@codefresh-io/http-infra');
11
11
  const { openapi } = require('@codefresh-io/cf-openapi');
12
12
  const CFError = require('cf-errors');
package/infra/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- const monitor = require('cf-monitor');
3
+ const monitor = require('@codefresh-io/cf-monitor');
4
4
 
5
5
  monitor.init();
6
6
  const Promise = require('bluebird'); // jshint ignore:line
package/infra/redis.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
 
3
3
  const Promise = require('bluebird');
4
- const monitor = require('cf-monitor');
4
+ const monitor = require('@codefresh-io/cf-monitor');
5
5
  const redis = require('redis');
6
6
 
7
7
  class Redis {
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@codefresh-io/service-base",
3
- "version": "3.0.18",
3
+ "version": "3.0.20",
4
4
  "main": "index.js",
5
5
  "description": "",
6
- "engines": {
7
- "node": ">=8.9.4"
8
- },
9
6
  "bin": {
10
7
  "cf-openapi": "./node_modules/cf-openapi/bin/cf-openapi"
11
8
  },
@@ -31,6 +28,7 @@
31
28
  "homepage": "https://github.com/codefresh-io/service-base#readme",
32
29
  "dependencies": {
33
30
  "@codefresh-io/authenticated-entity": "^2.13.1",
31
+ "@codefresh-io/cf-monitor": "^0.0.24",
34
32
  "@codefresh-io/cf-openapi": "~0.7.13",
35
33
  "@codefresh-io/eventbus": "1.4.2",
36
34
  "@codefresh-io/http-infra": "^1.8.11",
@@ -42,7 +40,6 @@
42
40
  "body-parser": "^1.18.3",
43
41
  "cf-errors": "^0.1.15",
44
42
  "cf-logs": "^1.1.24",
45
- "cf-monitor": "git+https://github.com/codefresh-io/cf-monitor.git#fc6b49d2a1a161beaf6d33b692d4ca86b38dfe43",
46
43
  "chai": "^4.1.2",
47
44
  "compression": "^1.7.4",
48
45
  "cookie-parser": "^1.4.4",
package/yarn.lock CHANGED
@@ -286,6 +286,13 @@
286
286
  lodash "^4.17.21"
287
287
  semver "^7.0.0"
288
288
 
289
+ "@codefresh-io/cf-monitor@^0.0.24":
290
+ version "0.0.24"
291
+ resolved "https://registry.yarnpkg.com/@codefresh-io/cf-monitor/-/cf-monitor-0.0.24.tgz#9c85f93c05bac6ba3a91385f8428270d9903ac23"
292
+ integrity sha512-hnp4DRjx/yAHi9Y7KlcZLAVTEO4emzd8JvXV26gMIONQ7QSWc17YxeXh5xL926Nx8EMh2Xol5soDAQ+sc/zuhg==
293
+ dependencies:
294
+ newrelic "^8.0.0"
295
+
289
296
  "@codefresh-io/cf-openapi@~0.7.13":
290
297
  version "0.7.13"
291
298
  resolved "https://registry.yarnpkg.com/@codefresh-io/cf-openapi/-/cf-openapi-0.7.13.tgz#ad763ee99ef770c4ed88b2efe5e9c9dda7d9f993"
@@ -352,9 +359,9 @@
352
359
  kuler "^2.0.0"
353
360
 
354
361
  "@grpc/grpc-js@^1.5.5":
355
- version "1.6.11"
356
- resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.6.11.tgz#74c04cde0cde4e8a88ffc514bd9cd1bb307815b9"
357
- integrity sha512-e/adiPjUxf5cKYiAlV4m+0jJS4k6g2w78X7WTZB3ISOBzcCwm+cwjB2dSRfBHbu46inGGzQMmWAmsgYLg8yT5g==
362
+ version "1.6.12"
363
+ resolved "https://registry.yarnpkg.com/@grpc/grpc-js/-/grpc-js-1.6.12.tgz#20f710d8a8c5c396b2ae9530ba6c06b984614fdf"
364
+ integrity sha512-JmvQ03OTSpVd9JTlj/K3IWHSz4Gk/JMLUTtW7Zb0KvO1LcOYGATh5cNuRYzCAeDR3O8wq+q8FZe97eO9MBrkUw==
358
365
  dependencies:
359
366
  "@grpc/proto-loader" "^0.7.0"
360
367
  "@types/node" ">=12.12.47"
@@ -1455,12 +1462,6 @@ cf-logs@^1.1.24, cf-logs@^1.1.25:
1455
1462
  lodash "^4.17.21"
1456
1463
  winston "3.3.3"
1457
1464
 
1458
- "cf-monitor@git+https://github.com/codefresh-io/cf-monitor.git#fc6b49d2a1a161beaf6d33b692d4ca86b38dfe43":
1459
- version "0.0.22"
1460
- resolved "git+https://github.com/codefresh-io/cf-monitor.git#fc6b49d2a1a161beaf6d33b692d4ca86b38dfe43"
1461
- dependencies:
1462
- newrelic "^8.0.0"
1463
-
1464
1465
  chai@^4.1.2:
1465
1466
  version "4.2.0"
1466
1467
  resolved "https://registry.yarnpkg.com/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5"
@@ -5047,19 +5048,19 @@ readable-stream@^2.3.5, readable-stream@^2.3.7:
5047
5048
  string_decoder "~1.1.1"
5048
5049
  util-deprecate "~1.0.1"
5049
5050
 
5050
- readable-stream@^3.0.2, readable-stream@^3.1.1:
5051
- version "3.4.0"
5052
- resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.4.0.tgz#a51c26754658e0a3c21dbf59163bd45ba6f447fc"
5053
- integrity sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==
5051
+ readable-stream@^3.0.2, readable-stream@^3.4.0, readable-stream@^3.6.0:
5052
+ version "3.6.0"
5053
+ resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
5054
+ integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
5054
5055
  dependencies:
5055
5056
  inherits "^2.0.3"
5056
5057
  string_decoder "^1.1.1"
5057
5058
  util-deprecate "^1.0.1"
5058
5059
 
5059
- readable-stream@^3.4.0, readable-stream@^3.6.0:
5060
- version "3.6.0"
5061
- resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
5062
- integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
5060
+ readable-stream@^3.1.1:
5061
+ version "3.4.0"
5062
+ resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.4.0.tgz#a51c26754658e0a3c21dbf59163bd45ba6f447fc"
5063
+ integrity sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==
5063
5064
  dependencies:
5064
5065
  inherits "^2.0.3"
5065
5066
  string_decoder "^1.1.1"