@mojaloop/sdk-scheme-adapter 24.9.5 → 24.9.6

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.
Binary file
package/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
  # Changelog: [mojaloop/sdk-scheme-adapter](https://github.com/mojaloop/sdk-scheme-adapter)
2
+ ### [24.9.6](https://github.com/mojaloop/sdk-scheme-adapter/compare/v24.9.5...v24.9.6) (2025-06-01)
3
+
4
+
5
+ ### Chore
6
+
7
+ * fix faulty jws replacement logic [@kleyow](https://github.com/kleyow) ([#585](https://github.com/mojaloop/sdk-scheme-adapter/issues/585)) ([efa7ce1](https://github.com/mojaloop/sdk-scheme-adapter/commit/efa7ce19f869a601f868f57ea569202110c9d7f9))
8
+
2
9
  ### [24.9.5](https://github.com/mojaloop/sdk-scheme-adapter/compare/v24.9.4...v24.9.5) (2025-05-30)
3
10
 
4
11
 
@@ -26,6 +26,7 @@
26
26
  ******/
27
27
  const Koa = require('koa');
28
28
 
29
+ const _ = require('lodash');
29
30
  const assert = require('assert').strict;
30
31
  const https = require('https');
31
32
  const http = require('http');
@@ -87,7 +88,8 @@ class InboundApi extends EventEmitter {
87
88
  }
88
89
 
89
90
  _updatePeerJwsKeys(peerJwsKeys) {
90
- if (this._conf.pm4mlEnabled) {
91
+ if (this._conf.pm4mlEnabled && !_.isEqual(this._jwsVerificationKeys, peerJwsKeys) &&
92
+ this._jwsVerificationKeys && typeof this._jwsVerificationKeys === 'object') {
91
93
  this._logger && this._logger.isVerboseEnabled && this._logger.verbose('Clearing existing JWS verification keys');
92
94
  Object.keys(this._jwsVerificationKeys).forEach(key => delete this._jwsVerificationKeys[key]);
93
95
  this._logger && this._logger.isVerboseEnabled && this._logger.verbose('Assigning new peer JWS keys');
@@ -144,10 +144,6 @@ class Server extends EventEmitter {
144
144
  || !_.isEqual(this.conf.outbound, newConf.outbound);
145
145
  }
146
146
 
147
- _shouldUpdatePeerJwsKeys(newConf) {
148
- return !_.isEqual(this.conf.peerJWSKeys, newConf.peerJWSKeys);
149
- }
150
-
151
147
  async start() {
152
148
  await this.cache.connect();
153
149
  await this.wso2.auth.start();
@@ -251,10 +247,7 @@ class Server extends EventEmitter {
251
247
  restartActionsTaken.updateInboundServer = true;
252
248
  }
253
249
 
254
- const updatePeerJwsKeys = this._shouldUpdatePeerJwsKeys(newConf);
255
- if (updatePeerJwsKeys) {
256
- this.inboundServer._api._updatePeerJwsKeys(newConf.peerJWSKeys);
257
- }
250
+ this.inboundServer._api._updatePeerJwsKeys(newConf.peerJWSKeys);
258
251
 
259
252
  this.logger.isDebugEnabled && this.logger.push({ oldConf: this.conf.outbound, newConf: newConf.outbound }).debug('Outbound server configuration');
260
253
  const updateOutboundServer = !_.isEqual(this.conf.outbound, newConf.outbound);
@@ -490,5 +490,59 @@ describe('Inbound Server', () => {
490
490
 
491
491
  expect(Jws.validator.__validationKeys['mock-jws'].toString()).toEqual('foo-key-updated');
492
492
  });
493
+
494
+ it('should overwrite an existing peer JWS key when _updatePeerJwsKeys is called with the same key name', async () => {
495
+ // Arrange
496
+ const serverConfig = JSON.parse(JSON.stringify(defaultConfig));
497
+ serverConfig.validateInboundJws = true;
498
+ const cache = new Cache({
499
+ cacheUrl: serverConfig.cacheUrl,
500
+ logger: logger.push({ component: 'cache' }),
501
+ unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
502
+ });
503
+ serverConfig.validateInboundJws = true;
504
+ serverConfig.pm4mlEnabled = true;
505
+ serverConfig.peerJWSKeys = {
506
+ 'peer1': 'original-key'
507
+ };
508
+ const svr = new InboundServer(serverConfig, logger, cache);
509
+
510
+ // Save reference before update
511
+ const keysRef = svr._api._jwsVerificationKeys;
512
+
513
+ // Act: Overwrite the key
514
+ svr._api._updatePeerJwsKeys({ 'peer1': 'new-key' });
515
+
516
+ // Assert
517
+ expect(svr._api._jwsVerificationKeys['peer1']).toBe('new-key');
518
+ expect(svr._api._jwsVerificationKeys).toBe(keysRef); // memory reference unchanged
519
+ });
520
+
521
+ it('should add a new peer JWS key when _updatePeerJwsKeys is called with a new key name', async () => {
522
+ // Arrange
523
+ const serverConfig = JSON.parse(JSON.stringify(defaultConfig));
524
+ serverConfig.validateInboundJws = true;
525
+ const cache = new Cache({
526
+ cacheUrl: serverConfig.cacheUrl,
527
+ logger: logger.push({ component: 'cache' }),
528
+ unsubscribeTimeoutMs: serverConfig.unsubscribeTimeoutMs,
529
+ });
530
+ serverConfig.validateInboundJws = true;
531
+ serverConfig.pm4mlEnabled = true;
532
+ serverConfig.peerJWSKeys = {
533
+ 'peer1': 'original-key'
534
+ };
535
+ const svr = new InboundServer(serverConfig, logger, cache);
536
+
537
+ // Save reference before update
538
+ const keysRef = svr._api._jwsVerificationKeys;
539
+
540
+ // Act: Add a new key
541
+ svr._api._updatePeerJwsKeys({ 'peer1': 'original-key', 'peer2': 'another-key' });
542
+ // Assert
543
+ expect(svr._api._jwsVerificationKeys['peer1']).toBe('original-key');
544
+ expect(svr._api._jwsVerificationKeys['peer2']).toBe('another-key');
545
+ expect(svr._api._jwsVerificationKeys).toBe(keysRef); // memory reference unchanged
546
+ });
493
547
  });
494
548
  });
@@ -99,21 +99,6 @@ describe('Server', () => {
99
99
  expect(server.restart).toHaveBeenCalledWith(newConf);
100
100
  });
101
101
 
102
- it('hot mutates peerJwsKeys reference if peerJWSKeys config is different', async () => {
103
- // Test that peerJwsKeys are updated without a full restart if config changes
104
- const originalPeerJwsKeys = conf.peerJWSKeys;
105
- const newPeerJwsKeys = { ...originalPeerJwsKeys, newKey: 'newValue' };
106
- const newConfPeerJwsKeys = { ...conf, peerJWSKeys: newPeerJwsKeys };
107
-
108
- expect(server._shouldUpdatePeerJwsKeys(newConfPeerJwsKeys)).toBe(true);
109
-
110
- controlServer.broadcastConfigChange(newConfPeerJwsKeys);
111
- await new Promise((wait) => setTimeout(wait, 1000));
112
-
113
- // Should call restart with new config
114
- expect(server.restart).toHaveBeenCalledWith(newConfPeerJwsKeys);
115
- });
116
-
117
102
  it('restarts inbound server if inbound or outbound is different', async () => {
118
103
  // Clone the conf and change inbound config
119
104
  const newConfInbound = JSON.parse(JSON.stringify(conf));
@@ -60,7 +60,7 @@
60
60
  "@types/convict": "6.1.6",
61
61
  "@types/express": "5.0.2",
62
62
  "@types/jest": "29.5.14",
63
- "@types/node": "22.15.28",
63
+ "@types/node": "22.15.29",
64
64
  "@types/node-cache": "4.2.5",
65
65
  "@types/supertest": "6.0.3",
66
66
  "@types/swagger-ui-express": "4.1.8",
@@ -57,7 +57,7 @@
57
57
  "@types/convict": "6.1.6",
58
58
  "@types/express": "5.0.2",
59
59
  "@types/jest": "29.5.14",
60
- "@types/node": "22.15.28",
60
+ "@types/node": "22.15.29",
61
61
  "@types/node-cache": "4.2.5",
62
62
  "@types/supertest": "6.0.3",
63
63
  "@types/swagger-ui-express": "4.1.8",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "devDependencies": {
42
42
  "@eslint/compat": "1.2.9",
43
- "@types/node": "22.15.28",
43
+ "@types/node": "22.15.29",
44
44
  "@types/uuid": "10.0.0",
45
45
  "@typescript-eslint/eslint-plugin": "8.33.0",
46
46
  "@typescript-eslint/parser": "8.33.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mojaloop/sdk-scheme-adapter",
3
- "version": "24.9.5",
3
+ "version": "24.9.6",
4
4
  "description": "mojaloop sdk-scheme-adapter",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/mojaloop/sdk-scheme-adapter",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "devDependencies": {
84
84
  "@types/jest": "29.5.14",
85
- "@types/node": "22.15.28",
85
+ "@types/node": "22.15.29",
86
86
  "@types/node-cache": "4.2.5",
87
87
  "@typescript-eslint/eslint-plugin": "8.33.0",
88
88
  "@typescript-eslint/parser": "8.33.0",